728x90
반응형
Bilateral Filter
OpenCV에서 대표적인 필터로는 blur, GaussianBlur, medianBlur 그리고 BilateralFilter 가 있다. 이 필터는 선형으로 처리되지 않고, 엣지와 노이즈를 줄여주어 부드러운 영상이 만들어지게 된다. 변수의 값이 크면 클수록 픽셀에 미치는 영향이 많아져 가중치가 커지게 된다.
bilateralFilter(src, dst, d, sigmaColor, sigmaSpace);
src : 입력 이미지
dst : 출력 이미지
d : 필터링에 이용하는 이웃한 픽셀의 지름을 정의 불가능한경우 sigmaspace 를 사용
sigmaColor : 컬러공간의 시그마공간 정의, 클수록 이웃한 픽셀과 기준색상의 영향이 커진다
sigmaSpace : 시그마 필터를 조정한다. 값이 클수록 긴밀하게 주변 픽셀에 영향을 미친다. d>0 이면 영향을 받지 않고, 그 외에는 d 값에 비례한다.
opencv reference 에 있는 함수 원형은 다음과 같다.
Applies the bilateral filter to an image.
- C++:
voidbilateralFilter(InputArray src, OutputArray dst, int d, double sigmaColor, double sigmaSpace, int borderType=BORDER_DEFAULT )
- Python:
cv2.bilateralFilter(src, d, sigmaColor, sigmaSpace[, dst[, borderType]]) → dst Parameters: - src – Source 8-bit or floating-point, 1-channel or 3-channel image.
- dst – Destination image of the same size and type as
src. - d – Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from
sigmaSpace. - sigmaColor – Filter sigma in the color space. A larger value of the parameter means that farther colors within the pixel neighborhood (see
sigmaSpace) will be mixed together, resulting in larger areas of semi-equal color. - sigmaSpace – Filter sigma in the coordinate space. A larger value of the parameter means that farther pixels will influence each other as long as their colors are close enough (see
sigmaColor). Whend>0, it specifies the neighborhood size regardless ofsigmaSpace. Otherwise,dis proportional tosigmaSpace.
블러 소스 코드 (변수 값을 임의로 주었다)
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv){
Mat bilateral = imread("image/face.png", 1);
Mat b = bilateral.clone();
Mat gaussian = bilateral.clone();
Mat median = bilateral.clone();
Mat result;
imshow("original image", bilateral);
blur(b, result, Size(5, 5));
imshow("blur result", result);
GaussianBlur(gaussian, result, Size(5, 5), 1.5, 1.5);
imshow("GaussianBlur result",result);
medianBlur(median, result, 7);
imshow("medianBlur result", result);
bilateralFilter(bilateral, result, 10, 50, 50);
imshow("bilateralFilter result", result);
/*
bilateralFilter (1, 2, 3, 4, 5);
argument 1 : Source image
argument 2 : Destination image
argument 3 : the diameter of each pixel neighborhood
argument 4 : Standard deviation in the color space
argument 5 : Standard deviation in the coordinate space
*/
waitKey(0);
return 0;
}
실행결과
728x90
반응형
'Development & Tools > Tools & Environments' 카테고리의 다른 글
| [OpenCV] 동영상 저장 및 파일명 지정 (to_string) (0) | 2017.08.17 |
|---|---|
| [OpenCV] Image Denoising (0) | 2017.02.16 |
| [OpenCV] SimpleBlobDetector 을 이용한 Blob Detection (0) | 2017.02.08 |
| [OpenCV] pyrMeanShiftFiltering 적용하여 영상분할 (0) | 2017.01.17 |
| [OpenCV] MOG2 함수를 이용한 배경추출 (0) | 2017.01.17 |