简体   繁体   中英

how does Matlab calculate the mean of whole image?

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?

As has been suggested in the comments, you could create a temporary array for the R, the G and the B pages of the matrix and calculate their mean, but in the specific case of a 3D RGB matrix you're probably better of just doing,

rgb_mean = squeeze(mean(mean(A,1),2))

If you're not familiar with squeeze , it will convert the 3D 1x1x3 matrix that results from taking the means, into a 2D 1x3 vector, which is most likely what you are expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM