How to implement convolution instead of the built-in imfilter
Ältere Kommentare anzeigen
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 Kommentare
Valeska Pearson
am 10 Jul. 2013
Chad Gilbert
am 10 Jul. 2013
Are you happy to use conv2? Or are you avoiding it along with imfilter?
Image Analyst
am 10 Jul. 2013
Don't do that - it's not linear filtering, that's masking. See my demo below.
Ferdie
am 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.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
