import cv2
img=cv2.imread('C:/Users/xpp/Desktop/Lena.png')#原始图像
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#将彩色图片转换为灰度图片
t,rst=cv2.threshold(gray,127,255,cv2.THRESH_TOZERO)#低阈值零处理
cv2.imshow("img",img)
cv2.imshow("rst",rst)
cv2.waitKey()
cv2.destroyAllWindows()
算法:低阈值零处理是将图像中大于阈值的像素值保持不变,小于或等于阈值的像素值设为黑色(0)。低阈值零处理应用在边缘提取、图像分割、目标识别等领域。
低阈值零处理方式示意图:
例子:
设定阈值为130,即大于130的像素值保持不变,小于或等于130的像素值设为0(黑色)。
retval, dst=cv2.threshold(src, thresh, maxval, type)
文献:Otsu, N. . (1979). A thresholding selection method from gray-level histogram. IEEE Trans.syst.man. & Cybern, 9(1), 62-66.
Donoho, & D., L. . (2002). Denoising by softthresholding. IEEE Transactions on Information Theory, 41(3), 613-627.
Mallat, S., Hwang, & W., L. . (1992). Singularity detection and processing with wavelets. IEEE Trans. Inform. Theory, 38(2), 617-643.
注意:低阈值零处理的图像是彩色图像还是灰度图像。通常情况下,低阈值依靠人工经验来自定义。
本文分享自 图像处理与模式识别研究所 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有