【问题标题】:Remove noise from threshold TEXT images in opencv从opencv中的阈值文本图像中去除噪声
【发布时间】:2020-08-03 14:36:03
【问题描述】:

我有这些图片:

我想在所有这些图像中去除背景中的噪点(即在第 1 和第 3 中使背景为白色,在第 2 中使背景为黑色),我尝试了这种方法:Remove noise from threshold image opencv python 但它不起作用,我该怎么做做吗?

附言 这是我试图增强的原始图像。

【问题讨论】:

  • 如果你还没有这样做,你可以尝试使用腐蚀和膨胀来清理它
  • 你的问题不是很清楚。您显示嘈杂的图像,但随后显示已经干净的原始图像。您要处理哪些图像 - 3 个嘈杂的图像还是 1 个好的图像?
  • @fmw42 其实我想增强原始图像...即手写应该变暗(呃)和背景纯白色...我这样做是为了训练我的 ML 模型
  • 只需在该图像上使用 cv2.adaptiveThreshold

标签: python opencv computer-vision


【解决方案1】:

您可以在 Python/OpenCV 中对原始图像使用自适应阈值

输入:

import cv2
import numpy as np

# read image
img = cv2.imread("writing.jpg")

# convert img to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# do adaptive threshold on gray image
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 21, 10)

# write results to disk
cv2.imwrite("writing_thresh.jpg", thresh)

# display it
cv2.imshow("thresh", thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()

结果:

【讨论】:

    猜你喜欢
    • 2017-06-23
    • 2014-05-22
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2012-03-08
    相关资源
    最近更新 更多