Main Content

영상에 가우스 평활화 필터 적용하기

이 예제에서는 imgaussfilt를 사용하여 영상에 여러 가우스 평활화 필터를 적용하는 방법을 보여줍니다. 가우스 평활화 필터는 일반적으로 잡음을 줄이는 데 사용됩니다.

영상을 작업 공간으로 읽어 들입니다.

I = imread('cameraman.tif');

표준편차가 증가하는 등방성 가우스 평활화 커널을 사용하여 영상을 필터링합니다. 가우스 필터는 보통 등방성으로, 두 차원에서 동일한 표준편차를 가집니다. sigma에 스칼라 값을 지정하여 등방성 가우스 필터로 영상을 필터링할 수 있습니다.

Iblur1 = imgaussfilt(I,2);
Iblur2 = imgaussfilt(I,4);
Iblur3 = imgaussfilt(I,8);

원래 영상과 필터링된 모든 영상을 표시합니다.

figure
imshow(I)
title('Original image')

Figure contains an axes object. The axes object with title Original image contains an object of type image.

figure
imshow(Iblur1)
title('Smoothed image, \sigma = 2')

Figure contains an axes object. The axes object with title Smoothed image, sigma blank = blank 2 contains an object of type image.

figure
imshow(Iblur2)
title('Smoothed image, \sigma = 4')

Figure contains an axes object. The axes object with title Smoothed image, sigma blank = blank 4 contains an object of type image.

figure
imshow(Iblur3)
title('Smoothed image, \sigma = 8')

Figure contains an axes object. The axes object with title Smoothed image, sigma blank = blank 8 contains an object of type image.

비등방성 가우스 평활화 커널을 사용하여 영상을 필터링합니다. imgaussfilt를 사용하면 가우스 커널은 행 차원과 열 차원에서 서로 다른 표준편차를 가질 수 있습니다. 이를 축 정렬 비등방성 가우스 필터라고 합니다. 비등방성 필터를 사용할 때는 sigma에 요소를 2개 가진 벡터를 지정합니다.

IblurX1 = imgaussfilt(I,[4 1]);
IblurX2 = imgaussfilt(I,[8 1]);
IblurY1 = imgaussfilt(I,[1 4]);
IblurY2 = imgaussfilt(I,[1 8]);

필터링된 영상을 표시합니다.

figure
imshow(IblurX1)
title('Smoothed image, \sigma_x = 4, \sigma_y = 1')

Figure contains an axes object. The axes object with title Smoothed image, sigma indexOf x baseline blank = blank 4 , blank sigma indexOf y baseline blank = blank 1 contains an object of type image.

figure
imshow(IblurX2)
title('Smoothed image, \sigma_x = 8, \sigma_y = 1')

Figure contains an axes object. The axes object with title Smoothed image, sigma indexOf x baseline blank = blank 8 , blank sigma indexOf y baseline blank = blank 1 contains an object of type image.

figure
imshow(IblurY1)
title('Smoothed image, \sigma_x = 1, \sigma_y = 4')

Figure contains an axes object. The axes object with title Smoothed image, sigma indexOf x baseline blank = blank 1 , blank sigma indexOf y baseline blank = blank 4 contains an object of type image.

figure
imshow(IblurY2)
title('Smoothed image, \sigma_x = 1, \sigma_y = 8')

Figure contains an axes object. The axes object with title Smoothed image, sigma indexOf x baseline blank = blank 1 , blank sigma indexOf y baseline blank = blank 8 contains an object of type image.

원래 영상에서 하늘 영역에 보이는 가로 띠가 표시되지 않도록 합니다. 비등방성 가우스 필터는 영상의 가로 방향 또는 세로 방향의 특징이 표시되지 않도록 할 수 있습니다. 영상에서 하늘 영역에 해당하는 부분을 추출한 후 열이 증가하는 방향인 X축에 표준편차가 더 큰 가우스 필터를 사용합니다.

I_sky = imadjust(I(20:50,10:70));
IblurX1_sky = imadjust(IblurX1(20:50,10:70));

원래 영상의 하늘 패치와 필터링된 버전의 하늘 패치를 표시합니다.

figure
imshow(I_sky), title('Sky in original image')

Figure contains an axes object. The axes object with title Sky in original image contains an object of type image.

figure
imshow(IblurX1_sky), title('Sky in filtered image')

Figure contains an axes object. The axes object with title Sky in filtered image contains an object of type image.