Merge pull request #225 from lct123/ImageSegTut

DOC: Clean up image segmentation tutorial.
This commit is contained in:
Stefan van der Walt
2012-07-20 15:54:43 -07:00
2 changed files with 33 additions and 7 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ plt.title('Input image')
plt.subplot(132)
plt.imshow(edges, cmap=plt.cm.gray)
plt.title('Sobel edges')
plt.title('Canny edges')
plt.subplot(133)
plt.imshow(edges * 0)
@@ -47,10 +47,6 @@ detection, we use the `Canny detector
As the background is very smooth, almost all edges are found at the
boundary of the coins, or inside the coins.
Now that we have contours that delineate the outer boundary of the coins,
we fill the inner part of the coins using the
``ndimage.binary_fill_holes`` function, which uses mathematical morphology
to fill the holes.
::
@@ -61,6 +57,15 @@ to fill the holes.
:target: ../auto_examples/applications/plot_coins_segmentation.html
:align: center
Now that we have contours that delineate the outer boundary of the coins,
we fill the inner part of the coins using the
``ndimage.binary_fill_holes`` function, which uses mathematical morphology
to fill the holes.
.. image:: ../../_images/plot_coins_segmentation_4.png
:target: ../auto_examples/applications/plot_coins_segmentation.html
:align: center
Most coins are well segmented out of the background. Small objects from
the background can be easily removed using the ``ndimage.label``
function to remove objects smaller than a small threshold.
@@ -78,6 +83,10 @@ has not been segmented correctly at all. The reason is that the contour
that we got from the Canny detector was not completely closed, therefore
the filling function did not fill the inner part of the coin.
.. image:: ../../_images/plot_coins_segmentation_5.png
:target: ../auto_examples/applications/plot_coins_segmentation.html
:align: center
Therefore, this segmentation method is not very robust: if we miss a
single pixel of the contour of the object, we will not be able to fill
it. Of course, we could try to dilate the contours in order to
@@ -117,12 +126,29 @@ separate the coins from the background.
.. image:: data/elevation_map.jpg
:align: center
and here is the corresponding 2-D plot:
.. image:: ../../_images/plot_coins_segmentation_6.png
:target: ../auto_examples/applications/plot_coins_segmentation.html
:align: center
The next step is to find markers of the background and the coins based on the
extreme parts of the histogram of grey values::
>>> markers = np.zeros_like(coins)
>>> markers[coins < 30] = 1
>>> markers[coins > 150] = 2
.. image:: ../../_images/plot_coins_segmentation_7.png
:target: ../auto_examples/applications/plot_coins_segmentation.html
:align: center
Let us now compute the watershed transform::
>>> from skimage.morphology import watershed
>>> segmentation = watershed(elevation_map, markers)
.. image:: ../../_images/plot_coins_segmentation_4.png
.. image:: ../../_images/plot_coins_segmentation_8.png
:target: ../auto_examples/applications/plot_coins_segmentation.html
:align: center
@@ -139,7 +165,7 @@ We can now label all the coins one by one using ``ndimage.label``::
>>> labeled_coins, _ = ndimage.label(segmentation)
.. image:: ../../_images/plot_coins_segmentation_5.png
.. image:: ../../_images/plot_coins_segmentation_9.png
:target: ../auto_examples/applications/plot_coins_segmentation.html
:align: center