Module Expr Str ImportFrom alias Import alias identifier Import alias identifier ImportFrom alias ImportFrom alias alias alias ImportFrom alias ImportFrom alias Assign NameStore Call NameLoad SubscriptLoad Call NameLoad ExtSlice Slice Num Slice Num Assign NameStore Call NameLoad NameLoad keyword Num keyword Num keyword Num Assign NameStore Call NameLoad NameLoad keyword Num keyword Num keyword Num Assign NameStore Call NameLoad NameLoad keyword Num keyword Num keyword Num Expr Call NameLoad BinOpMod Str Call NameLoad Call AttributeLoad NameLoad attr NameLoad Expr Call NameLoad BinOpMod Str Call NameLoad Call AttributeLoad NameLoad attr NameLoad Expr Call NameLoad BinOpMod Str Call NameLoad Call AttributeLoad NameLoad attr NameLoad Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr Num Num keyword NameLoad keyword NameLoad keyword Dict Str Str Expr Call AttributeLoad NameLoad attr Num Num keyword NameLoad Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad SubscriptLoad NameLoad Index Num attr Call NameLoad NameLoad NameLoad Expr Call AttributeLoad SubscriptLoad NameLoad Index Num attr Str Expr Call AttributeLoad SubscriptLoad NameLoad Index Num attr Call NameLoad NameLoad NameLoad Expr Call AttributeLoad SubscriptLoad NameLoad Index Num attr Str Expr Call AttributeLoad SubscriptLoad NameLoad Index Num attr Call NameLoad NameLoad NameLoad Expr Call AttributeLoad SubscriptLoad NameLoad Index Num attr Str For NameStore NameLoad body Expr Call AttributeLoad NameLoad attr TupleLoad Expr Call AttributeLoad NameLoad attr TupleLoad Expr Call AttributeLoad NameLoad attr
N/A N/A 
====================================================
Comparison of segmentation and superpixel algorithms
====================================================

This example compares three popular low-level image segmentation methods.  As
it is difficult to obtain good segmentations, and the definition of "good"
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).


Felzenszwalb's efficient graph based segmentation
-------------------------------------------------
This fast 2D image segmentation algorithm, proposed in [1]_ is popular in the
computer vision community.
The algorithm has a single ``scale`` parameter that influences the segment
size. The actual size and number of segments can vary greatly, depending on
local contrast.

.. [1] Efficient graph-based image segmentation, Felzenszwalb, P.F. and
       Huttenlocher, D.P.  International Journal of Computer Vision, 2004


Quickshift image segmentation
-----------------------------

Quickshift is a relatively recent 2D image segmentation algorithm, based on an
approximation of kernelized mean-shift. Therefore it belongs to the family of
local mode-seeking algorithms and is applied to the 5D space consisting of
color information and image location [2]_.

One of the benefits of quickshift is that it actually computes a
hierarchical segmentation on multiple scales simultaneously.

Quickshift has two main parameters: ``sigma`` controls the scale of the local
density approximation, ``max_dist`` selects a level in the hierarchical
segmentation that is produced. There is also a trade-off between distance in
color-space and distance in image-space, given by ``ratio``.

.. [2] Quick shift and kernel methods for mode seeking,
       Vedaldi, A. and Soatto, S.
       European Conference on Computer Vision, 2008


SLIC - K-Means based image segmentation
---------------------------------------

This algorithm simply performs K-means in the 5d space of color information and
image location and is therefore closely related to quickshift. As the
clustering method is simpler, it is very efficient. It is essential for this
algorithm to work in Lab color space to obtain good results.  The algorithm
quickly gained momentum and is now widely used. See [3] for details.  The
``compactness`` parameter trades off color-similarity and proximity, as in the
case of Quickshift, while ``n_segments`` chooses the number of centers for
kmeans.

.. [3] Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi,
    Pascal Fua, and Sabine Suesstrunk, SLIC Superpixels Compared to
    State-of-the-art Superpixel Methods, TPAMI, May 2012.
 __future__ print_function N/A matplotlib.pyplot plt N/A numpy np skimage.data astronaut skimage.segmentation felzenszwalb slic quickshift skimage.segmentation mark_boundaries skimage.util img_as_float N/A img N/A img_as_float N/A N/A astronaut N/A N/A 2 N/A 2 N/A segments_fz N/A felzenszwalb img scale 100 sigma 0.5 min_size 50 N/A segments_slic N/A slic img n_segments 250 compactness 10 sigma 1 N/A segments_quick N/A quickshift img kernel_size 3 max_dist 6 ratio 0.5 N/A N/A print N/A Felzenszwalb's number of segments: %d N/A len N/A N/A np unique segments_fz N/A N/A print N/A Slic number of segments: %d N/A len N/A N/A np unique segments_slic N/A N/A print N/A Quickshift number of segments: %d N/A len N/A N/A np unique segments_quick N/A N/A fig ax N/A N/A plt subplots 1 3 sharex True sharey True subplot_kw N/A adjustable box-forced N/A N/A N/A fig set_size_inches 8 3 forward True N/A N/A N/A fig tight_layout N/A N/A N/A N/A ax N/A 0 imshow N/A mark_boundaries img segments_fz N/A N/A N/A N/A ax N/A 0 set_title Felzenszwalbs's method N/A N/A N/A N/A ax N/A 1 imshow N/A mark_boundaries img segments_slic N/A N/A N/A N/A ax N/A 1 set_title SLIC N/A N/A N/A N/A ax N/A 2 imshow N/A mark_boundaries img segments_quick N/A N/A N/A N/A ax N/A 2 set_title Quickshift N/A a ax N/A N/A N/A N/A a set_xticks N/A N/A N/A N/A a set_yticks N/A N/A N/A N/A plt show