I'm trying to create a Region Adjacency Graph from after segmenting an image using the tools in the Skimage
package. Using the examples in the documentation I can segment an image using SLIC and create the RAG successfully.
from skimage import data
from skimage import segmentation
from skimage.future import graph
import matplotlib.pyplot as plt
#Load Image
img = data.coffee()
#Segment image
labels = segmentation.slic(img, compactness=30, n_segments=800)
#Create RAG
g = graph.rag_mean_color(img, labels)
#Draw RAG
gplt = graph.draw_rag(labels, g, img)
plt.imshow(gplt)
However, if I use either segmentation.quickshift
or segmentation.felzenszwalb
to segment the image and then create the RAG, I get an error at draw_rag()
.
labels = segmentation.quickshift(img, kernel_size=5, max_dist=5, ratio=0.5)
g = graph.rag_mean_color(img, labels)
gplt = graph.draw_rag(labels, g, img)
labels = segmentation.felzenszwalb(img, scale=100, sigma=0.5, min_size=50)
g = graph.rag_mean_color(img, labels)
gplt = graph.draw_rag(labels, g, img)
Traceback (most recent call last):
File "C:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3032, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-34-c0784622a6c7>", line 1, in <module>
gplt = graph.draw_rag(labels, g, img)
File "C:\Anaconda\lib\site-packages\skimage\future\graph\rag.py", line 429, in draw_rag
out[circle] = node_color
IndexError: index 600 is out of bounds for axis 1 with size 600
The documentation seems to suggest that RAG methods should be compatible with segments from any of these methods, so I'm not sure if I'm doing something wrong, there's a bug, or RAG can only be used with the SLIC segmentation method. Any suggestions?
Seems that this was an issue in Skimage 0.11.2
but is fixed in version 0.12.3
.