■ 수퍼 픽셀(Superpixel)을 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import matplotlib import matplotlib.pyplot as pp import skimage.color as color import skimage.io as io import skimage.segmentation as segmentation matplotlib.use("TkAgg") io.use_plugin("matplotlib") imageNDArray = io.imread("source.png") imageSegmentNDArray = segmentation.slic(imageNDArray, compactness = 20, n_segments = 500) superpixelImageNDArray = color.label2rgb(imageSegmentNDArray, imageNDArray, kind="avg") figure, axesNDArray = pp.subplots(nrows = 1, ncols = 2, sharex = True, sharey = True, figsize = (6, 8)) axesNDArray[0].imshow(imageNDArray) axesNDArray[1].imshow(superpixelImageNDArray) for axes in axesNDArray: axes.axis("off") pp.tight_layout() pp.show() |