■ find_contours 함수를 사용해 외곽선을 검출하는 방법을 보여준다.
▶ 예제 코드 (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 30 31 32 33 34 |
import matplotlib import matplotlib.pyplot as pp import skimage.measure as measure import skimage.io as io import skimage.color as color import skimage.filters as filters matplotlib.use("TkAgg") io.use_plugin("matplotlib") imageNDArray = io.imread("source.png") grayscaleImageNDArray = color.rgb2gray(imageNDArray) sobelImageNDArray = filters.sobel(grayscaleImageNDArray) contourList = measure.find_contours(sobelImageNDArray, 0.2) figure, axes = pp.subplots() axes.imshow(sobelImageNDArray, interpolation = "nearest", cmap = pp.cm.gray) for n, contour in enumerate(contourList): axes.plot(contour[:, 1], contour[:, 0], linewidth = 2) axes.axis("image") axes.set_xticks([]) axes.set_yticks([]) pp.show() |