Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am doing my PhD in Clinical Neuropsychology; I had someone helping me analyse images (.jpg pictures) in Mathematica, but it turns out this person made some really bad decisions, and well, now I have to do it myself. But, I have no idea.

Basically, what I want is to analyze the JPEG image, get a RGB histogram, and get the values for the mean and standard deviation of this histogram.

Using ImageHistogram [[*image*], Appearance, -> "Separated"] works fine, but I can't figure out the next step, turning the histogram plot into numbers.

How can I do that?

Thank you for helping!

share|improve this question
You could use ImageData[] to get the values being binned for the histograms... –  Guess who it is. Oct 12 '12 at 13:27
Thank you for responding!!I am trying it right now! –  onemonkey Oct 12 '12 at 13:31
Hmmm... it says A very large out put was generated, here is a sample of it. "{0., 0., 0.}, {0., 0., 0.}, {0., 0., 0.}," –  onemonkey Oct 12 '12 at 13:33
And if I input: StandardDeviation[Out[37]] I get pretty much the same result. –  onemonkey Oct 12 '12 at 13:34
You might need the Interleaving option... –  Guess who it is. Oct 12 '12 at 13:40

2 Answers 2

There is one suggestion.

img = ExampleData[{"TestImage", "Lena"}];
imgChannelsRGB = Transpose@Flatten[ImageData[img], 1];

Creating Histogram:

GraphicsRow[Histogram /@ imgChannelsRGB, ImageSize -> 500]

enter image description here

Geting statistics:

TableForm[Through[{Mean, StandardDeviation}[#]] & /@ imgChannelsRGB, 
 TableHeadings -> {{"Red", "Blue", "Green"}, {"Mean", "StDev"}}]

enter image description here

share|improve this answer
Alternatively: imgChannelsRGB = Flatten /@ ImageData[img, Interleaving -> False]. The Lenna example image is easily accessed as ExampleData[{"TestImage", "Lena"}]. –  Guess who it is. Oct 12 '12 at 14:00
Nice tip. Changed the example. –  Murta Oct 12 '12 at 14:03
Am trying it right now! –  onemonkey Oct 12 '12 at 14:09
O wow, this is very promissing! I'm going to play with this (and then I might be back). Thnx! –  onemonkey Oct 12 '12 at 14:43
You could use ImageData[img] ~Flatten~ {{3}, {1, 2}} in place of Transpose@Flatten[ImageData[img], 1], eliminating Transpose. –  Mr.Wizard Oct 12 '12 at 15:19

I thought it might be interesting to combine the graphs and statistics in small multiple style, but I got stuck... How do you present two numbers as a label without showing the curly brackets?

small multiple


{r, g, b} = ColorSeparate[img];
    ImageHistogram[#, Appearance -> "Transparent",  Joined -> False, 
     Frame -> None],
    ImageSize -> 200
    ] & /@ {r, g, b}

Edit with bill (?!)'s suggestion:

    ImageHistogram[#, Appearance -> "Transparent", Joined -> False, 
     Frame -> None],
     14, Bold], 
    ImageSize -> 500
    ] & /@ {r, g, b}]

better small multiple

share|improve this answer
Maybe add a Column ? Row[Labeled[ ImageHistogram[#, Appearance -> "Transparent", Joined -> False, Frame -> None], Column[{Mean[Flatten[ImageData[#]]], StandardDeviation[Flatten[ImageData[#]]]}], ImageSize -> 200] & /@ {r, g, b}] –  b.gatessucks Oct 12 '12 at 19:26
@b.gatessucks Good idea! As usual, your comments are better than my answers! :) –  cormullion Oct 12 '12 at 19:30
Wow! I have been getting some help from a friend, and we will definitely come back to this! –  onemonkey Oct 15 '12 at 9:46
OK, so we are on a roll, but now I have a new, buyt related qustion. Should i post it here or open a new topic? –  onemonkey Oct 19 '12 at 8:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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