scikit に実装されているスーパーピクセルを試してみる
スーパーピクセルに関する参考記事: http://scikit-image.org/docs/dev/auto_examples/segmentation/plot_segmentations.html
先人に感謝.
元画像
SLIC
felzenszwalb
quickshift
watershed
上に実行結果例を示しているが,パラメータの調整により結果が変わりますので,上の図だけで,どれが良いと結論を出さないようにしてください.
キーワード:superpixel, SLIC, felzenszwalb, quickshift, watershed, scikit-image, Python
システム Python を使うことができる(その場合,Python のインストールは行わない)
システム Python を用いるときは,pip, setuptools の更新は次のコマンドで行う.
sudo apt -y update sudo apt -y install python3-pip python3-setuptools
Ubuntu で,システム Python 以外の Python をインストールしたい場合は pyenv が便利である: 別ページで説明している.
Python の URL: http://www.python.org/
【Python, pip の使い方】
Python, pip は,次のコマンドで起動できる.
【Python 開発環境のインストール】
JupyterLab, spyder, nteract (Python 開発環境) のインストールは, Windows でコマンドプロンプトを管理者として実行し, 次のコマンドを実行.
python -m pip install -U pip setuptools jupyterlab jupyter jupyter-console jupytext nteract_on_jupyter spyder
詳しくは,: 別ページで説明している.
JupyterLab, spyder, nteract (Python 開発環境) のインストール: : 別ページで説明している.
python -m pip install -U scikit-image matplotlib
SLIC を行う Python プログラムを実行してみる.
Python プログラムを動かすために, Windows では「python」, Ubuntu では「python3」などのコマンドを使う.
あるいは, 開発環境や Python コンソール(Jupyter Qt Console,Spyder,PyCharm,PyScripter など)の利用も便利である.
あるいは,オンラインで動くGoogle Colaboratory のノートブックの利用も,場合によっては便利である.
%matplotlib inline
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore') # Suppress Matplotlib warnings
import skimage.data
import skimage.color
import skimage.filters
import skimage.util
import skimage.segmentation
img = skimage.util.img_as_float( plt.imread("d:\lena_std.jpg") )
plt.imshow(img)
a = skimage.segmentation.slic(img)
plt.imshow( a )
plt.imshow( skimage.segmentation.mark_boundaries(img, a) )
felzenszwalb を行う Python プログラムを実行してみる.
%matplotlib inline
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore') # Suppress Matplotlib warnings
import skimage.data
import skimage.color
import skimage.filters
import skimage.util
import skimage.segmentation
img = skimage.util.img_as_float( plt.imread("d:\lena_std.jpg") )
plt.imshow(img)
a = skimage.segmentation.felzenszwalb(img)
plt.imshow( a )
plt.imshow( skimage.segmentation.mark_boundaries(img, a) )
quickshift を行う Python プログラムを実行してみる.
%matplotlib inline
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore') # Suppress Matplotlib warnings
import skimage.data
import skimage.color
import skimage.filters
import skimage.util
import skimage.segmentation
img = skimage.util.img_as_float( plt.imread("d:\lena_std.jpg") )
plt.imshow(img)
a = skimage.segmentation.quickshift(img)
plt.imshow( a )
plt.imshow( skimage.segmentation.mark_boundaries(img, a) )
watershed を行う Python プログラムを実行してみる.
%matplotlib inline
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore') # Suppress Matplotlib warnings
import skimage.data
import skimage.color
import skimage.filters
import skimage.util
import skimage.segmentation
img = skimage.util.img_as_float( plt.imread("d:\lena_std.jpg") )
plt.imshow(img)
a = skimage.segmentation.watershed( skimage.filters.sobel( skimage.color.rgb2gray( img ) ), markers=250 )
plt.imshow( a )
plt.imshow( skimage.segmentation.mark_boundaries(img, a) )