Gaussian Filter without using any special function
Show older comments
Hi,
i need to apply a gaussian filter to the image without using imgaussfilt() function,
i create a gaussian mask:
[ 1, 4, 7, 4, 1;
4, 20, 33, 20, 4;
7, 33, 55, 33, 7;
4, 20, 33, 20, 4;
1, 4, 7, 4, 1 ]
then i applied to the image and i get gaussian filtered image but i don't know to change the gaussian filter degree (sigma is 1 and i couldn't change this value),
so how can i use this mask with different sigma values.
Answers (1)
Here is one example.
% specify input parameter as a scalar or 2-element vector
sigma = [4 5]; % [y x]
% expand if necessary
if isscalar(sigma); sigma = [1 1]*sigma; end
% generate kernel
r = ceil(2.5*sigma); % filter size is (2*r + 1) pixels
[xx yy] = meshgrid(-r(2):r(2),-r(1):r(1));
fk = exp(-(xx.^2/(2*sigma(2)^2) + yy.^2/(2*sigma(1)^2)));
fk = fk./sum(fk(:)); % sum-normalize
imshow(fk,[])
Categories
Find more on Image Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!