How to implement convolution instead of the built-in imfilter
Show older comments
m=13; n=13;
sigma=15;
[h1 h2]=meshgrid(-(m-1)/2:(m-1)/2, -(n-1)/2:(n-1)/2);
hg= exp(-(h1.^2+h2.^2)/(2*sigma^2)); %Gaussian function
h=hg ./sum(hg(:));
Now I want to use these Gaussian kernels to implement linear filtering with on image
OriginalRGB = imread('LeerNaam.png'); % read image
filter=h; s = size(OriginalRGB);
r = zeros(s);
for i = 2:s(1)-1
for j = 2:s(2)-1
temp = OriginalRGB(i-1:i+1,j-1:j+1)) .* filter;
r(i,j) = sum(temp(:));
end
end
4 Comments
Valeska Pearson
on 10 Jul 2013
Chad Gilbert
on 10 Jul 2013
Are you happy to use conv2? Or are you avoiding it along with imfilter?
Image Analyst
on 10 Jul 2013
Don't do that - it's not linear filtering, that's masking. See my demo below.
Ferdie
on 11 Jul 2013
Thanks... The reason for not implementing imfilter is because I need to know what imfilter does. It is for a project and I can't just use built-in functions.
Accepted Answer
More Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!