【发布时间】:2014-02-05 18:28:12
【问题描述】:
我想使用 numpy 的标签分割我的图像,然后根据在每个标签中找到的索引数量删除满足我标准的那些。例如,如果像这样创建带有我分割区域的图像并使用 scipy 的label 进行分割:
from numpy import ones, zeros
from numpy.random import random_integers
from scipy.ndimage import label
image = zeros((512, 512), dtype='int')
regionator = ones((11, 11), dtype='int')
xs = random_integers(5, 506, size=500)
ys = random_integers(5, 506, size=500)
for x, y in zip(xs, ys):
image[x-5:x+6, y-5:y+6] = regionator
labels, n_labels = label(image)
现在我想检索大小大于 121 像素(或一个区域器大小)的每个区域的索引。然后我想取这些索引并将它们设置为零,这样它们就不再是标记图像的一部分。完成这项任务最有效的方法是什么?
基本上类似于 MATLAB 的 regionprops 或利用 IDL 的 reverse_indices 从其直方图函数输出。
【问题讨论】: