scipy ndimage测量标签无法正常工作 [英] scipy ndimage measurement labeling is not working properly

查看:149
本文介绍了scipy ndimage测量标签无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将此图像标记为两个区域:

I am trying to label this image into two regions:

这是我的代码:

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)  

这是带有低通滤波器的已过滤图像"results.png"

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

我的问题是我得到的输出是1而我期望是2

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

推荐答案

我很确定您是在计算白色像素而不是黑色像素.尝试反转图像,然后计数.

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

这篇关于scipy ndimage测量标签无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆