MATLAB: How to apply a 2D low pass filter to a colored image

2dcolorfilterimagelowpassprocessing

It works fine when I apply the filter on the grayscale format of the image but not on the actual colored image
img = imread('IMG_1638.tif');
gray = rgb2gray(img);
h = fir1(4,0.25,'low');
h = h'*h;
freqz2(h)
y = filter2(h,gray,'same');
figure, imshow(gray);
figure, imshow(uint8(y));

Best Answer

You would need to rewrite your filter2() in terms of convn(), because filter2() does not accept 3 dimensional matrices.
However, are you certain that you want all three color channels to be taken into account simultaneously for filtering? If you only need to take into account one color channel at a time, then you can use filter2() on each successive channel and put the results together. (You can code that more compactly with arrayfun() but really a loop is faster.)