在OCR处理之前删除背景颜色或纹理 [英] Remove Background Color or Texture Before OCR Processing

查看:613
本文介绍了在OCR处理之前删除背景颜色或纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当典型的手机用户为卡尺寸的物体拍照时,图像中通常会包含一些背景纹理 - 请参阅附带的示例。在某些情况下,该背景可能会污染OCR的准确性。

When a typical mobile phone user takes picture for a card-size object, some background texture is usually included in the image -- please refer to the attached samples. In certain cases, that background could pollute OCR's accuracy.

我想知道是否有解决方案或不删除背景(有阳性)背景区域,所以可以在OCR之前裁剪它们。在附加的图像的情况下,木桌和台面呈现是候选者被移除。我想象,对比颜色可能是一个解决方案,但不是很确定。

I am wondering that whether there are solutions or not to remove the background (am positive that there are), or detect the background regions so one can just crop them off before OCR. In case of the attached images, wood tables and counter-top presenting are the candidate being removed. I would imagine that contrasting colors could be a solution but not so sure.


< img src =https://i.stack.imgur.com/SvoQe.jpgalt =enter image description here>

推荐答案

在某些情况下,作为一个人,你在背景和前景之间有麻烦,所以肯定没有办法正确地做你想要的。因为你提到OCR,我想你实际上想要消除一切不是文本。这不会使问题更容易实际上,所以我实际上假设是要保留对其他对象(如前景和背景,或白色背景上的黑色文本)高度对比度的对象。再次,没有完美的方法。

There are certain cases where you, as a human, have trouble discerning between background and foreground, so certainly there is no method to do correctly what you want. Since you mention OCR, I assume you actually want to eliminate everything that is not text. This doesn't make the question any easier actually, so what I'm actually assuming is that you want to keep objects that are highly contrasted against other objects (like foreground and background, or black text on a white background, for example). Again, there is no perfect method for that.

因此,所有这些答案都是一个简单的方法,可以帮助你的任务。该方法是准备形态学工具和用于二值化的Otsu方法的组合,因为它是统计上最优的。结果是可能值得看的地区。注意,你肯定需要将这些结果与许多其他不同的分析结合起来,一个好的OCR系统远远超出了这些直接的方法。

So, all this answer is going to do is present a simple method that might help you in your task. The method is a combination of ready morphological tools and the Otsu method for binarization since it is statistically optimal. The result are the regions that are potentially worth to look at. Note that you will certainly need to combine these results with many other different analysis, a good OCR system goes much beyond these direct approaches.

方法:1)到灰度(不感兴趣的颜色,但不同的方法肯定可以使用它们); 2)使用h-dome变换去除不相关的最大值; 3)计算形态梯度; 4)otsu的Binarize; 5)通过区域开口移除小物体。删除不相关的最大值对你的任务很重要,因为你可以有糟糕的相机与坏相机的闪光灯与一个没有经验的摄影师的组合造成的相当可怕的区域。 H-dome变换是基于形态重建,所以如果你的库有后者,但不是前者,它是直接实现它(否则你可以学习如何有效地实现后者)。离散图像的形态梯度是一种非常简单的应用方法,其即使在不良照明下也易于工作,因为它是局部方法。 Otsu的结果的阈值保持最强的边缘(可能包括噪声和其他次要特征)。您可以在所有这些之前使用高斯平滑,这可以作为噪声抑制的初始工具。小特征通过面积开口容易地去除。在Matlab中,可以这样做:

The method: 1) convert the image to grayscale (not interested in the colors, but a different method can certainly use them); 2) Use the h-dome transform to remove irrelevant maxima; 3) Calculate the morphological gradient; 4) Binarize by otsu; 5) Remove small objects by area opening. Removing irrelevant maxima is important for your task since you can have pretty horrible regions caused by a combination of bad camera's with bad camera's flash together with a inexperienced photographer. H-dome transform is based on morphological reconstruction, so if your library has the latter but not the former, it is straightforward to implement it (otherwise you could learn how to efficiently implement the latter). Morphological gradient for discrete images is a very simple method to apply which tends to work fine even with bad illumination, since it is a local method. Threshold on its result by Otsu keeps the strongest edges (which possibly includes noise and other minor features). You could precede all this by a gaussian smoothing, which might serve as an initial tool for noise suppression. The small features are readily removed by area opening. In Matlab, this can be done as in:

f = rgb2gray(imread(yourimage));
se = strel('square', 3);
g = imhmax(f, 50);                    % h-dome with h = 50
g = imdilate(g, se) - imerode(g, se); % morphological gradient
h = im2bw(g, graythresh(g));          % graythresh applies Otsu's method
w = bwareaopen(h, 50);

假设小于50像素的对象是不相关的(小文本可能不一定如此)

assuming that objects smaller than 50 pixels are irrelevant (which might not always be the case for small text).

以下是您的示例的 w 图片:

Here are the w images for your examples:

这些输出指示您应该在哪里查找文本,即连接的组件的内部。

These outputs give an indication of where you should look for text, i.e., the interior of the connected components.

这篇关于在OCR处理之前删除背景颜色或纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆