# How to make the histogram of an image in Julia

**URL:** <https://discourse.julialang.org/t/how-to-make-the-histogram-of-an-image-in-julia/21745>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [March 11, 2019, 3:25pm UTC](https://discourse.julialang.org/t/how-to-make-the-histogram-of-an-image-in-julia/21745 "2019-03-11T15:25:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GERSON\_EZEQUIEL\_HERN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gerson_ezequiel_hern/32/7437_2.png) [@GERSON\_EZEQUIEL\_HERN](https://discourse.julialang.org/u/GERSON_EZEQUIEL_HERN)\
**Post date:** [March 11, 2019, 3:25pm UTC](https://discourse.julialang.org/t/how-to-make-the-histogram-of-an-image-in-julia/21745/1 "2019-03-11T15:25:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [March 11, 2019, 5:22pm UTC](https://discourse.julialang.org/t/how-to-make-the-histogram-of-an-image-in-julia/21745/2 "2019-03-11T17:22:58Z")

</div>

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

```julia
using Images, TestImages, Plots

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

```

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

---

<div class="post-metadata">

**Author:** ![GERSON\_EZEQUIEL\_HERN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gerson_ezequiel_hern/32/7437_2.png) [@GERSON\_EZEQUIEL\_HERN](https://discourse.julialang.org/u/GERSON_EZEQUIEL_HERN)\
**Post date:** [March 11, 2019, 7:23pm UTC](https://discourse.julialang.org/t/how-to-make-the-histogram-of-an-image-in-julia/21745/3 "2019-03-11T19:23:37Z")

</div>

> [@stillyslalom](#):
>
> ```julia
> 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

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [March 11, 2019, 7:40pm UTC](https://discourse.julialang.org/t/how-to-make-the-histogram-of-an-image-in-julia/21745/4 "2019-03-11T19:40:34Z")

</div>

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](https://stackoverflow.com/questions/27513141/getting-a-2d-histogram-of-a-grayscale-image-in-julia)?

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

```julia
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:

 ![](https://global.discourse-cdn.com/julialang/original/3X/9/4/941cd4496ea9663d5d60d0d9f4a34e7d9e2032b5.jpeg)

---

<div class="post-metadata">

**Author:** ![GERSON\_EZEQUIEL\_HERN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gerson_ezequiel_hern/32/7437_2.png) [@GERSON\_EZEQUIEL\_HERN](https://discourse.julialang.org/u/GERSON_EZEQUIEL_HERN)\
**Post date:** [March 11, 2019, 8:26pm UTC](https://discourse.julialang.org/t/how-to-make-the-histogram-of-an-image-in-julia/21745/5 "2019-03-11T20:26:19Z")

</div>

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)
