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

Is there a simple way to apply a 2d Gaussian filter in the area of ​​a circular image (by simple I mean the ready-made matlab function) or do I need to implement this myself?

+4
source share
3 answers

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

Let it imgbe your image, set the position and radius of the circular mask, as well as the filter size:

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

Then create a 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)

:

filtered lion

: 1. uint8 . 2. , : en.wikipedia.org/wiki/File:Phase_correlation.png.

+4

fspecial. img - , :

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

n - . Gaussian n x n.

, :

h = fspecial('gaussian', n, std_sigma);
+3

fspecial imfilter -

h = fspecial('gaussian', hsize, sigma);
filteredIMG = imfilter(originalIMG, h);

originalIMG = imread('cameraman.tif');
h = fspecial('gaussian', 21, 0.9);
filteredIMG = imfilter(originalIMG, h);

figure,
subplot(211),imshow(originalIMG)
subplot(212),imshow(filteredIMG)

enter image description here

+2

Source: https://habr.com/ru/post/1535351/


All Articles