## Averaging an image

on 20 Mar 2011

### Walter Roberson (view profile)

A basic Image Processing question . How can I average the values or RGB for an input color image? If the input is a color image, the output I need is just the average value of RGB in the entire image. How can I do it?

## Products

### Walter Roberson (view profile)

on 20 Mar 2011

One possible interpretation:

```mean(YourImage(:))
```

Another possible interpretation:

```mean(reshape(YourImage, size(YourImage,1) * size(YourImage,2), size(YourImage,3)))
```

Which you choose depends on whether you need the average R separate from the average G and average B (second expression) or if you are looking for the single over-all average value (first expression.)

Niranjan

### Niranjan (view profile)

on 20 Mar 2011

I want only a single value of RGB as an output for the entire image. I can't understand your second expression but that gave me this.
[ 120.2294 115.3884 118.1661 ]
Is this what I am looking for? Please clarify me.
I am doing this operation in order to average an image ,to calculate the average value of RBG in the entire image.

Walter Roberson

### Walter Roberson (view profile)

on 21 Mar 2011

Do you want the average R, the average G, and the average B? If so, that's what the second expression gives.

If you want a single value that averages the intensity of _everything_, then that is what the first expression gives.

If you want a simpler version of the second expression, it would be

mean(reshape(YourImage,[],size(YourImage,3)))

Jan Simon

### Jan Simon (view profile)

on 21 Mar 2011

Or even simpler for RGB images: mean(reshape(YourImage, [], 3))

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi