Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying 2d gaussian filter in a circular image area - Matlab

Is there an easy way to apply a 2d gaussian filter in a circular image area (by easy i mean a ready matlab function) or does one have to implement this on his own ??

like image 948
obelix Avatar asked Jan 10 '23 20:01

obelix


1 Answers

If you want to apply any filter to a selected portion of the image, one option is to use a binary mask.

Let img be your image, set the position and the radius of the circular mask as well as the dimension of the filter:

centre=[50 50];
radius=20;
n=5;

Then create the mask:

Mask=zeros(size(img));
Disk = fspecial('disk',radius)==0;
Mask(centre(1)-radius:centre(1)-radius+size(Disk,1)-1, centre(2)-radius:centre(2)-radius+size(Disk,2)-1)=double(~Disk);

Apply filtering as suggested by @Gacek:

h = fspecial('gaussian', n);
Filtered=filter2(h, img);

Combine the filtered area with the original image and show the result:

Result=img.*uint8(~Mask)+uint8(Filtered.*Mask);
imshow(Result)

Example result:

filtered lion

Notes: 1. change the class uint8 to the appropriate class of your original image. 2. The example image is in the public domain, source: en.wikipedia.org/wiki/File:Phase_correlation.png.

like image 199
Cape Code Avatar answered Jan 17 '23 12:01

Cape Code