Bitmap/Read a PPM file: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added the REXX language.)
Line 747: Line 747:


=={{header|Julia}}==
=={{header|Julia}}==
<lang Julia>
{{works with|Julia|0.6}}
using Color, Images, FixedPointNumbers


<lang julia>using Images, FileIO, Netpbm
const M_RGB_Y = reshape(Color.M_RGB_XYZ[2,:], 3)


rgbimg = load("data/bitmapInputTest.ppm")
function rgb2gray(img::Image)
greyimg = Gray.(rgbimg)
g = red(img)*M_RGB_Y[1] + green(img)*M_RGB_Y[2] + blue(img)*M_RGB_Y[3]
save("data/bitmapOutputTest.ppm", greyimg)</lang>
g = clamp(g, 0.0, 1.0)
return grayim(g)
end

ima = imread("bitmap_read_ppm_in.ppm")
imb = convert(Image{Gray{Ufixed8}}, ima)
imwrite(imb, "bitmap_read_ppm_out.png")
</lang>

{{out}}
[https://raw.githubusercontent.com/MichaeLeroy/rosetta-code/master/julia/support/color_chips.png Input] and [https://raw.githubusercontent.com/MichaeLeroy/rosetta-code/master/julia/completed/bitmap_read_ppm_out.png output] images in <tt>PNG</tt> format. The <tt>PPM</tt> input file was created using a variant of the Julia PPM/Write [https://github.com/MichaeLeroy/rosetta-code/blob/master/julia/support/color_chips.jl solution] to provide something reasonably colorful.


=={{header|Mathematica}}/ {{header|Wolfram Language}}==
=={{header|Mathematica}}/ {{header|Wolfram Language}}==