Grayscale image: Difference between revisions

different structure for grayscale, bug fixes
(added J code)
(different structure for grayscale, bug fixes)
Line 378:
 
=={{header|J}}==
 
Grayscale image is stored as two-dimensional array of luminance values.
 
<lang j>
NB. converts the image to grayscale according to formula
NB. L = 0.2126*R + 0.7152*G + 0.0722*B
toGray=: 3 & $ @ (+/) @: <. @ (0.2126 0.7152 0.0722 & *)"1 1
 
NB. converts grayscale image to the color image, with all channels equal
toColor=: 3 & $"0 0
 
</lang>
 
Examples:
Example:
 
<lang j>
viewImage toColor toGray myimg
</lang>
 
Anonymous user