scipy ndimage measurement labeling is not working properly

给你一囗甜甜゛ 提交于 2019-12-24 23:14:34

问题


I am trying to label this image into two regions:

And here is my code:

from scipy.ndimage import measurements,morphology 
from PIL import Image
from numpy import *
im = array(Image.open('two_leds.png').convert('L'))
im = 1*(im<200)
result = Image.fromarray((im * 255).astype(uint8))
result.save('results.png')
labels,  nbr_objects = measurements.label(im)
print 'number of objects equals: {}'.format(nbr_objects)  

Here is the filtered image "results.png" with low-pass filter

My problem is the output that I am getting is 1 while I am expecting 2

>>> number of objects equals: 1

Is there something wrong with the labeling code itself. It seems to me pretty straightforward


回答1:


I'm pretty sure you're counting the white pixels rather than the black pixels. Try inverting the image and then count.



来源:https://stackoverflow.com/questions/27977303/scipy-ndimage-measurement-labeling-is-not-working-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!