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 ??
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With