2013-09-23 41 views
1

我在这里有一个黑色/白色图像,我准备准备好放入OCR中,即Tesseract。但是Tesseract无法检测到任何噪声区域。 enter image description here发票/成像:消除图像中的噪音

我在这里寻找什么样的解决方案来消除噪音?由于Tesseract无法识别它,我认为去除是最好的选择。

回答

2

您可以使用TextCleaner,一个ImageMagick脚本来清理文本背景。

+0

当我回来了,我会尝试这个下周在我的工作上,虽然我希望授权费不太差。 – skiwi

0

如果万一你正在寻找一个Python代码,这里的人会去除噪声

import cv2 
import numpy as np 

# load color image 
im = cv2.imread('input.jpg') 

# smooth the image with alternative closing and opening 
# with an enlarging kernel 
morph = im.copy() 

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 1)) 
morph = cv2.morphologyEx(morph, cv2.MORPH_CLOSE, kernel) 
morph = cv2.morphologyEx(morph, cv2.MORPH_OPEN, kernel) 

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2)) 

# take morphological gradient 
gradient_image = cv2.morphologyEx(morph, cv2.MORPH_GRADIENT, kernel) 

# split the gradient image into channels 
image_channels = np.split(np.asarray(gradient_image), 3, axis=2) 

channel_height, channel_width, _ = image_channels[0].shape 

# apply Otsu threshold to each channel 
for i in range(0, 3): 
    _, image_channels[i] = cv2.threshold(~image_channels[i], 0, 255, cv2.THRESH_OTSU | cv2.THRESH_BINARY) 
    image_channels[i] = np.reshape(image_channels[i], newshape=(channel_height, channel_width, 1)) 

# merge the channels 
image_channels = np.concatenate((image_channels[0], image_channels[1], image_channels[2]), axis=2) 

# save the denoised image 
cv2.imwrite('output.jpg', image_channels) 

工作上面的代码不会得到好的结果,如果你正在处理的图像是发票(或有在白色背景上的大量文字)。 为了得到这样的图像了良好的效果,去除

gradient_image = cv2.morphologyEx(morph, cv2.MORPH_GRADIENT, kernel) 

,并通过morph OBJ的分割功能,并删除了~符号内的循环