首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何去除opencv中图像中的噪声?

如何去除opencv中图像中的噪声?
EN

Stack Overflow用户
提问于 2022-05-24 18:26:04
回答 1查看 230关注 0票数 -1

如何在opencv中去除图像中的噪声(见输入图片)?我想要实现的输出,我将得到白色背景和黑色的文本只。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-24 19:05:48

假设灰度图像,您可以部分地消除这样的噪声:

代码语言:javascript
运行
复制
# thresholding
thresh, thresh_img = cv.threshold(img, 128, 255, 0, cv.THRESH_BINARY)

# erode the image to *enlarge* black blobs
erode = cv.erode(thresh_img, cv.getStructuringElement(cv.MORPH_ELLIPSE, (3,3)))

# fill in the black blobs that are not surrounded by white:
_, filled, _, _ = cv.floodFill(erode, None, (0,0), 255)

# binary and with the threshold image to get rid of the thickness from erode
out = (filled==0) & (thresh_img==0)
# also
# out = cv.bitwise_and(filled, thresh_img)

输出不干净(文本行之间的一些黑点,可以通过阈值连接组件的大小来进一步去除),但这应该是一个好的开始:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72367780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档