【问题标题】:How to deduce automatically if the processed image needs morphological post-processing or not?处理后的图像是否需要形态学后处理,如何自动推断?
【发布时间】:2020-09-03 02:23:05
【问题描述】:
  • 我使用 Deep-Learning 进行了分割,之后我注意到有时分割的形状看起来不错,但有时需要更多的后处理,使用 形态学操作。李>
  • 分割的形状是一个环形,在极少数情况下是实心圆形,如您在所附图片中所见。
  • 当这个环分割是闭合形状时,没有问题,但是当环打开时有问题,因为我无法正确测量内部区域(环内部)和面积计算是整个项目的目标。
  • 那么如何自动检测我的分割图像是否需要后处理(使用形态学运算)以及在这种情况下首选哪种形态学?所以我可以计算here提到的面积。

提前致谢

import numpy as np
import matplotlib.pyplot as plt
from skimage.io import imread, imsave
# import scipy.ndimage as ndi 
from skimage import morphology, filters, feature

seg = imread('prediction.png')
# meijering alpha=None,
# rem2 = morphology.remove_small_objects(seg, 4)
resf = filters.meijering(seg, sigmas=range(1, 3, 1),  black_ridges=False)

sobel = filters.sobel(resf)
# diam = morphology.diameter_closing(sobel, 64, connectivity=2)
gaussian = filters.gaussian(sobel, sigma= 1)
val = filters.threshold_otsu(gaussian)
resth = gaussian < val 

# Morphology
SE = morphology.diamond(2)
# SE = np.ones((3,3))
# SE = morphology.disk(2)
# SE = square(7)
# SE = rectangle(3,3)
# SE = octagon(3, 3)

erosion  = morphology.binary_erosion( resth, SE).astype(np.uint8)
dilation = morphology.binary_dilation(resth, SE).astype(np.uint8)
opening  = morphology.binary_opening( resth, SE).astype(np.uint8)
closing  = morphology.binary_closing( resth, SE).astype(np.uint8)
#thinner = morphology.thin(erosion, max_iter=4)

rem  = morphology.remove_small_holes(resth, 2)

# entropy  = filters.rank.entropy(resth, SE) 
# print(seg.shape)

plt.figure(num='PProc')
# 1
plt.subplot('335')
plt.imshow(rem,cmap='gray')
plt.title('rem')
plt.axis('off')
# 2
plt.subplot('336')
plt.imshow(dilation,cmap='gray')
plt.title('dilation')
plt.axis('off')
# 3
plt.subplot('337')
plt.imshow(opening,cmap='gray')
plt.title('opening')
plt.axis('off')
# 4
plt.subplot('338')
plt.imshow(closing,cmap='gray')
plt.title('closing')
plt.axis('off')
# 5
plt.subplot('332')
plt.imshow(seg,cmap='gray')
plt.title('segmented')
plt.axis('off')
# 6
plt.subplot('333')
plt.imshow(resf,cmap='gray')
plt.title('meijering')
plt.axis('off')
# 7
# 8
plt.subplot('334')
plt.imshow(resth,cmap='gray')
plt.title('threshold_otsu')
plt.axis('off')
# 9
plt.subplot('339')
plt.imshow(erosion,cmap='gray')
plt.title('erosion')
plt.axis('off')
#
plt.show()

【问题讨论】:

    标签: python image-processing image-segmentation image-morphology


    【解决方案1】:

    也许这会以某种方式帮助解决问题。 图片:

    1. Connected Components:4 , Convexy: yes, Euler number(by one object):1
    2. Connected Components:1 , Convexy: no, Euler number: 1
    3. Connected Components:1 , Convexy: yes, Euler number: 0
    4. Connected Components:1 , Convexy: yes, Euler number: 1
    

    欧拉数这是该区域中的对象数减去这些对象中的孔数。 见 skimage.measure.regionprops,https://www.mathworks.com/help/images/ref/regionprops.html 或开源https://octave.sourceforge.io/image/function/regionprops.html

    【讨论】:

    • 感谢您的建议,现在我必须在 python 和 scikit-image 上寻找相同的概念 :)
    • 见 Skimage.measure.regionprops euler_number,convex_area/area ratio
    【解决方案2】:

    通过复制post 上的答案,并稍微调整一下,答案是:通过检查标记区域的数量,所以如果区域少于 3 个,则大部分是需要形态学操作,否则我有一个闭合的环,那么就有3个标注区域。

    from skimage.io import imread
    import numpy as np
    from skimage.measure import label, regionprops
    from skimage.color import label2rgb
    
    img = imread(os.path.join(path,im_name))
    labeled = label(img, background=2)
    overlay = label2rgb(labeled)
    
    LV = overlay[...,0] + overlay[...,1]
    LV = LV > 1
    
    if (np.sum(LV)):
        print('This image doesnt need Morphological processing')
    else:
        print('This image needs Morphological processing')
    

    【讨论】:

      猜你喜欢
      • 2010-11-07
      • 2019-06-18
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      相关资源
      最近更新 更多