In [1]:
from Custom.mediahelper import show_image_with_pil # 개발자 정의 모듈
In [2]:
import cv2
img = cv2.imread('../Media/images/img.png')
_3 = (3,3)
_5 = (5,5)
_7 = (7,7)
kernel_3 = cv2.GaussianBlur(img, _3, 0) # 0 -> 표준편차
kernel_5 = cv2.GaussianBlur(img, _5, 0)
kernel_7 = cv2.GaussianBlur(img, _7, 0)
cv2.imshow('img', img)
cv2.imshow('kernel_3', kernel_3)
cv2.imshow('kernel_5', kernel_5)
cv2.imshow('kernel_7', kernel_7)
cv2.waitKey(0)
cv2.destroyAllWindows()
In [3]:
show_image_with_pil(img, 'img')
show_image_with_pil(kernel_3, 'kernel_3')
show_image_with_pil(kernel_5, 'kernel_5')
show_image_with_pil(kernel_7, 'kernel_7')
'img'
'kernel_3'
'kernel_5'
'kernel_7'
표준 편차 변화에 따른 흐림
- 표준편차가 클수록 블러 효과가 더 강해지며, 가우시안 필터의 분산이 증가.
In [4]:
import cv2
img = cv2.imread('../Media/images/img.png')
sigma_1 = cv2.GaussianBlur(img, (0,0), 1) # sigmaX
sigma_2 = cv2.GaussianBlur(img, (0,0), 2)
sigma_3 = cv2.GaussianBlur(img, (0,0), 3)
sigma_4 = cv2.GaussianBlur(img, (0,0), 4)
cv2.imshow('img', img)
cv2.imshow('sigma_1', sigma_1)
cv2.imshow('sigma_2', sigma_2)
cv2.imshow('sigma_3', sigma_3)
cv2.imshow('sigma_4', sigma_4)
cv2.waitKey(0)
cv2.destroyAllWindows()
In [5]:
show_image_with_pil(cv2.resize(img, None, fx = 0.5, fy = 0.5, interpolation = cv2.INTER_AREA), 'img')
show_image_with_pil(cv2.resize(sigma_1, None, fx = 0.5, fy = 0.5, interpolation = cv2.INTER_AREA), 'sigma_1')
show_image_with_pil(cv2.resize(sigma_2, None, fx = 0.5, fy = 0.5, interpolation = cv2.INTER_AREA), 'sigma_2')
show_image_with_pil(cv2.resize(sigma_3, None, fx = 0.5, fy = 0.5, interpolation = cv2.INTER_AREA), 'sigma_3')
show_image_with_pil(cv2.resize(sigma_4, None, fx = 0.5, fy = 0.5, interpolation = cv2.INTER_AREA), 'sigma_4')
'img'
'sigma_1'
'sigma_2'
'sigma_3'
'sigma_4'
'Python > OpenCV' 카테고리의 다른 글
13_1. 이미지 변형(이진화) (0) | 2024.11.18 |
---|---|
12. 이미지 변형(원근) (0) | 2024.11.18 |
10. 이미지 변형(흑백) (0) | 2024.11.18 |
09. 이미지 회전 (0) | 2024.11.18 |
08. 이미지 대칭 (0) | 2024.11.18 |