@@ -0,0 +1,1298 @@
+%22%22%22%0A=============================================%0AFind Regular Segments Using Compact Watershed%0A=============================================%0A%0AThe watershed transform is commonly used as a starting point for many%0Asegmentation algorithms. However, without a judicious choice of seeds, it%0Acan produce very uneven fragment sizes, which can be difficult to deal with%0Ain downstream analyses.%0A%0AThe *compact* watershed transform remedies this by favoring seeds that are%0Aclose to the pixel being considered.%0A%0ABoth are implemented in the :py:func:%60skimage.morphology.watershed%60 function.%0ATo use the compact form, simply pass a %60%60compactness%60%60 value greater than 0.%0A%22%22%22%0A%0Aimport numpy as np%0Afrom skimage import data, util, filters, color%0Afrom skimage.morphology import watershed%0Aimport matplotlib.pyplot as plt%0A%0Acoins = data.coins()%0Aedges = filters.sobel(coins)%0A%0Agrid = util.regular_grid(coins.shape, n_points=468)%0A%0Aseeds = np.zeros(coins.shape, dtype=int)%0Aseeds%5Bgrid%5D = np.arange(seeds%5Bgrid%5D.size).reshape(seeds%5Bgrid%5D.shape) + 1%0A%0Aw0 = watershed(edges, seeds)%0Aw1 = watershed(edges, seeds, compactness=0.01)%0A%0Afig, (ax0, ax1) = plt.subplots(1, 2)%0A%0Aax0.imshow(color.label2rgb(w0, coins))%0Aax0.set_title('Classical watershed')%0A%0Aax1.imshow(color.label2rgb(w1, coins))%0Aax1.set_title('Compact watershed')%0A%0Aplt.show()%0A

Add compact watershed gallery example