In [1]:
from Custom.mediahelper import show_image_with_pil # 개발자 정의 모듈
In [2]:
import cv2
import numpy as np
kernel = np.ones((3, 3), dtype=np.uint8)
img = cv2.imread('../Media/images/erode.png', cv2.IMREAD_GRAYSCALE)
img_color_reverse = cv2.bitwise_not(img) # 흑백전환
erode = cv2.erode(img_color_reverse, kernel, iterations = 3)
dilate = cv2.dilate(erode, kernel, iterations = 3)
cv2.imshow('img_color_reverse',img_color_reverse)
cv2.imshow('erode',erode)
cv2.imshow('dilate',dilate)
cv2.waitKey(0)
cv2.destroyAllWindows()
show_image_with_pil(img_color_reverse, 'img_color_reverse')
show_image_with_pil(erode, 'erode')
show_image_with_pil(dilate, 'dilate')
'img_color_reverse'
'erode'
'dilate'
닫힘 (Closing): 팽창 후 침식. 구멍을 메운 후 다시 깍음¶
erode(dilate(image))
In [3]:
import cv2
import numpy as np
kernel = np.ones((3, 3), dtype=np.uint8)
img = cv2.imread('../Media/images/dilate.png', cv2.IMREAD_GRAYSCALE)
img_color_reverse = cv2.bitwise_not(img) # 흑백전환
dilate = cv2.dilate(img_color_reverse, kernel, iterations = 3)
erode = cv2.erode(dilate, kernel, iterations = 3)
cv2.imshow('img_color_reverse',img_color_reverse)
cv2.imshow('dilate',dilate)
cv2.imshow('erode',erode)
cv2.waitKey(0)
cv2.destroyAllWindows()
show_image_with_pil(img_color_reverse, 'img_color_reverse')
show_image_with_pil(dilate, 'dilate')
show_image_with_pil(erode, 'erode')
'img_color_reverse'
'dilate'
'erode'
'Python > OpenCV' 카테고리의 다른 글
17. 이미지 검출(윤곽선) (0) | 2024.11.19 |
---|---|
16. 이미지 검출(경계선) (0) | 2024.11.19 |
14. 이미지 변환(팽창) (0) | 2024.11.18 |
13_2. 이미지 변형(이진화) (0) | 2024.11.18 |
13_1. 이미지 변형(이진화) (0) | 2024.11.18 |