sharpen和filter2D

Sharpen()

sharpen和filter2D_第1张图片

 

 

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

输出结果:

sharpen和filter2D_第2张图片

                原始图像,sharpen ,filterD

代码:Sharpen.cpp

#include 
#include 
#include 
#include 
#include 
#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(j - 1);
		const uchar* current = myImage.ptr(j);
		const uchar* next = myImage.ptr(j + 1);
		uchar* output = Result.ptr(j);			// 输出图像对应坐标位置
		// 输出按行处理,每行第一个元素,++指向后一个元素。
		for (int i = nChannels; i < nChannels*(myImage.cols - 1); ++i)
		{
			// 先执行,再加加
			*output++ = saturate_cast(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

你可能感兴趣的:(sharpen和filter2D)