Morphological watershed

Perform the following steps to use skimage.morphology module's implementation of a morphological watershed for binary image segmentation:

  1. First, read the image of input binary circles and convert it into grayscale with an unsigned integer type:
image = img_as_ubyte(rgb2gray(imread('images/circles.png')))
  1. Compute the exact Euclidean distance transform and find peaks in it, labeling them subsequently to use them as markers for the watershed algorithm:
distance = ndi.distance_transform_edt(image)local_maximum = peak_local_max(distance, indices=False, footprint=np.ones((3, 3)), labels=image)markers = ndi.label(local_maximum)[0]
  1. Now, run the watershed algorithm with the marker created to get the output segmentation ...

Get Python Image Processing Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.