Bitmap/Read a PPM file: Difference between revisions

→‎{{header|Julia}}: A new entry for Julia
(Nimrod -> Nim)
(→‎{{header|Julia}}: A new entry for Julia)
Line 745:
myimgGray=: toColor toGray myimg
myimgGray writeppm jpath '~temp/myimgGray.ppm'</lang>
 
=={{header|Julia}}==
<lang Julia>
using Color, Images, FixedPointNumbers
 
const M_RGB_Y = reshape(Color.M_RGB_XYZ[2,:], 3)
 
function rgb2gray(img::Image)
g = red(img)*M_RGB_Y[1] + green(img)*M_RGB_Y[2] + blue(img)*M_RGB_Y[3]
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}}==
<lang Mathematica>Import["file.ppm","PPM"]