In [1]:
from Custom.mediahelper import show_image_with_pil # 개발자 정의 모듈
14. 이미지 변환¶
In [2]:
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) # 이미지 색상 반전, 흰색(255)은 검정(0)으로, 검정(0)은 흰색(255)으로 바뀜.
dilate1 = cv2.dilate(img, kernel, iterations = 1) # 반복 횟수
dilate2 = cv2.dilate(img, kernel, iterations = 2) # 반복 횟수
dilate3 = cv2.dilate(img, kernel, iterations = 3) # 반복 횟수
img_color_reverse_dilate1 = cv2.dilate(img_color_reverse, kernel, iterations = 1) # iterations: 연산 반복 횟수. 숫자가 클수록 더 많이 확장.
img_color_reverse_dilate2 = cv2.dilate(img_color_reverse, kernel, iterations = 2)
img_color_reverse_dilate3 = cv2.dilate(img_color_reverse, kernel, iterations = 3)
cv2.imshow('img',img)
cv2.imshow('dilate1',dilate1)
cv2.imshow('dilate2',dilate2)
cv2.imshow('dilate3',dilate3)
cv2.imshow('img_color_reverse',img_color_reverse)
cv2.imshow('img_color_reverse_dilate1',img_color_reverse_dilate1)
cv2.imshow('img_color_reverse_dilate2',img_color_reverse_dilate2)
cv2.imshow('img_color_reverse_dilate3',img_color_reverse_dilate3)
cv2.waitKey(0)
cv2.destroyAllWindows()
show_image_with_pil(img, 'img')
show_image_with_pil(dilate1, 'dilate1')
show_image_with_pil(dilate2, 'dilate2')
show_image_with_pil(dilate3, 'dilate3')
show_image_with_pil(img_color_reverse, 'img_color_reverse')
show_image_with_pil(img_color_reverse_dilate1, 'img_color_reverse_dilate1')
show_image_with_pil(img_color_reverse_dilate2, 'img_color_reverse_dilate2')
show_image_with_pil(img_color_reverse_dilate3, 'img_color_reverse_dilate3')
'img'
'dilate1'
'dilate2'
'dilate3'
'img_color_reverse'
'img_color_reverse_dilate1'
'img_color_reverse_dilate2'
'img_color_reverse_dilate3'
In [3]:
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)
erode1 = cv2.erode(img_color_reverse, kernel, iterations = 1)
erode2 = cv2.erode(img_color_reverse, kernel, iterations = 2)
erode3 = cv2.erode(img_color_reverse, kernel, iterations = 3)
cv2.imshow('img_color_reverse',img_color_reverse)
cv2.imshow('erode1',erode1)
cv2.imshow('erode2',erode2)
cv2.imshow('erode3',erode3)
cv2.waitKey(0)
cv2.destroyAllWindows()
show_image_with_pil(img_color_reverse, 'img_color_reverse')
show_image_with_pil(erode1, 'erode1')
show_image_with_pil(erode2, 'erode2')
show_image_with_pil(erode3, 'erode3')
'img_color_reverse'
'erode1'
'erode2'
'erode3'
'Python > OpenCV' 카테고리의 다른 글
16. 이미지 검출(경계선) (0) | 2024.11.19 |
---|---|
15. 이미지 변환(열림 & 닫힘) (0) | 2024.11.19 |
13_2. 이미지 변형(이진화) (0) | 2024.11.18 |
13_1. 이미지 변형(이진화) (0) | 2024.11.18 |
12. 이미지 변형(원근) (0) | 2024.11.18 |