How to make the histogram of an image in Julia

How to make the histogram of an image in julia?

I’m working with images in julia, but I have problems taking the histogram of an image

using ImageView, Images, TestImages
img_gld = imread("...path to some color jpg...")
    img_gld = imread("mandril")

img_gld_gs = convert(Image{Gray},img_gld)
#change of floats to matrix of values ​​between 0 and 255:
img_gld_gs = reinterpret(Uint8,data(img_gld_gs))

someone could help me?

If you just want to make a plot of the histogram,

using Images, TestImages, Plots

img = Gray.(testimage("mandrill"))
histogram(vec(reinterpret(UInt8, img)))

If you actually need raw counts, try bins, vals = imhist(img).

but it does not show me the histogram

It’d be helpful if you could be a bit more specific – what output are you hoping for exactly? Could you link to an example? The code you have above seems to be copied and pasted from a 4 year old Stack Overflow post?

Here’s some sample code that might serve as a start:

using Plots, StatsBase, TestImages

img = testimage("lighthouse")

plot(leg=:none)
for (comp, col) = zip([red, green, blue], [RGB(1,0,0), RGB(0,.8,0), RGB(0,0,1)])
    hist = fit(Histogram, reinterpret.(comp.(vec(img))), 0:256).weights
    plot!(hist, c=col, f=(0, RGBA(col, 0.5)))
end
gui()

Result:

6 Likes

that’s right, it’s a stack overflow, I’m really new to using julia, and I’m liking it and I’d love to continue learning more about this program, (I’m working on the console)