Bitmap/Histogram: Difference between revisions

→‎{{header|Julia}}: A new entry for Julia
(→‎{{header|Julia}}: A new entry for Julia)
Line 607:
<lang j> 'Lenna100BW.ppm' writeppm~ toColor toBW readppm 'Lenna100.ppm'
786447</lang>
 
=={{header|Julia}}==
<lang Julia>
using Color, Images, FixedPointNumbers
ima = imread("bitmap_histogram_in.jpg")
imb = convert(Image{Gray{Ufixed8}}, ima)
 
# calculate histogram
a = map(x->x.val.i, imb.data)
(nothing, h) = hist(reshape(a, length(a)), -1:typemax(Uint8))
 
g = float(imb.data)
b = g .> median(g)
fill!(imb, Gray(0.0))
imb[b] = Gray(1.0)
 
imwrite(imb, "bitmap_histogram_out.png")
</lang>
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.
 
{{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|Lua}}==
This solution uses functions defined at: