mean value of subarrays
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (1)
Sean de Wolski
le 22 Avr 2011
Here's a 2-dimensional example that demonstrates the logic and kernels.
%sample data
A = uint32(repmat(magic(10),[4,1]));
A(A<10) = 0;
%We will use a window size 6x10
window = ones(6,10);
nnzeros = conv2(double(logical(A)),window,'valid'); %you can change this shape do whatever it is you want at the edges.
winsum = conv2(double(A),window,'valid');
mean_wout_zeros = winsum./nnzeros;
%check that it worked (for first valid value)
isequal(sum(sum(A(1:6,:)))/nnz(A(1:6,:)),mean_wout_zeros(1))
You could convert mean_wout_zeros back to uint32 if you want...
4 commentaires
Hassan
le 22 Avr 2011
Sean de Wolski
le 22 Avr 2011
Where does the 16x5 come from? It seems to be appearing out of the air. For the skipping every 92; do EXACTLY what I have above (with a ones(92) window and extract every 92nd value. I.e. mean_wout_zeros = mean_wout_zeros(1:92:end);
Hassan
le 22 Avr 2011
Hassan
le 22 Avr 2011
Catégories
En savoir plus sur Neighborhood and Block Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!