MATLAB: Mean value of subarrays

blkprocblockprocmean

I have a 3-dimensinal array ( 1483 rows, 417 columns and 4 bands). I am trying to get a mean value for each sub-array of 92rows*92columns. I have some zero values that I want to exclude when the calcualtion of mean is being done. I used the following code but it's not correct.my data type is uint32. i apperciate your help.

Best Answer

A couple of calls to convn. The first call will determine the number of zeros; the second will calculate the sum of all values in the sub array; array divide the second by the first.
If you don't want to do it to EVERY POSSIBLE subarray, use blkproc or blockproc with function handle
@(x)sum(x(:))./(sum(logical(x(:)))
Also be aware that since your data type is uint32, if the sum of the 92*92*4 values exceeds 4,294,967,295 it will truncate to 4,294,967,295 and your mean will be wrong.
Related Question