

.. _sphx_glr_auto_examples_segmentation:

Segmentation of objects
-----------------------



.. raw:: html

    <div class="sphx-glr-thumbnails">

.. thumbnail-parent-div-open

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Construct a region boundary RAG with the rag_boundary function. The function  :pyskimage.graph.rag_boundary takes an edge_map argument, which gives the significance of a feature (such as edges) being present at each pixel. In a region boundary RAG, the edge weight between two regions is the average value of the corresponding pixels in edge_map along their shared boundary.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_rag_boundary_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_rag_boundary.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Region Boundary based Region adjacency graphs (RAGs)</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example constructs a Region Adjacency Graph (RAG) and merges regions which are similar in color. We construct a RAG and define edges as the difference in mean color. We then join regions with similar mean color.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_rag_mean_color_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_rag_mean_color.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Region adjacency graph (RAG) Thresholding</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example constructs a Region Adjacency Graph (RAG) and recursively performs a Normalized Cut on it [1]_.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_ncut_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_ncut.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Normalized Cut</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The watershed transform is commonly used as a starting point for many segmentation algorithms. However, without a judicious choice of seeds, it can produce very uneven fragment sizes, which can be difficult to deal with in downstream analyses.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_compact_watershed_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_compact_watershed.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Find Regular Segments Using Compact Watershed</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Thresholding is used to create a binary image from a grayscale image [1]_.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_thresholding_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_thresholding.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Thresholding</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example constructs a Region Adjacency Graph (RAG) and draws it with the rag_draw method.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_rag_draw_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_rag_draw.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Drawing Region Adjacency Graphs (RAGs)</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The Chan-Vese segmentation algorithm is designed to segment objects without clearly defined boundaries. This algorithm is based on level sets that are evolved iteratively to minimize an energy, which is defined by weighted values corresponding to the sum of differences intensity from the average value outside the segmented region, the sum of differences from the average value inside the segmented region, and a term which is dependent on the length of the boundary of the segmented region.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_chan_vese_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_chan_vese.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Chan-Vese Segmentation</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The peak_local_max function returns the coordinates of local peaks (maxima) in an image. Internally, a maximum filter is used for finding local maxima. This operation dilates the original image and merges neighboring local maxima closer than the size of the dilation. Locations where the original image is equal to the dilated image are returned as local maxima.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_peak_local_max_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_peak_local_max.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Finding local maxima</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The multi-Otsu threshold [1]_ is a thresholding algorithm that is used to separate the pixels of an input image into several different classes, each one obtained according to the intensity of the gray levels within the image.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_multiotsu_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_multiotsu.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Multi-Otsu Thresholding</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The random walker algorithm [1]_  determines the segmentation of an image from a set of markers labeling several phases (2 or more). An anisotropic diffusion equation is solved with tracers initiated at the markers&#x27; position. The local diffusivity coefficient is greater if neighboring pixels have similar values, so that diffusion is difficult across high gradients. The label of each unknown pixel is attributed to the label of the known marker that has the highest probability to be reached first during this diffusion process.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_random_walker_segmentation_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_random_walker_segmentation.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Random walker segmentation</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example is about comparing the segmentations obtained using the plain SLIC method [1]_ and its masked version maskSLIC [2]_.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_mask_slic_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_mask_slic.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Apply maskSLIC vs SLIC</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Niblack and Sauvola thresholds are local thresholding techniques that are useful for images where the background is not uniform, especially for text recognition [1]_, [2]_. Instead of calculating a single global threshold for the entire image, several thresholds are calculated for every pixel by using specific formulae that take into account the mean and standard deviation of the local neighborhood (defined by a window centered around the pixel).">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_niblack_sauvola_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_niblack_sauvola.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Niblack and Sauvola Thresholding</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Given several connected components represented by a label image, these connected components can be expanded into background regions using :pyskimage.segmentation.expand_labels. In contrast to :pyskimage.morphology.dilation this method will not let connected components expand into neighboring connected components with lower label number.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_expand_labels_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_expand_labels.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Expand segmentation labels without overlap</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The watershed is a classical algorithm used for segmentation, that is, for separating different objects in an image.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_watershed_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_watershed.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Watershed segmentation</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to segment an image with image labelling. The following steps are applied:">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_label_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_label.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Label image regions</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example compares four popular low-level image segmentation methods.  As it is difficult to obtain good segmentations, and the definition of &quot;good&quot; often depends on the application, these methods are usually used for obtaining an oversegmentation, also known as superpixels. These superpixels then serve as a basis for more sophisticated algorithms such as conditional random fields (CRF).">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_segmentations_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_segmentations.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Comparison of segmentation and superpixel algorithms</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="When segmenting an image, you may want to combine multiple alternative segmentations. The :pyskimage.segmentation.join_segmentations function computes the join of two segmentations, in which a pixel is placed in the same segment if and only if it is in the same segment in both segmentations.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_join_segmentations_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_join_segmentations.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Find the intersection of two segmentations</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates the use of the merge_nodes function of a Region Adjacency Graph (RAG). The RAG class represents an undirected weighted graph which inherits from networkx.Graph class. When a new node is formed by merging two nodes, the edge weight of all the edges incident on the resulting node can be updated by a user defined function weight_func.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_rag_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_rag.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Region Adjacency Graphs (RAGs)</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example constructs a Region Adjacency Graph (RAG) and progressively merges regions that are similar in color. Merging two adjacent regions produces a new region with all the pixels from the merged regions. Regions are merged until no highly similar region pairs remain.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_rag_merge_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_rag_merge.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Region adjacency graph (RAG) Merging</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="In this example, we show the error on measuring perimeters, comparing classic approximations and Crofton ones. For that, we estimate the perimeter of an object (either a square or a disk) and its rotated version, as we increase the rotation angle.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_perimeters_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_perimeters.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Measure perimeters with different estimators</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="We detect local maxima in a galaxy image. The image is corrupted by noise, generating many local maxima. To keep only those maxima with sufficient local contrast, we use h-maxima.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_extrema_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_extrema.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Extrema</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This toy example shows how to compute the size of every labelled region in a series of 10 images. We use 2D images and then 3D images. The blob-like regions are generated synthetically. As the volume fraction (i.e., ratio of pixels or voxels covered by the blobs) increases, the number of blobs (regions) decreases, and the size (area or volume) of a single region can get larger and larger. The area (size) values are available in a pandas-compatible format, which makes for convenient data analysis and visualization.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_regionprops_table_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_regionprops_table.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Explore and visualize region properties with pandas</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to calculate the Hausdorff distance between two sets of points. The Hausdorff distance is the maximum distance between any point on the first set and its nearest point on the second set, and vice-versa.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_hausdorff_distance_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_hausdorff_distance.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Hausdorff Distance</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to perform hierarchical merging on region boundary Region Adjacency Graphs (RAGs). Region boundary RAGs can be constructed with the :pyskimage.graph.rag_boundary function. The regions with the lowest edge weights are successively merged until there is no edge with weight less than thresh. The hierarchical merging is done through the :pyskimage.graph.merge_hierarchical function. For an example of how to construct region boundary based RAGs, see plot_rag_boundary.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_boundary_merge_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_boundary_merge.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Hierarchical Merging of Region Boundary RAGs</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Morphological Snakes [1]_ are a family of methods for image segmentation. Their behavior is similar to that of active contours (for example, Geodesic Active Contours [2]_ or Active Contours without Edges [3]_). However, Morphological Snakes use morphological operators (such as dilation or erosion) over a binary array instead of solving PDEs over a floating point array, which is the standard approach for active contours. This makes Morphological Snakes faster and numerically more stable than their traditional counterpart.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_morphsnakes_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_morphsnakes.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Morphological Snakes</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="When trying out different segmentation methods, how do you know which one is best? If you have a ground truth or gold standard segmentation, you can use various metrics to check how close each automated method comes to the truth. In this example we use an easy-to-segment image as an example of how to interpret various segmentation metrics. We will use the adapted Rand error and the variation of information as example metrics, and see how oversegmentation (splitting of true segments into too many sub-segments) and undersegmentation (merging of different true segments into a single segment) affect the different scores.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_metrics_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_metrics.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Evaluating segmentation metrics</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Flood fill is an algorithm to identify and/or change adjacent values in an image based on their similarity to an initial seed point [1]_. The conceptual analogy is the &#x27;paint bucket&#x27; tool in many graphic editors.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_floodfill_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_floodfill.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Flood Fill</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows an illustration of the computation of the Euler number [1]_ in 2D and 3D objects.">

.. only:: html

  .. image:: /auto_examples/segmentation/images/thumb/sphx_glr_plot_euler_number_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_segmentation_plot_euler_number.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Euler number</div>
    </div>


.. thumbnail-parent-div-close

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/segmentation/plot_rag_boundary
   /auto_examples/segmentation/plot_rag_mean_color
   /auto_examples/segmentation/plot_ncut
   /auto_examples/segmentation/plot_compact_watershed
   /auto_examples/segmentation/plot_thresholding
   /auto_examples/segmentation/plot_rag_draw
   /auto_examples/segmentation/plot_chan_vese
   /auto_examples/segmentation/plot_peak_local_max
   /auto_examples/segmentation/plot_multiotsu
   /auto_examples/segmentation/plot_random_walker_segmentation
   /auto_examples/segmentation/plot_mask_slic
   /auto_examples/segmentation/plot_niblack_sauvola
   /auto_examples/segmentation/plot_expand_labels
   /auto_examples/segmentation/plot_watershed
   /auto_examples/segmentation/plot_label
   /auto_examples/segmentation/plot_segmentations
   /auto_examples/segmentation/plot_join_segmentations
   /auto_examples/segmentation/plot_rag
   /auto_examples/segmentation/plot_rag_merge
   /auto_examples/segmentation/plot_perimeters
   /auto_examples/segmentation/plot_extrema
   /auto_examples/segmentation/plot_regionprops_table
   /auto_examples/segmentation/plot_hausdorff_distance
   /auto_examples/segmentation/plot_boundary_merge
   /auto_examples/segmentation/plot_morphsnakes
   /auto_examples/segmentation/plot_metrics
   /auto_examples/segmentation/plot_floodfill
   /auto_examples/segmentation/plot_euler_number

