ENH contours of segmentation in segmentation tutorial

This commit is contained in:
emmanuelle
2011-12-08 11:04:34 +01:00
parent d5994c6715
commit 4e3895b44b
2 changed files with 20 additions and 3 deletions
@@ -107,6 +107,7 @@ elevation_map = sobel(coins)
segmentation = watershed(elevation_map, markers)
plt.figure(figsize=(7, 3))
plt.subplot(131)
plt.imshow(markers, cmap=plt.cm.spectral, interpolation='nearest')
@@ -124,12 +125,24 @@ plt.title('segmentation')
plt.subplots_adjust(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0,
right=1)
# ------------------- Removing a few small holes ---------------------
segmentation = ndimage.binary_fill_holes(segmentation - 1)
#------------------ Labeling the coins --------------------------------
labeled_coins, _ = ndimage.label(segmentation - 1)
labeled_coins, _ = ndimage.label(segmentation)
plt.figure(figsize=(6, 4))
plt.figure(figsize=(6, 3))
plt.subplot(121)
plt.imshow(coins, cmap=plt.cm.gray, interpolation='nearest')
plt.contour(segmentation, [0.5], linewidths=1.2, colors='y')
plt.axis('off')
plt.subplot(122)
plt.imshow(labeled_coins, cmap=plt.cm.spectral, interpolation='nearest')
plt.axis('off')
plt.subplots_adjust(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0,
right=1)
plt.show()
+5 -1
View File
@@ -131,9 +131,13 @@ markers for the background were not well distributed, the barriers in the
elevation map were high enough for these markers to flood the entire
background.
We remove a few small holes with mathematical morphology::
>>> segmentation = ndimage.binary_fill_holes(segmentation - 1)
We can now label all the coins one by one using ``ndimage.label``::
>>> labeled_coins, _ = ndimage.label(segmentation - 1)
>>> labeled_coins, _ = ndimage.label(segmentation)
.. image:: ../../_images/plot_coins_segmentation_5.png
:target: ../auto_examples/applications/plot_coins_segmentation.html