2
$\begingroup$

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.

enter image description here

The color histogram of this is:

enter image description here

And the gradient histogram is:

enter image description here

Below is what I expect as my 2D histogram:

enter image description here

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];
gradient = Flatten@ImageData@GradientFilter[im, 1];
vals = Transpose[{gradient, intensity}];
plot1 = ImageHistogram[im]

and got the result as

enter image description here

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

and the corresponding plot is:

enter image description here

And the joint plot is:

enter image description here

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

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Szabolcs Mar 29 '17 at 11:45
  • 1
    $\begingroup$ E.g. BinCounts[vals, {2^Range[-12, 0]}, {Range[0, 1, 0.05]}] // MatrixPlot $\endgroup$ – Szabolcs Mar 29 '17 at 11:55

Your Answer

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

Browse other questions tagged or ask your own question.