6
$\begingroup$

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?

$\endgroup$

2 Answers 2

13
$\begingroup$

There are ImageMeasurements for this:

ImageMeasurements[image, "Mean"]
(* {0.427958, 0.559264, 0.130725} *)
$\endgroup$
7
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.