0
votes

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?

1
When you do A(:) to any matrix of any size, it gets converted into a column vector. You know the rest. Right?Sardar Usama
yes I know from that converted column vector we estimate mean, but my question is for a color image we have three matrices, among them which one is used or all three are used and converted into column vector or something else i don't know and that is what i want to know @SardarUsamaanil
As Sardar wrote in his comment, the colon operator (:) turns an array of any dimension into a column vector. So, the whole mxnx3 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 do B=A(:, :, 1); mean_1 = mean(B(:)).Amos Egel
@AmosEgel the third dimension (page) value is included while estimating the mean.,right?anil
@anil Do you have any further questions or did Sardar and Amos address all of your concerns?Dev-iL

1 Answers

0
votes

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.