MATLAB: How can i take mean of whole image excluding boundary pixels?

MATLAB

i want to take mean of image excluding boundary pixels..is there any way to calculate mean of whole image excluding boundary pixels ?

Best Answer

Hopefully this is not homework. This is how I'd do it if your definition of boundary is the straight left, top, right, and bottom edges of the image.
meanInside = mean2(grayImage(2:end-1, 2:end-1));
If it's a color image, extract the individual color channels and do it on each in turn. If your boundary is the edge of some irregularly shaped blob in the image, then you need a mask defining those edge pixels and then you can do
nonEdgeMeans = mean(grayImage(~edgeMask));
Related Question