5

I am trying to detect text from an input image using openCV. For that I need to remove the noise components from the image. The criteria for that which am using is that if the pixel count of certain component is less than 15 am eliminating that particular component.

e.g suppose the below given images are provided as i/p to the function: input image 1

Input image 2

As it can be seen both the images contain a lot of unwanted noisy pixels, specially the first one.

So if anyone can suggest a feasible way for achieving it, it would be highly appreciated.

Koustav
  • 733
  • 1
  • 6
  • 21
  • The text also looks like noise. See "Learning from data" in first image. – Abid Rahman K Jul 02 '12 at 16:16
  • yeah, I know. That "Learning from data" is actually not required also. It`s just the outside border color. In later stages Solid color filled "Learning from data" is obtainable. So for the time being, that particular piece of text can also be considered as noise. Infact in the first picture more or less everything needs to be eliminated. In the second case the horizontal "Learning from data" is useful, and suits our requirement. – Koustav Jul 02 '12 at 16:29
  • erosion or dilation, opening, closing? have you tried any of those? – Seçkin Savaşçı Jul 02 '12 at 18:09
  • I have already tried erosion dilation, but in that case my text is also getting tampered. Also I tried Median filter. But in that also the actual texts are becoming too blurred. – Koustav Jul 02 '12 at 18:44
  • Just a naive suggestion: The letters are aligned and the lines of text almost present themselves as bare-codes. It is not the case of your noise) Can you use these features ? – Quentin Geissmann Jul 02 '12 at 22:43

1 Answers1

2

Ok, sorry but this isn't in c and its not using opencv, however I'm sure labelling must be possible in opencv, just I haven't used it yet... so this might help... Basically the idea is:

  1. Find, and label all separate blobs in the image
  2. Remove all blobs that fall outside certain constraints (size, shape)

Here I implement this in python using scipy, but just for size (not shape, although this is easy and would get rid of the long thin lines in first image below). For this to work we must know an acceptable range of sizes for the letters - however you could determine this after labelling by looking at average blob size.. You may still get letter sized false positives - but these could possibly be removed by observing that they fall outside a certain area of concentrated blobs (as text is spacially regular)... Also minimum sentence length could be a powerful constraint.

Anyhow, code:

import scipy
from scipy import ndimage

im = scipy.misc.imread('learning2.png',flatten=1)
#threshold image, so its binary, then invert (`label` needs this):
im[im>100]=255
im[im<=100]=0
im = 255 - im
#label the image:
blobs, number_of_blobs = ndimage.label(im)
#remove all labelled blobs that are outside of our size constraints:
for i in xrange(number_of_blobs):
    if blobs[blobs==i].size < 40 or blobs[blobs==i].size>150:
        im[blobs==i] = 0
scipy.misc.imsave('out.png', im)

results:

enter image description here enter image description here

fraxel
  • 34,470
  • 11
  • 98
  • 102