• sharpen和filter2D


    Sharpen()

    第一种表示法是使用公式,而第二种表示法是使用掩码对第一种表示法进行压缩的版本。使用掩码时,将掩码矩阵的中心放在要计算的像素上。

    输出结果:

                    原始图像,sharpen ,filterD

    代码:Sharpen.cpp

    #include <iostream>
    #include <opencv2highguihighgui.hpp>
    #include <opencv2corecore.hpp>
    #include <opencv2imgprocimgproc.hpp>
    #include <cmath>
    #include "GamaT.h"
    
    using namespace cv;
    using namespace std;
    
    void Sharpen(const Mat& myImage, Mat& Result)
    {
    	CV_Assert(myImage.depth() == CV_8U);				// accept only uchar images
    	const int nChannels = myImage.channels();			//channels
    //The output has the same structure as the input
    	Result = Mat::zeros(myImage.size(), myImage.type());
    
    	for (int j = 1; j < myImage.rows - 1; ++j)			// 只计算第二行到倒数第二行,第二列到倒数第二列之间的像素点
    	{
    		const uchar* previous = myImage.ptr<uchar>(j - 1);
    		const uchar* current = myImage.ptr<uchar>(j);
    		const uchar* next = myImage.ptr<uchar>(j + 1);
    		uchar* output = Result.ptr<uchar>(j);			// 输出图像对应坐标位置
    		// 输出按行处理,每行第一个元素,++指向后一个元素。
    		for (int i = nChannels; i < nChannels*(myImage.cols - 1); ++i)
    		{
    			// 先执行,再加加
    			*output++ = saturate_cast<uchar>(5 * current[i]			// 当前位置
    				- current[i - nChannels] - current[i + nChannels]	// 前后
    				- previous[i] - next[i]);							// 上下
    		}
    	}
    }
    

      

    其他滤波器:

    方框滤波器:boxFilter(img, out, -1, Size(5, 5));//-1指原图深度

    均值滤波器:blur(img, out,Size(5, 5));//-1指原图深度

    高斯滤波器:GaussianBlur(img, out, Size(3, 3), 0, 0);

    中值滤波对于椒盐噪声污染的图像,中值滤波要远远优于线性平滑滤波。

    中值滤波器:medianBlur(img, out, 7);//第三个参数表示孔径的线性尺寸,它的值必须是大于1的奇数

    自适应中值滤波:在扫描像素排序时,当前像素非极大极小值时,不改变像素值。

    注意:作为一种非线性滤波,中值滤波有可能会改变图像的性质,因而一般不适用于像军事图像处理、医学图像处理等领域.

    双边滤波器:bilateralFilter(img, out, 25, 25 * 2, 25 / 2);

    取了名字的这些滤波器就是定好kernel的滤波器。相当于filter2D+kernel

    参考文献:

    https://docs.opencv.org/master/d7/d37/tutorial_mat_mask_operations.html

  • 相关阅读:
    C语言学习11(循环结构:for语句)
    C语言学习9(循环结构:while语句)
    C语言学习8(选择结构的嵌套)
    C语言学习笔记2
    C语言学习笔记1
    C语言的学习5(数据的输出)
    C语言学习12(函数的定义)
    第二十一章流 14临时文件 简单
    第二十一章流 12输出数据到文件指定位置处seekp() 简单
    第二十一章流 11指定读取文件中的数据seekg() 简单
  • 原文地址:https://www.cnblogs.com/philothypeipei/p/12142681.html
Copyright © 2020-2023  润新知