Bitmap/Histogram: Difference between revisions

Content added Content deleted
(Added Kotlin)
(Added Julia language)
Line 723: Line 723:


=={{header|Julia}}==
=={{header|Julia}}==
<lang Julia>
{{works with|Julia|0.6}}
using Color, Images, FixedPointNumbers
ima = imread("bitmap_histogram_in.jpg")
imb = convert(Image{Gray{Ufixed8}}, ima)


<lang julia>using Images, FileIO
# calculate histogram
a = map(x->x.val.i, imb.data)
(nothing, h) = hist(reshape(a, length(a)), -1:typemax(Uint8))


g = float(imb.data)
ima = load("data/lenna50.jpg")
b = g .> median(g)
imb = Gray.(ima)
fill!(imb, Gray(0.0))
imb[b] = Gray(1.0)


medcol = median(imb)
imwrite(imb, "bitmap_histogram_out.png")
imb[imb .≤ medcol] = Gray(0.0)
</lang>
imb[imb .> medcol] = Gray(1.0)
This solution calculates the histogram, <tt>h</tt>, to comply with the letter of the task description. However, because it is easiest to calculate the median luminosity directly, <tt>h</tt> is not used to calculate the black to white threshold used to create the output image.
save("data/lennaGray.jpg", imb)</lang>

{{out}}
The [https://raw.githubusercontent.com/MichaeLeroy/rosetta-code/master/julia/completed/bitmap_histogram_in.jpg input] and [https://raw.githubusercontent.com/MichaeLeroy/rosetta-code/master/julia/completed/bitmap_histogram_out.png output] files.


=={{header|Kotlin}}==
=={{header|Kotlin}}==