Bitmap/Histogram: Difference between revisions

Added Julia language
(Added Kotlin)
(Added Julia language)
Line 723:
 
=={{header|Julia}}==
<lang{{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))
 
gima = floatload(imb."data/lenna50.jpg")
bimb = g Gray.> median(gima)
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[bimb .> 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}}==
Anonymous user