Writing my own gaussian filter
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (0)
See Also
Categories
Find more on Digital Filter Analysis 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!