http://scikit-image.org/docs/dev/auto_examples/plot_ncut.html
I tried to test the operation of scikit-image by referring to this site. If you install from pip, the stable version will be installed, so I think it's better to drop it from git and do python setup.py install develop.
Click here to install.
http://scikit-image.org/docs/dev/install.html
You can't just do it with coffee, so try something with your own image. I rewrote the code as follows.
from skimage import graph, data, io, segmentation, color
from matplotlib import pyplot as plt
#img = data.coffee()
img = io.imread('test.jpg')
labels1 = segmentation.slic(img, compactness=30, n_segments=400)
out1 = color.label2rgb(labels1, img, kind='avg')
g = graph.rag_mean_color(img, labels1, mode='similarity')
labels2 = graph.cut_normalized(labels1, g)
out2 = color.label2rgb(labels2, img, kind='avg')
io.imsave('test_out1.png',out1)
io.imsave('test_out2.png',out2)
#plt.figure()
#io.imshow(out1)
#plt.figure()
#io.imshow(out2)
#io.show()
When I run it right away ...
‘module’ object has no attibute ‘rag_mean_color’
What is this ... Moreover, there is no solution even if you google.
It can't be helped, so let's take a look at the scikit-image code. /to-site-packages-path/scikit_image-0.11dev-py2.7-linux-x86_64.egg/skimage/
Looking inside the graph, rag_mean_color is written in \ _ \ _ init \ _ \ _. Py, but I can't find the main method body. If you read the doc on github obediently
https://github.com/scikit-image/scikit-image/tree/372ea53cc94bda31edeabfc6443fa73c5b89f3fe/doc/examples
There is a sample ...
plot_rag_mean_color.py
In the file
from skimage.future import graph
future path ... Try to specify in the same way.
from skimage import data, io, segmentation, color
from skimage.future import graph
from matplotlib import pyplot as plt
#img = data.coffee()
img = io.imread('test.jpg')
labels1 = segmentation.slic(img, compactness=30, n_segments=400)
out1 = color.label2rgb(labels1, img, kind='avg')
g = graph.rag_mean_color(img, labels1, mode='similarity')
labels2 = graph.cut_normalized(labels1, g)
out2 = color.label2rgb(labels2, img, kind='avg')
io.imsave('test_out1.png',out1)
io.imsave('test_out2.png',out2)
#plt.figure()
#io.imshow(out1)
#plt.figure()
#io.imshow(out2)
#io.show()
It works safely.
Recommended Posts