# How to create 2D ImageHistogram?

Using ImageHistogram I can find the frequency of each color value in an image. Applying the same, I can have a histogram of its gradient values. I wish to combine these two on a log scale such that X - axis will represent the color values and Y - axis will represent the gradient values and each entry in the 2D histogram plot will represent the frequency of pixels having a specific color and gradient values.

Consider the image of Lena.

The color histogram of this is:

Below is what I expect as my 2D histogram:

The problem is how to display the frequency of a pair of color and gradient values through ImageHistogram.

Edit 1: After getting suggestion from Szabolcs, I've modified the code and got result as follows:

im = ColorConvert[lena, "Grayscale"];
intensity = Flatten@ImageData[im];
plot1 = ImageHistogram[im]


and got the result as

plot2 = Rotate[ImageHistogram[GradientFilter[im, 1]], 90 Degree]


and the corresponding plot is:

And the joint plot is:

However, I'm not sure whether I've got the desired result. Can anyone please confirm me?

• Assuming grayscale im, vals = Transpose[{Flatten@ImageData@GradientFilter[im, 1], Flatten@ImageData[im]}];, then use BinCounts with a suitable (perhaps manually constructed) bin specification to bin the 2D data. This should get you started. – Szabolcs Mar 29 '17 at 11:45
• E.g. BinCounts[vals, {2^Range[-12, 0]}, {Range[0, 1, 0.05]}] // MatrixPlot – Szabolcs Mar 29 '17 at 11:55