개발/OpenCV

가우시안 노이즈 + 가우시안 필터

njsung 2018. 4. 9. 23:17
반응형
#include <opencv\highgui.h>
#include <opencv2\opencv.hpp>

using namespace cv;

int main() {
	
	cvNamedWindow("Origin", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Filter3", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Filter5", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Filter7", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Filter9", CV_WINDOW_AUTOSIZE);

	Mat inputImg;
	Mat filter3Img;
	Mat filter5Img;
	Mat filter7Img;
	Mat filter9Img;

	inputImg = imread("cat.png", CV_LOAD_IMAGE_COLOR);
	resize(inputImg, inputImg, Size(), 0.3, 0.3, CV_INTER_AREA);

	Mat noise_image(inputImg.size(), CV_16SC3);
	double average = 0.0;
	double std = 30.0; randn(noise_image, Scalar::all(average), Scalar::all(std));
	Mat temp_image; inputImg.convertTo(temp_image, CV_16SC3);
	addWeighted(temp_image, 1.0, noise_image, 1.0, 0.0, temp_image);
	temp_image.convertTo(temp_image, inputImg.type());


	// Gaussian Filer 적용
	GaussianBlur(temp_image, filter3Img, Size(3, 3), 0);
	GaussianBlur(temp_image, filter5Img, Size(5, 5), 0);
	GaussianBlur(temp_image, filter7Img, Size(7, 7), 0);
	GaussianBlur(temp_image, filter9Img, Size(9, 9), 0);

	imshow("Origin", temp_image);
	imshow("Filter3", filter3Img);
	imshow("Filter5", filter5Img);
	imshow("Filter7", filter7Img);
	imshow("Filter9", filter9Img);

	waitKey(0);


	return 0;
}

가우시안 노이즈와 함께 가우시안 블러를 사용하는 예제입니다.


결과는 다음과 같습니다.




반응형