Remove points which contains pixels fewer than (N) Remove points which contains pixels fewer than (N) numpy numpy

Remove points which contains pixels fewer than (N)


Numpy/Scipy can do morphological operations just as well as Matlab can.

See scipy.ndimage.morphology, containing, among other things, binary_opening(), the equivalent of Matlab's bwareaopen().


Numpy/Scipy solution: scipy.ndimage.morphology.binary_opening. More powerful solution: use scikits-image.

from skimage import morphologycleaned = morphology.remove_small_objects(YOUR_IMAGE, min_size=64, connectivity=2)

See http://scikit-image.org/docs/0.9.x/api/skimage.morphology.html#remove-small-objects


I don't think this is what you want, but this works (uses Opencv (which uses Numpy)):

import cv2# load imagefname = 'Myimage.jpg'im = cv2.imread(fname,cv2.COLOR_RGB2GRAY)# blur imageim = cv2.blur(im,(4,4))# apply a thresholdim = cv2.threshold(im, 175 , 250, cv2.THRESH_BINARY)im = im[1]# show imagecv2.imshow('',im)cv2.waitKey(0)

Output ( image in a window ):
Output image

You can save the image using cv2.imwrite