I'm really finding many ambiguities in how I really should interpret the histogram of an RGB image? I could understand what the height denotes, but did not understand how the pixels get plotted on a single dimensional x-axis. Also, is it possible to plot the image onto histogram3D? I tried after converting it to separate RGB images but I get an error that says it is not able to calculate the "bins" the diagram.

Thank you

  • 2
    $\begingroup$ Have you read the wiki link:en.wikipedia.org/wiki/Image_histogram . For the Histogram3D part, I can't really understand what you are asking for. $\endgroup$
    – mmjang
    Sep 20, 2013 at 6:30
  • $\begingroup$ Collect ImageData using 'Byte' type and you can see the pixel values clearly in n*n*n dimension. Loop to pick two from each set for Histogram3D. Each represents a color channel hence 3 per set. You can pick them separately and find simple Historgram. It shall match the below plotted onces. $\endgroup$ Sep 20, 2013 at 9:59

2 Answers 2


The default is to not show any useful labelling, so perhaps it might be easier to do this:

i = ExampleData[{"TestImage", "Mandrill"}];
ImageHistogram[i, FrameTicks -> {True, True}, 
 Appearance -> "Separated"]

mandrill histogram

For the 3D aspect of your question, perhaps you want something like this:

{r, g, b} = ColorSeparate[ImageResize[i, 200]]
ListPlot3D[ImageData[r, DataReversed -> True], Mesh -> False, 
 ColorFunction -> "GrayTones"] 

red channel of mandrill

— this is just the red channel.


This might be one more manual way to see Histogram.

image = Import["ExampleData/lena.tif"]
tr = ImageData[image, "Byte"]
tr // Dimensions (*{116,150,3}*)
a = Table[tr[[i, j]] /. {a_, b_, c_} -> a, {i, 116}, {j, 150}](*Similarly for b,c)

Sample Histogram computation is

Histogram[b, 100, ChartBaseStyle -> EdgeForm[None],  ChartStyle -> Green]

Now comparing Histogram for a,b & c with ImageHistogram respectively. we shall see similar results. enter image description here

We can see both of them resembling. So, to calculate Histogram3D you need two coordinates which you can extract as,

ab = Table[tr[[i, j]] /. {a_, b_, c_} -> {a,b}, {i, 116}, {j, 150}]
(*Similarly for bc,ca)

My system is old so, I could produce it only once as it took long time. I am not pasting graphics for Histogram3D but you can generate it by Histogram3D[ab].


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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