Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- C언어
- 프로세스
- CV
- Windows 10
- 백준
- Windows10
- 시스템프로그래밍
- 알고리즘
- TensorFlow
- 딥러닝
- 텐서플로우
- linux
- 프로그래밍
- 쉘
- 공부
- 회귀
- 영상처리
- shell
- C++
- error
- 리눅스
- 턱걸이
- python
- OpenCV
- 운영체제
- 백준알고리즘
- c
- Computer Vision
- 학습
- 코딩
Archives
- Today
- Total
줘이리의 인생적기
CV - opencv(Python) Blur, GaussianBlur, MedianBlur 본문
728x90
Blur, GaussianBlur, MedianBlur에 대해 알아보겠습니다.
그전에, 영상 평활화(Image Smoothing, Image Blurring)를 알아보겠습니다.
영상 평활화는 영상을 부드럽게 표현하거나 잡음을 제거하기 위해 사용되며, 평균값 필터링(mean filtering) 및 중간값 필터링(median filtering) 연산을 통해 수행되어집니다.
평균값 필터링(mean filtering)
-모든 계수가 양수, 전체 합이 1인 마스크
-weight의 형태에 따라 Gaussian filtering이라고도 불림.
중간값 필터링(median filtering)
-Nonlinear filtering
-중앙의 픽셀 값이 필터 영역 내 모든 픽셀 값의 중앙값으로 대체됨.
1번 imageBlur, GaussianBlur
2번 MedianBlur
코드 원형 설명
#Blur
def imageBlur(image, ksize):
size = ((ksize+1) * 2 - 1, (ksize+1) * 2 - 1)
return cv2.blur(image, size)
#GaussianBlur
def imageGaussianBlur(image, ksize, sigmaX, sigmaY):
size = ((ksize+1) * 2 - 1, (ksize+1) * 2 - 1)
return cv2.GaussianBlur(image, ksize=size, sigmaX=sigmaX, sigmaY=sigmaY)
#Medianblur
def imageMedianBlur(image, size):
ksize = (size+1) * 2 - 1
return cv2.medianBlur(image, ksize)
1번 코드 설명
더보기
# -*- coding: utf-8 -*-
from OpenCV_Functions import *
def nothing(x):
pass
#이미지 설정
imagePath = "<이미지 경로>"
image = imageRead(imagePath)
backup = imageCopy(image)
#창 설정
cv2.namedWindow('Mean and gaussian', cv2.WINDOW_GUI_EXPANDED)
#트랙바 설정
cv2.createTrackbar('BlurSize', 'Mean and gaussian', 0, 10, nothing)
cv2.createTrackbar('sigmaX', 'Mean and gaussian', 0, 50, nothing)
cv2.createTrackbar('sigmaY', 'Mean and gaussian', 0, 50, nothing)
switch = '0:Mean\n1:Gaussian'
cv2.createTrackbar(switch, 'Mean and gaussian', 0, 1, nothing)
while True:
cv2.imshow('Mean and gaussian', image)
if cv2.waitKey(1) & 0xFF == 27:
break
size = cv2.getTrackbarPos('BlurSize', 'Mean and gaussian')
sigmaX = cv2.getTrackbarPos('sigmaX', 'Mean and gaussian')
sigmaY = cv2.getTrackbarPos('sigmaY', 'Mean and gaussian')
s = cv2.getTrackbarPos(switch, 'Mean and gaussian')
if s == 0:
image = imageBlur(backup, size)
else:
image = imageGaussianBlur(backup, size, sigmaX, sigmaY)
cv2.destroyAllWindows()
2번 코드 설명
더보기
# -*- coding: utf-8 -*-
from OpenCV_Functions import *
def nothing(x):
pass
#이미지 설정
imagePath = "<이미지 경로>"
image = imageRead(imagePath)
backup = imageCopy(image)
#창 띄우기
cv2.namedWindow('imageMedianBlur', cv2.WINDOW_GUI_EXPANDED)
#트랙바 설정
cv2.createTrackbar('BlurSize', 'imageMedianBlur', 0, 10, nothing)
switch = '0:OFF\n1:On'
cv2.createTrackbar(switch, 'imageMedianBlur', 1, 1, nothing)
while True:
cv2.imshow('imageMedianBlur', image)
if cv2.waitKey(1) & 0xFF == 27:
break
size = cv2.getTrackbarPos('BlurSize', 'imageMedianBlur')
s = cv2.getTrackbarPos(switch, 'imageMedianBlur')
if s == 1:
image = imageMedianBlur(backup, size)
else:
image = backup
cv2.destroyAllWindows()
'공부 > Computer Vision(py)' 카테고리의 다른 글
CV - opencv(Python) Canny Edge (0) | 2020.07.21 |
---|---|
CV - opencv(Python) 경계선 검출(edge detection) (0) | 2020.07.20 |
CV - opencv(Python) addImage, addWeightedImage, imageThreshold (0) | 2020.07.16 |
CV - opencv(Python) 비디오에 라인, 원, 사각형 그리기 (0) | 2020.07.13 |
CV - opencv(Python) White, Yellow 차선 검출 (0) | 2020.07.10 |