ImageHistogram
is much faster than Histogram
with ImageData
.
The only problem: I cannot find out how to make the y axis logarithmic. Is this possible?
I am using Mathematica 10.3.1.
Answer
Here is an answer from the Wolfram Technical Support:
Mathematica does not currently allow for an option for a logarithmic scale in ImageHistogram. However, taking apart the underlying structure, it is possible to rescale the data. The underlying structure is a GraphicsComplex, such that the following code should get you started on a workaround for your interests:
LogImageHistogram[input_Image, base_?NumericQ /; base >= 2] :=
Module[
{
imh = ImageHistogram[input], logdata
},
logdata = MapAt[
Log[#]/Log[base] &,
First@Cases[imh, GraphicsComplex[x_, y_] :> x, Infinity], {All, 2}
] /. Indeterminate -> -1;
(
imh /. GraphicsComplex[x_, y_] :> GraphicsComplex[logdata, y]
) /.
{
Rule[FrameTicks, x_] :> Rule
[
FrameTicks, {
{
{#, base^#} & /@ Range[1, 10] // N, None
}, {Automatic, Automatic}
}
],
Rule[PlotRange, x_] :> Rule[PlotRange, {0, Max[logdata]}]
}
]
This function takes two arguments,
1) the input image and
2) the logarithmic base with which to scale the y-axis.
This function isn't perfect because I only generate 10 tick marks, but these things can be adjusted by hand.
Also, because the GraphicsComplex contains some zeroes for the y-coordinates, I've artificially set these to -1 because the Log[0] is Indeterminate. You won't see these because the PlotRange starts at 0.
Show
[
LogImageHistogram[image, #],
BaseStyle -> {FontFamily -> "Calibri", FontSize -> 20},
ImageSize -> 800
] & /@ {10, 2}
gives:
Comments
Post a Comment