## How to calculate the mean of an image?

### bh dhouha (view profile)

on 16 Feb 2015
Latest activity Commented on by Kweku Nkrumah

on 15 Jun 2018

### Image Analyst (view profile)

How to calculate the mean of an image? Does the code mean2(img) give the right result?

### Image Analyst (view profile)

on 16 Feb 2015

To calculate the mean of all pixels in the image, without regard to what color channel they came from (if it's a color image), you do
meanIntensity = mean(img(:));
What you did will not do it, as I'm sure you found out.

bh dhouha

### bh dhouha (view profile)

on 16 Feb 2015
Thank you very much :) just a little thing : i used mean(mean(img1(:,:,1)))and it gave me the same result as mean(img1(:)).The first code is focused on the red channel only i think-as you answered me in another question- so how could it be the same result?
Image Analyst

### Image Analyst (view profile)

on 16 Feb 2015
It could be the same if the image was gray since the blue and green channel would be identical to the red channel. It would also be the same for lots of other cases, like where the green and blue channels are scrambled (spatially rearranged) versions of the red channel since they would have the same pixel values regardless of how they're rearranged.

### Rashmi.D Jeya kumar (view profile)

on 8 Jan 2018

meanval = mean2(I) you can get mean value of an image

Kweku Nkrumah

### Kweku Nkrumah (view profile)

on 13 Jun 2018
Hello. I used the above code (meanval=mean2(I)) for finding the mean of different images. Over sometime, it gave me the same value for the mean of most of the images. What could be wrong?
Image Analyst

### Image Analyst (view profile)

on 13 Jun 2018
Why does that mean anything is wrong? Maybe you took a bunch of photos through a microscope and they all have the same mean brightness (or really close to each other). Doesn't seem inherently unusual to me. Why do you think it indicates something is wrong?
Kweku Nkrumah

### Kweku Nkrumah (view profile)

on 15 Jun 2018
Ok. I get it now. Thank you.