的对象细胞计数的正确方法假设你有一个numpy.array
形式的图像:Scikit形象:在图像
vals=numpy.array([[3,24,25,6,2],[8,7,6,3,2],[1,4,23,23,1],[45,4,6,7,8],[17,11,2,86,84]])
而且要计算多少个小区各对象的内部,给予(实施例)的阈值:
from scipy import ndimage
from skimage.measure import regionprops
blobs = numpy.where(vals>17, 1, 0)
labels, no_objects = ndimage.label(blobs)
props = regionprops(blobs)
如果选中,这给出了超过阈值的4级不同的对象的图像:
In[1]: blobs
Out[1]:
array([[0, 1, 1, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 1, 1, 0],
[1, 0, 0, 0, 0],
[0, 0, 0, 1, 1]])
事实上:
In[2]: no_objects
Out[2]: 4
我要计算每个对象的细胞(或区域)的数量。预期的结果是与object ID: number of cells
格式的词典:
size={0:2,1:2,2:1,3:2}
我尝试:
size={}
for label in props:
size[label]=props[label].area
返回一个错误:
Traceback (most recent call last):
File "<ipython-input-76-e7744547aa17>", line 3, in <module>
size[label]=props[label].area
TypeError: list indices must be integers, not _RegionProperties
我明白我使用label
不当,但目的是迭代对象。 如何做到这一点?
我喜欢这个,谢谢。我的解决方案只是为了解决这个问题,但我们知道性能是关键。 – FaCoffee