MATLAB: Recolor an image tile-wise with average colors of these certain tiles

image analysisImage Processing Toolboxrecoloring

Hello everyone,
I have the following image (original image is .tif format)
Now, I would like to recolor it, that I don't have single color pixels anymore. I imagine something like the following:
assess a 10 x 10 pixel wide tile (or any other size), add only the non-zero color values and devide it by the number of non-zero values in this 10 x 10 tile to get the average pixel color. Than, recolor this 10 x 10 tile with the average pixel color. And than repeat this, with all possible not overlapping tiles of the image.
I hope, someone is 1. abler to understand waht I tried to say and 2. also able to help me.
Thank you!
Julian

Best Answer

Use blockproc to handle the block processing
doc blockproc
Then write a function which does the average ignoring zeros. So something like:
blockproc(magic(100),[10 10], @(bs)(sum(bs.data(logical(bs.data)))./nnz(bs.data))*ones(size(bs.data)))