MATLAB: How to make mean filter for color image

colorimageimage processingMATLABMATLAB and Simulink Student Suitemean

I am trying to do something like this for a color image:
SetPixelsIn32by32BlocksToStandardDeviationExample_01.png SetPixelsIn32by32BlocksToStandardDeviationExample_02.png
I was trying to use plockproc function but kept getting an error; it is my first time working with an image in matlab but i feel like it should not be hard to do. Can anyone help please?

Best Answer

Gleb, you just had to make a minor modification to my code to call it 3 times, once for each color channel, and then recombine the results into an RGB image.
meanFilterFunction4 = @(theBlockStructure) mean2(theBlockStructure.data(:)) * ones(1, 1, class(theBlockStructure.data));
% Now,here we actually to the actual filtering.
blockyImageR = blockproc(redChannel, blockSize, meanFilterFunction4);
blockyImageG = blockproc(greenChannel, blockSize, meanFilterFunction4);
blockyImageB = blockproc(blueChannel, blockSize, meanFilterFunction4);
[blockRows, blockColumns] = size(blockyImageR)
% Recombine separate color channels into a single, true color RGB image.
rgbImage2 = cat(3, blockyImageR, blockyImageG, blockyImageB);
Attached is a full demo using the standard peppers demo image and using a variety of input and output block sizes.
0000 Screenshot.png
Let me know if you still don't know how to adapt it to what you want.