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?
2 Answers
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.
-
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