图像平滑算法
图像平滑与图像模糊是同一概念,主要用于图像的去噪。平滑要使用滤波器,为不改变图像的相位信息,一般使用线性滤波器。
几种不同的平滑方法:
1. 归一化滤波器
Blurs an image using the normalized box filter.
void blur(InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT )
其中ksize为核窗口大小,
Point(-1, -1):
Indicates where the anchor point (the pixel evaluated) is located with respect to the neighborhood.If there is a negative value, then the center of the kernel is considered the anchor point.
2. 高斯滤波
void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT )
sigmaX: The standard deviation in x. Writing 0 implies that x is calculated using kernel size.
sigmaxY: The standard deviation in y. Writing 0 implies that y is calculated using kernel size.
3. 中值滤波
void medianBlur(InputArray src, OutputArray dst, int ksize)
Size of the kernel (only one because we use a square window). Must be odd.因为其核窗口为正方形,所以他只有一个。
中值滤波对椒盐噪声的去噪效果最好。
Opencv加椒盐噪声
椒盐噪声是由图像传感器,传输信道,解码处理等产生的黑白相间的亮暗点噪声。椒盐噪声往往由图像切割引起。
我们用程序来模拟椒盐噪声,随机选取一些像素,把这些像素设为白色。
void salt(Mat& image, int n) {
for (int k = 0; k<n; k++) {
int i = rand() % image.cols;
int j = rand() % image.rows;
if (image.channels() == 1) { //判断是一个通道
image.at<uchar>(j, i) = 255;
}
else {
image.at<cv::Vec3b>(j, i)[0] = 255;
image.at<cv::Vec3b>(j, i)[1] = <