.. _example_segmentation_plot_rag.py:


=======================
Region Adjacency Graphs
=======================

This example demonstrates the use of the `merge_nodes` function of a Region
Adjacency Graph (RAG). The `RAG` class represents a 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`.

The default behaviour is to use the smaller edge weight in case of a conflict.
The example below also shows how to use a custom function to select the larger
weight instead.


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


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


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


.. literalinclude:: plot_rag.py
    :lines: 17-



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



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

