ROI的一些opencv过滤算法

原文:https://zhuanlan.zhihu.com/p/285660247

计算MTF/SFR通常用到棋盘格。在计算棋盘格的区域上,花了些时间,记录下。

首先需要根据需要测试的FOV寻找5个区域。

算法的总体思路:

1)选取ROI区域;

2)使用滤波算法,过滤到噪点,并强化边缘,找到棋盘格的格子;

3)从连通区判断FOV点是否在连通区内,连通区是否最小;

4)从找到的连通区找外接矩形;

5)通过固定位置找刃边ROI区域。

记录下一些通用算法的效果,方便以后查阅

开操作:消除细小颗粒

# 设置kernel
kernel = np.ones((5, 5), np.int16)
kernel[2][2] = -24

# 设置卷积核
kernel15 = np.ones((8, 8), np.int16)
kernel5 = np.ones((5, 5), np.int16)
kernel3 = np.ones((3, 3), np.int16)
kernel2 = np.ones((2, 2), np.int16)
cv2.imwrite('1_gray.png',dst)
dst = cv2.morphologyEx(img_gray, cv2.MORPH_OPEN, kernel5)
cv2.imwrite('2_morphologyEx.png',dst)

平滑或高斯滤波:消除毛刺

dst = cv2.blur(dst, (5, 5))
cv2.imwrite('3_blur.png',dst)
#dst = cv2.GaussianBlur(dst, (5, 5), 0)
#cv2.imwrite('3_GaussianBlur.png',dst)

锐化

# 锐化
blur = cv2.Laplacian(dst, cv2.CV_16S, ksize=3)

取绝对值

cv2.imwrite('4_Laplacian.png',blur)
dst = cv2.convertScaleAbs(blur)
cv2.imwrite('5_convertScaleAbs.png',dst)

低通道滤波

# 线性滤波,低通滤波
dst = cv2.filter2D(img_gray, -1, kernel)
cv2.imwrite('6_filter2D.png',dst)

双边滤波:平滑 用于消除噪音

# 双边滤波
dst = cv2.bilateralFilter(dst, 9, 100, 100)
cv2.imwrite('7_bilateralFilter.png',dst)

膨胀 加强白色

dst = cv2.dilate(dst, kernel2)
cv2.imwrite('8_dilate.png',dst)

二值化

ret, dst = cv2.threshold(dst, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2.imwrite('9_threshold.png',dst)

<br> (二维码自动识别)

腐蚀 强化黑色

dst = cv2.erode(dst, kernel15)
cv2.imwrite('10_erode.png',dst)

Candy 突出边缘

dst = cv2.Canny(dst, 50, 150)
cv2.imwrite('11_Canny.png',dst)

最后的效果:

附 “图像传感器与信号处理——SFR算法/ISO 12233解读”

https://blog.csdn.net/weixin_44580210/article/details/104653950

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值