opencv中值滤波和低通滤波器对椒盐噪声处理的效果比较
效果:
通过比较我们可以看出,中值滤波器有很好的保留了图像的边界信息
代码:
void showimage(const std::string &str,const cv::Mat &image){ namedWindow(str,CV_WINDOW_AUTOSIZE); imshow(str,image); } Mat salt(const cv::Mat &image,int n){ Mat result = image.clone(); for (int i = 0; i<n;++i) { int row = rand()%result.rows; int col = rand()%result.cols; result.at<Vec3b>(row,col)[0] = 255; result.at<Vec3b>(row,col)[1] = 255; result.at<Vec3b>(row,col)[2] = 255; } return result; } int _tmain(int argc, _TCHAR* argv[]) { Mat image = imread("boldt.jpg"); showimage("image",image); Mat saltimage = salt(image,500); showimage("saltimage",saltimage); Mat medianimage,blurimage; blur(saltimage,blurimage,Size(5,5)); showimage("blurimage",blurimage); medianBlur(saltimage,medianimage,5); showimage("medianimage",medianimage); waitKey(0); return 0; }
opencv中值滤波和低通滤波器对椒盐噪声处理的效果比较,布布扣,bubuko.com
时间: 2024-10-03 06:56:59