diff --git a/doc/examples/plot_lena_bilateral_denoise.py b/doc/examples/plot_lena_bilateral_denoise.py index 9fd20285..57593867 100644 --- a/doc/examples/plot_lena_bilateral_denoise.py +++ b/doc/examples/plot_lena_bilateral_denoise.py @@ -1,3 +1,4 @@ + """ ==================================================== Denoising the picture of Lena using bilateral filter diff --git a/doc/examples/plot_marked_watershed.py b/doc/examples/plot_marked_watershed.py new file mode 100644 index 00000000..8f65e344 --- /dev/null +++ b/doc/examples/plot_marked_watershed.py @@ -0,0 +1,53 @@ +""" +================================ +Markers for watershed transform +================================ + +The watershed is a classical algorithm used for **segmentation**, that +is, for separating different objects in an image. + +See Wikipedia_ for more details on the algorithm. + +.. _Wikipedia: http://en.wikipedia.org/wiki/Watershed_(image_processing) + +""" + +import numpy as np +from scipy import ndimage +import matplotlib.pyplot as plt +from skimage.morphology import watershed,disk +from skimage import rank +from skimage import data +from scipy import ndimage + +# Generate an initial image with two overlapping circles +image = data.camera() + +# denoise image +denoised = rank.median(image,disk(2)) + +# find continuous region (low gradient) --> markers +markers = rank.gradient(denoised,disk(5))<10 +markers = ndimage.label(markers)[0] + +#local gradient +gradient = rank.gradient(denoised,disk(2)) + +# process the watershed +labels = watershed(gradient, markers) + +# display results +fig, axes = plt.subplots(ncols=4, figsize=(8, 2.7)) +ax0, ax1, ax2, ax3 = axes + +ax0.imshow(image, cmap=plt.cm.gray, interpolation='nearest') +ax1.imshow(gradient, cmap=plt.cm.spectral, interpolation='nearest') +ax2.imshow(markers, cmap=plt.cm.spectral, interpolation='nearest') +ax3.imshow(image, cmap=plt.cm.gray, interpolation='nearest') +ax3.imshow(labels, cmap=plt.cm.spectral, interpolation='nearest',alpha=.7) + +for ax in axes: + ax.axis('off') + +plt.subplots_adjust(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0, right=1) +plt.show()