图像重建(侵蚀和膨胀)均提供黑色图像作为输出

I am trying to remove the black spots from a face of this image using the erosion methods.

我已经实现了:

img = skimage.io.imread('blemish.jpeg')
img = skimage.color.rgb2gray(img)
img_inten = skimage.exposure.rescale_intensity(img,in_range=(50,100))

diliation_seed = img_inten.copy()
diliation_seed[1:-1,1:-1] = img_inten.min()
mask = img_inten

eroded_img = skimage.morphology.reconstruction(diliation_seed,mask,method='dilation')
matplotlib.pyplot.imshow(eroded_img,cmap='gray')

在两种情况下,我的输出始终都是黑色图像。这是怎么了?

评论
  • AK94
    AK94 回复

    rgb2gray is outputting an image as a matrix of floats, with values in [0;1]

    所以rescale_intensity只是输出一个0矩阵,因为您要求的值在50到100之间,而灰色img中没有。

    您可以这样解决:

    import skimage
    from skimage import data, exposure, img_as_float
    from skimage.morphology import reconstruction
    import matplotlib.pyplot as plt
    
    img = skimage.io.imread('blemish.jpeg')
    gray_img = 255*skimage.color.rgb2gray(img) # multiply by 255 to get back in the [0;255] range
    img_inten = exposure.rescale_intensity(gray_img,in_range=(50,100))
    
    diliation_seed = img_inten.copy()
    diliation_seed[1:-1,1:-1] = img_inten.min()
    mask = img_inten
    
    eroded_img = reconstruction(diliation_seed,mask,method='dilation')
    plt.imshow(eroded_img,cmap='gray')
    plt.show()