图像重建(腐蚀和膨胀)都给出黑色图像作为输出

Image Reconstruction (Erosion and Dilation) both gives black image as output

我正在尝试使用侵蚀方法去除 this image 脸上的黑点。

我已经实现了:

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')

在这两种情况下,我的输出始终是黑色图像。这里出了什么问题?

rgb2gray 将图像输出为浮点矩阵,值在 [0;1]

因此 rescale_intensity 只是输出一个矩阵 0,因为你要求的值介于 50 和 100 之间,并且灰色图像中有 none。

你可以这样修复它:

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()