Removing noisy pixels using opencv

I am trying to detect text from an input image using openCV. To do this, I need to remove the noise components from the image. The criteria for what I use is that if the number of pixels in a particular component is less than 15 in the morning, eliminating that particular component.

for example, suppose the images below are provided as i / p for a function: input image 1

Input image 2

As you can see, both images contain many unwanted noise pixels, especially the first.

Therefore, if someone can offer an acceptable way to achieve it, he will be highly appreciated.

+5
source share
1 answer

, , c opencv, , opencv, ... ... :

  • , (, )

python scipy, ( , ). - , . , , , , ( -)... .

, :

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)

:

enter image description hereenter image description here

+2

All Articles