# How do I find the average color of an image?

It sounds so simple to do, but the best solution I've found so far is by using the MeanFilter function, which isn't really feasible on large images. Can anyone help me out?

There are ImageMeasurements for this:

ImageMeasurements[image, "Mean"]
(* {0.427958, 0.559264, 0.130725} *)


If ImageMeasurements didn't exist we could have used this one-liner:

Total[#]/Length[#] &@Flatten[ImageData[img], 1]


ImageData will give you a matrix of RGB vectors, Flatten[...,1] will then give you a one-dimensional list of RGB vectors. Total adds them together, by dividing by the number of RGB vectors we get the mean.

Also take a look at blochwave's version in his comment below.

• What about Mean[#] &@Flatten[ImageData[image], 1]? – dr.blochwave Mar 30 '15 at 20:22
• @blochwave Hah! In my desire to do something more low level I missed this intermediate version. Thanks for the reminder. – C. E. Mar 30 '15 at 20:29
• Cool! I didn't know about the ImageData function, but it makes perfect sense now. – Tim Vermeulen Mar 31 '15 at 5:44