我正在寻找一个Python函数,可以提供图像的形态组分。也就是说,该函数将返回一种度量方式,其中图像的每个像素都被替换为表示该像素所在的连通前景图像组件的整数索引。类似于这样:
Ideally我可以计算每个组件的属性,例如平均颜色、面积和标准偏差。
参考资料:
参考资料:
from skimage.segmentation import slic
from skimage.data import astronaut
import matplotlib.pyplot as plt
image = astronaut()
superpixels = slic(image, n_segments=200) # n_segments is approximate
# Plot the figure
plt.figure()
plt.subplot(121)
plt.imshow(image)
plt.title('Original image')
ax = plt.subplot(122)
plt.imshow(superpixels)
plt.title('Superpixels')
plt.colorbar()
plt.show()