1
윤곽선을 찾은 이미지가 skimage.measure.find_contours()
인데, 이제 가장 큰 닫힌 윤곽선 밖의 픽셀에 대한 마스크를 만들고 싶습니다. 어떤 생각을 어떻게 할 것인가? 문서의 예제를 수정skimage 윤곽선에서 마스크 만들기
: 여기
import numpy as np
import matplotlib.pyplot as plt
from skimage import measure
# Construct some test data
x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j]
r = np.sin(np.exp((np.sin(x)**2 + np.cos(y)**2)))
# Find contours at a constant value of 0.8
contours = measure.find_contours(r, 0.8)
# Select the largest contiguous contour
contour = sorted(contours, key=lambda x: len(x))[-1]
# Display the image and plot the contour
fig, ax = plt.subplots()
ax.imshow(r, interpolation='nearest', cmap=plt.cm.gray)
X, Y = ax.get_xlim(), ax.get_ylim()
ax.step(contour.T[1], contour.T[0], linewidth=2, c='r')
ax.set_xlim(X), ax.set_ylim(Y)
plt.show()
빨간색의 윤곽이다 :
그러나 당신이 확대되면 윤곽이의 해상도에 있지 발견 픽셀.
어떻게 완전히 외부 (즉 등고선에 의해 교차하지 않음)를 마스크 화소와 원고와 동일한 크기의 이미지를 생성 할 수 있는가? 예 :
from numpy import ma
masked_image = ma.array(r.copy(), mask=False)
masked_image.mask[pixels_outside_contour] = True
고마워요!