728x90
목표
- 블러 이미지 만들기
- 커스텀 필터 적용하기
2D Convolution (Image Filtering)
import numpy as np
import cv2 as cv
img = cv.imread('cat.png')
kernel = np.ones((5, 5), np.float32)/25
dst = cv.filter2D(img, -1, kernel)
cv.imshow("img", img)
cv.imshow("dst", dst)
cv.waitKey(0)
cv.destroyAllWindows()
커널을 5x5행렬로 만들어 평균값을 해준 필터이다.
Blur
import numpy as np
import cv2 as cv
img = cv.imread('cat.png')
blur = cv.blur(img, (5, 5))
cv.imshow("img", img)
cv.imshow("dst", blur)
cv.waitKey(0)
cv.destroyAllWindows()
위에 커널을 직접 만들지 않아도 블러 함수를 쓰면 똑같이 만들 수 있다.
Gaussian Blur
import numpy as np
import cv2 as cv
img = cv.imread('cat.png')
blur = cv.GaussianBlur(img, (5, 5), 0)
cv.imshow("img", img)
cv.imshow("dst", blur)
cv.waitKey(0)
cv.destroyAllWindows()
가우시안 필터는 평균을 내는것이 아니라 가까운 픽셀 일 수록 가중치가 높게 연산한다.
'언어 > OpenCV(Python)' 카테고리의 다른 글
[OpenCV]Smoothing 이미지(2) (0) | 2022.04.01 |
---|---|
[OpenCV]이미지 Adaptive Thresholding (0) | 2022.03.28 |
[OpenCV]이미지 Thresholding (0) | 2022.03.27 |
[OpenCV]이미지의 기하학적 변환(2) (0) | 2022.03.25 |
이미지의 기하학적 변환(1) (0) | 2022.03.24 |