imfilter
and conv2
aren't exactly the same (imfilter is like conv2
with the filter flipped). If you use 'conv' then they are the same.
First you can check that you are using the correct image types using imfilter in the other way. Check this:
out1=conv2(double(image),kernel,'same');
out_conv=uint8(out1);
old_imfilter=imfilter(image,kernel,'same');
new_imfilter=imfilter(image,kernel(end:-1:1,end:-1:1),'same');
new_imfilter
and out_conv
should be the same. If so, you can do it with your method:
convImage = uint8(conv2(double(image),kernel,'same'));
filteredImage = imfilter(image,kernel,'conv','same');
Now filteredImage
and convImage
should be the same.