我正在做教科书的图片,如问题和手写笔记,我想要二值图像,用于少数几个不同的任务,主要是OCR。但问题是,如果一个图像有一点阴影或亮度水平不连续,它会给我很多黑色区域覆盖我的文字。
我在我的图片上使用了from skimage.filters import try_all_threshold
,发现有些图片处理得很好,而另一些则不行。我不能使用本地阈值,在这里,我必须根据不同的图像更改参数,因为我想自动化OCR的过程。
img_path = DIR+str(11)+'.png'
sk_image = imread(img_path,as_gray=True)
fig,ax = try_all_threshold(sk_image,figsize=(20,15))
plt.savefig('threshold.jpeg',dpi=350)
为什么在图像中形成这个黑色区域,我如何删除它?
像Bilateral
或Gauss
这样的去噪滤波器可以吗?如果没有,请提出一些其他的技巧?
发布于 2020-08-27 16:26:06
下面是在Python/OpenCV中使用除法规范化的一种方法。
sharpen
H_(214)将灰度图像分割为平滑图像
H19
输入:
import cv2
import numpy as np
import skimage.filters as filters
# read the image
img = cv2.imread('math.png')
# convert to gray
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# blur
smooth = cv2.GaussianBlur(gray, (95,95), 0)
# divide gray by morphology image
division = cv2.divide(gray, smooth, scale=255)
# sharpen using unsharp masking
sharp = filters.unsharp_mask(division, radius=1.5, amount=1.5, multichannel=False, preserve_range=False)
sharp = (255*sharp).clip(0,255).astype(np.uint8)
# threshold
thresh = cv2.threshold(sharp, 0, 255, cv2.THRESH_OTSU )[1]
# save results
cv2.imwrite('math_division.jpg',division)
cv2.imwrite('math_division_sharp.jpg',sharp)
cv2.imwrite('math_division_thresh.jpg',division)
# show results
cv2.imshow('smooth', smooth)
cv2.imshow('division', division)
cv2.imshow('sharp', sharp)
cv2.imshow('thresh', thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()
部门形象:
锐化图像:
缩影图像:
https://stackoverflow.com/questions/63612617
复制相似问题