15、自定义线性滤波

 卷积可以对图像进行模糊,锐化,边沿查找等操作。

常见的算子:

               

定义Robert算子,当然也可以定义sobel算子和拉普拉斯算子。利用filter2D函数实现自定义线性滤波。

 

代码实现图像的逐渐模糊:

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
int main(int argc, char** argv) {
	Mat dst;
	Mat src = imread("C:/Users/ThinkPad/Desktop/1.PNG");
	if (!src.data) {
		printf("could not find");
		return -1;
	}
	namedWindow("input", cv::WINDOW_AUTOSIZE);
	namedWindow("output", cv::WINDOW_AUTOSIZE);
	cv::imshow("input", src);
	int index = 1;
	int c = 0;
	while (true) {
		c = waitKey(500);
		if ((char)c == 27) {
			break;
		}
		int ksize = 3 + 2 * (index % 5);
		Mat kernel = Mat::ones(Size(ksize, ksize), CV_32F)/ (float)(ksize * ksize);
		filter2D(src, dst, -1, kernel, Point(-1, -1), 0);
		imshow("output", dst);
		index++;
	}
	return 0;
}

 

这只是两个过程中的模糊图像,效果可以实现图像的逐渐模糊。ESC是退出运行。

 

 

 

                                                                    

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值