[PYTHON] Try to Normalize Cut the image with scikit-image (although it gets angry on the way)

coffee.png

plot_ncut_1.png

plot_ncut_2.png

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

Try to Normalize Cut the image with scikit-image (although it gets angry on the way)
CNN with keras Try it with the image you picked up
POST the image selected on the website with multipart / form-data and save it to Amazon S3! !!
Try blurring the image with opencv2
The fastest way to try EfficientNet
The easiest way to try PyQtGraph
Upload data to s3 of aws with a command and update it, and delete the used data (on the way)
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python
Try to image the elevation data of the Geographical Survey Institute with Python
Matching karaoke keys ~ I tried to put it on Laravel ~ <on the way>
Try to generate an image with aliasing
GAE --With Python, rotate the image based on the rotation information of EXIF and upload it to Cloud Storage.
Try to measure the position of the object on the desk (real coordinate system) from the camera image with Python + OpenCV
Try to solve the fizzbuzz problem with Keras
Try adding fisheye lens distortion to the image
The easiest way to get started with Django
Crop the image to rounded corners with pythonista
The easiest way to synthesize speech with python
Try to solve the man-machine chart with Python
How to try the friends-of-friends algorithm with pyfof
The easiest way to use OpenCV with python
An easy way to pad the number with zeros depending on the number of digits [Python]
Make it easy to install the ROS2 development environment with pip install on Python venv
What I did when I was angry to put it in with the enable-shared option
It is difficult to install a green screen, so I cut out only the face and superimposed it on the background image
I want to cut out only the face from a person image with Python and save it ~ Face detection and trimming with face_recognition ~
Try to visualize the room with Raspberry Pi, part 1
Try to solve the internship assignment problem with Python
Try to estimate the number of likes on Twitter
Try to get the contents of Word with Golang
[Neo4J] ④ Try to handle the graph structure with Cypher
POST the image with json and receive it with flask
Try to specify the axis with PyTorch's Softmax function
Return the image data with Flask of Python and draw it to the canvas element of HTML