Sorry for my poor english. I am really new in Mathematica. I have a data set and plot it in histogram, The whole script is following:test.jpg

img = ImageResize[Import["test.JPG"], 1000];
img = ImageTrim[img, {{.02, .02}, {.98, .98}}, DataRange -> {{0, 1}, {0, 1}}];
img1 = DeleteSmallComponents[Binarize[img, 0.3], smallSize];
img1 = DeleteSmallComponents[ColorNegate[img1], smallSize];
img1 = ColorNegate[Binarize[img1]];
img2 = MorphologicalComponents[img1] // Colorize;
img3 = WatershedComponents[img1, Method -> {"MinimumSaliency", 2.0}] //Colorize;
Show[GraphicsGrid[{{img2, img3}}, ImageSize -> 1000, Spacings -> {0, 0}]]

img4 = ColorNegate[img1];
img5 = MorphologicalComponents[img4] // Colorize;
img6 = WatershedComponents[img4, Method -> {"MinimumSaliency", 1.0}] //Colorize;
Show[GraphicsGrid[{{img5, img6}}, ImageSize -> 1000, Spacings -> {0, 0}]]

Now I prefer to plot it in log scale so it would be shown as a line with a specific slope. In other words, I want to find the X and y coordinates of the red circles shown in the picture. (The red circles are located as the median of each bin.) And then plot these red points in semi-log scale. enter image description here

My code as related to my request.

window[list_, {xmin_, xmax_}] := Pick[list, Boole[xmin <= # <= xmax] & /@ list, 1]
data = Tally[Flatten[MorphologicalComponents[img5,CornerNeighbors -> False]]]; 
window[data[[All, 2]], {10, 2000}];
GraphicsGrid[{{img, img5, Histogram[Sqrt[%]]}},
  ImageSize -> 1000, Spacings -> {0, 0}]
  • 1
    $\begingroup$ Can you elaborate on what it means for a histogram (log scale or otherwise) to be shown as a line with a specific slope? I am totally unfamiliar with that concept. $\endgroup$
    – JimB
    Jul 1, 2016 at 3:11
  • $\begingroup$ Sorry so the data is like: Sort[data, #1[[2]] > #2[[2]] &] {{1, 409318}, {0, 174697}, {189, 1443}, {286, 1056}, {289, 964}, {361, 903}, {259, 685}....... The first coordinate is the label of each area and the second is the area of this region. It just label each one based on the region's position in an image. For the semi-log plot, I want the x axis is the number of the area and y axis is the area. For example: point (9,60) in the semi-log plot means that there are 9 regions with area 60. $\endgroup$
    – Shuoqi Li
    Jul 1, 2016 at 3:50
  • $\begingroup$ I am voting to close this question because it is not at all clear what you are asking. We don't have the context you have, so we don't know what data is, what your code is supposed to do, what "areas" and "regions" are, etc. Try to explain it in a clear and concise way, so that someone who has absolutely no idea what you are doing (we don't) will understand it. $\endgroup$
    – Szabolcs
    Jul 1, 2016 at 7:54
  • 2
    $\begingroup$ @JimBaldwin Doing such transformations is in fact quite common. Also, the Histogram function does much more than histograms, so it's not really a concern that the result is not technically that. Here's an example: data = RandomVariate[ParetoDistribution[1, 4], 50000];. Now Histogram[data, PlotRange -> All] is not particularly informative, while Histogram[data, "Log", {"Log", "Count"}] is very much so. We can also do Histogram[data, "Log", {"Log", "SurvivalCount"}]. There's the revealing straight line, summoned up with a single simple command. $\endgroup$
    – Szabolcs
    Jul 1, 2016 at 20:19
  • 1
    $\begingroup$ @Jim Also note that with the vertical axis transformation the ticks are transformed too. So it is still a proper histogram, just displayed in a different way. $\endgroup$
    – Szabolcs
    Jul 1, 2016 at 20:28


Your Answer

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