{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Region Boundary based Region adjacency graphs (RAGs)\n\nConstruct a region boundary RAG with the ``rag_boundary`` function. The\nfunction  :py:func:`skimage.graph.rag_boundary` takes an\n``edge_map`` argument, which gives the significance of a feature (such as\nedges) being present at each pixel. In a region boundary RAG, the edge weight\nbetween two regions is the average value of the corresponding pixels in\n``edge_map`` along their shared boundary.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from skimage import graph\nfrom skimage import data, segmentation, color, filters\nfrom matplotlib import pyplot as plt\n\n\nimg = data.coffee()\ngimg = color.rgb2gray(img)\n\nlabels = segmentation.slic(img, compactness=30, n_segments=400, start_label=1)\nedges = filters.sobel(gimg)\nedges_rgb = color.gray2rgb(edges)\n\nfig, ax = plt.subplots()\n\ng = graph.rag_boundary(labels, edges)\nlc = graph.show_rag(\n    labels, g, edges_rgb, img_cmap=None, ax=ax, edge_cmap='viridis', edge_width=1.2\n)\n\n\nplt.colorbar(lc, fraction=0.03)\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.12"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}