.. _example_segmentation_plot_rag_merge.py:


===========
RAG Merging
===========

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.


.. image:: images/plot_rag_merge_1.png
    :align: center


.. literalinclude:: plot_rag_merge.py
    :lines: 12-



**Python source code:** :download:`download <plot_rag_merge.py>`
(generated using ``skimage`` |version|)



**IPython Notebook:** :download:`download <./notebook/plot_rag_merge.ipynb>`
(generated using ``skimage`` |version|)

