Note
Go to the endto download the full example code or to run this example in your browser via Binder.
Drawing Region Adjacency Graphs (RAGs)#
This example constructs a Region Adjacency Graph (RAG) and draws it withtherag_draw method.

fromskimageimportdata,segmentationfromskimageimportgraphfrommatplotlibimportpyplotaspltimg=data.coffee()labels=segmentation.slic(img,compactness=30,n_segments=400,start_label=1)g=graph.rag_mean_color(img,labels)fig,ax=plt.subplots(nrows=2,sharex=True,sharey=True,figsize=(6,8))ax[0].set_title('RAG drawn with default settings')lc=graph.show_rag(labels,g,img,ax=ax[0])# specify the fraction of the plot area that will be used to draw the colorbarfig.colorbar(lc,fraction=0.03,ax=ax[0])ax[1].set_title('RAG drawn with grayscale image and viridis colormap')lc=graph.show_rag(labels,g,img,img_cmap='gray',edge_cmap='viridis',ax=ax[1])fig.colorbar(lc,fraction=0.03,ax=ax[1])forainax:a.axis('off')plt.tight_layout()plt.show()
Total running time of the script: (0 minutes 2.259 seconds)
