【问题标题】:Filter regions using skimage regionprops and create a mask with filtered components使用 skimage regionprops 过滤区域并使用过滤后的组件创建蒙版
【发布时间】:2021-07-27 21:56:19
【问题描述】:

我已经通过 Otsu 的方法生成了一个蒙版,现在我必须从中消除某些不满足面积或偏心率条件的封闭区域。 我用skimage.measure.label 函数标记蒙版,然后对其应用skimage.measure.regionprops 以获取有关区域的面积和偏心率的信息。代码如下:

lab_img = label(mask)
regions = regionprops(lab_img)

for region in regions:
    if (condition):
        # Remove this region

# final_mask = mask (but without the discarded regions)

有没有人知道一种有效的方法来做到这一点? 谢谢!

【问题讨论】:

    标签: python filtering scikit-image masking


    【解决方案1】:

    这是获得您想要的东西的一种方法。关键函数是map_array,它允许您根据输入和输出值重新映射数组中的值,就像使用 Python 字典一样。因此,您可以使用regionprops_table 创建一个属性表,然后使用 NumPy 快速过滤这些列,最后使用标签列重新映射。这是一个例子:

    from skimage import measure, util
    
    ...
    
    lab_image = measure.label(mask)
    
    # table is a dictionary mapping column names to data columns
    # (NumPy arrays)
    table = regionprops_table(
        lab_image,
        properties=('label', 'area', 'eccentricity'),
    )
    condition = (table['area'] > 10) & (table['eccentricity'] < 0.5)
    
    # zero out labels not meeting condition
    input_labels = table['label']
    output_labels = input_labels * condition
    
    filtered_lab_image = util.map_array(
        lab_image, input_labels, output_labels
    )
    

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 1970-01-01
      • 2022-12-22
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 2014-04-25
      • 1970-01-01
      • 2020-01-13
      相关资源
      最近更新 更多