scikit-shape Image Segmentation

Image Segmentation is the task of identifying objects or regions in a given image. One way to achieve this is a to create label arrays, in which the label of a pixel denotes which region the pixel belongs to. scikit-shape includes different algorithms to compute label arrays from input images. In this example, we use the region-regularized topology optimization algorithm to segment color images into distinct regions, such that the image intensity in each region can be modeled with a Laplacian distribution.

Download the Python code for Edge-Preserving Smoothing.


import matplotlib.pyplot as plt
from skshape.image.segmentation import segment_by_topology

image = plt.imread('bush.png')[:,:,0:3]

label, new_image = segment_by_topology( image, n_phases=4, model='Laplace', mu=30, sigma=6, init_method='zero', gamma=0.5, epsilon=0 )

plt.figure()
plt.subplot(1,3,1); plt.imshow(image)
plt.axis('off'); plt.title('Original image')
plt.subplot(1,3,2); plt.imshow(label)
plt.axis('off'); plt.title('Segmentation')
plt.subplot(1,3,3); plt.imshow(new_image)
plt.axis('off'); plt.title('Assigned colors')
    
plt.show()
examples/color_segmentation_out.png