【问题标题】:Remove small objects in a mask and generate a new binary mask out of for loop移除掩码中的小对象并在 for 循环外生成新的二进制掩码
【发布时间】:2019-01-06 23:23:02
【问题描述】:

感谢您的帮助;

这部分代码允许我绘制我想要的,但我需要将结果(具有 >500 个区域对象的二进制图像)分配给一个变量以进行进一步处理

Improved_label = np.zeros_like(label_image)

#props = regionprops(label_image)

for R in regionprops(label_image):
    if R.area > 500:
        # draw the region (I'm sure there's a more efficient way of doing it)
        for c in R.coords:  
            Improved_label[c[0], c[1]] = 1

#Improved_labe1 = Improved_label > 1

【问题讨论】:

    标签: label generate


    【解决方案1】:

    显然,变量名称开头的“改进”名称有问题(不知道为什么)。但无论如何,这里有两个解决这个问题的方法。希望对有Matlab背景的人有所帮助:

    -------------选项A--------------

    label2_test = np.zeros_like(label_image)
    
    for R in regionprops(label_image):
        if R.area > 1000:
            # draw the region (I'm sure there's a more efficient way of doing it)
            for c in R.coords:  
                label2_test[c[0], c[1]] = 1
    
    label2_test = label2_test > 0
    
    plt.imshow(labe2_test)
    

    ----------------选项B-----------------

    from skimage import morphology
    labe1_improved = morphology.remove_small_objects(label_image, min_size=1000)
    

    【讨论】:

      猜你喜欢
      • 2017-10-22
      • 2017-03-19
      • 1970-01-01
      • 2020-04-13
      • 2018-07-21
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 2021-09-03
      相关资源
      最近更新 更多