wagahaiwananashi
10/4/2018 - 4:38 AM

Superpixel_skimage.py

from skimage import io
from skimage.segmentation import felzenszwalb, quickshift, slic, watershed, mark_boundaries
from skimage.filters import sobel
from skimage.color import rgb2gray
import matplotlib.pyplot as plt

img=io.imread("kumamon.jpg")#RGBの順番

#セグメント
felzen_segments = felzenszwalb(img)
quick_segments = quickshift(img)
slic_segments = slic(img)
water_segments = watershed(sobel(rgb2gray(img)), markers=250) 

#描画
plt.figure(figsize=(10, 10))
plt.rcParams["font.size"] = 15

plt.subplot(2, 2, 1)
plt.title("Felzenszwalb")
plt.imshow(mark_boundaries(img,felzen_segments))

plt.subplot(2, 2, 2)
plt.title("quickshift")
plt.imshow(mark_boundaries(img,quick_segments))

plt.subplot(2, 2, 3)
plt.title("slic")
plt.imshow(mark_boundaries(img,slic_segments))

plt.subplot(2, 2, 4)
plt.title("watershed")
plt.imshow(mark_boundaries(img,water_segments))