I know how to take the mean of the whole image which is of size mxnx3 uint8 by using the following command
m = mean(I(:));
my understanding of this command is supposed we have a matrix
A=[1 2 3;4 5 6; 7 8 9];
mean_1=mean(A(:));
output is
A =
1 2 3
4 5 6
7 8 9
mean_1 =
5
A color image is stored as an mxnx3 matrix where each element is the RGB value of that particular pixel (hence it’s a 3D matrix). You can consider it as three 2D matrices for red, green and blue intensities. so how mean is calculated in this case for three 2D matrices in Matlab?
(:)
turns an array of any dimension into a column vector. So, the wholemxnx3
matrix is turned into a column vector. Hence, all its entries contribute to the mean. If you wanted the mean of only the red RGB data, you would need to doB=A(:, :, 1); mean_1 = mean(B(:))
. – Amos Egel