본문 바로가기

인공지능/Python

change edge thickness (using opencv Morphological Transformations )

Problem

cv2.canny를 이용해 추출한 edge의 thickness를 올리고 싶어서 방법을 찾던중 형태학적 변환(Morphological Transformations)을 opencv에서 이미 제공을 하고 있는 것을 발견했다. thickness를 늘릴수도있고, 줄일수도있고, 잡티를 제거할수도 있는등, 다양한 방법을 제공하고 있었다.

난 그중에 thickness를 늘리는 것이 목적이었으므로 해당 함수를 적용했다.

 

Solution

plt.subplot(1,3,1)
plt.imshow(edges,cmap='gray')

plt.subplot(1,3,2)
kernel = np.ones((3,3),np.uint8)
dilation = cv2.dilate(edges,kernel,iterations = 1)
plt.imshow(dilation,cmap='gray')

plt.subplot(1,3,3)
kernel = np.ones((5,5),np.uint8)
dilation = cv2.dilate(edges,kernel,iterations = 1)
plt.imshow(dilation,cmap='gray')

plt.show()

kernel의 크기에 비례하여 thickness가 결정된다. 2개의 다른 크기의 kernel을 적용한 결과이다.

확실히 kernel이 크면 thickness가 커지는 것을 볼 수 있다.