opencv - Pixel height and width of blobs -


i have image blobs. 1 pixel dot , not. when use cvblobslibs find height , width of 1 pixel dot, shows value equals zero. correct? tried use contours fill 1 dot pixel seems fail too. other approach can remove 1 dot pixel or remove height or width equal zero?

i not sure why area of single pixel element zero. ( mind says should one). check out documentation contourarea. says, area calculated using green formula, area , number of pixels may different.

secondly, remove noise, can use medianfilter. have shown below using python.

input image :

enter image description here

now code :

>>> img2 = cv2.imread('d:\abid_rahman_k\work_space\mask.png',0)  >>> contours,hierarchy = cv2.findcontours(img,cv2.retr_list,cv2.chain_approx_simple) 

number of non-zero pixels:

>>> cv2.countnonzero(img2) 121 

now apply medianfilter , check again number of non-zero pixels:

>>> blur = cv2.medianblur(img2,5) >>> cv2.countnonzero(blur) 0 

output image :

enter image description here

edit:

if image has object, not affected blurring.

input image :

enter image description here

output image :

enter image description here

edit after second comment answer.

as mizuki commented, there chance closely placed objects connected each other after median filtering. understand this, give here image wikipedia page. check how yellow objects seperated black lines connected after using median filter of high radius.

enter image description here

it because, median filter uses window calculates median of values in windows , replaces center element median. size of window increases, more elements used calculate median. narrow gaps removed.

wikipedia articles 1 : link

also see link simple explanation : link

so avoid this, there method called erosion , dilation ( both implemented in opencv). saying, erosion reduces size of white object , dilation increases size of white object.

so erosion removes small white pixels, reduces size of our object. use dilate size. since, white noises removed due erosion, won't come in dilation.

this procedure remove noise.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -