Writing my own gaussian filter

1 view (last 30 days)
Dan
Dan on 28 Feb 2012
I am aware there iseasier ways to do this using matlabs inbuilt functionality but I am trying to implement a Gaussian filter. I have this code so far but it is not working and the filtered image is coming out black. Any ideas, thank you!
sig = 1.5;
[M,N] = size(img);
y = zeros(size(img));
r = 1; % Adjust for desired window size
for n = 1+r:N-r
for m = 1+r:M-r
% Extract a window of size (2r+1)x(2r+1) around (m,n)
w = img(m+(-r:r),n+(-r:r));
GAUSS = 1/(2*pi*sig^2)*exp(-(M.^2+N.^2)/(2*sig^2));
GAUSS = GAUSS./sum(GAUSS(:));
y(M,N) = GAUSS;
end
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!