bits←⌊0.5+(+/[⎕IO]256 256 256⊤bits)÷3
It didn't work for me:-)
Only _weighted_ mean:
⍝ Y = .2126 * R^gamma + .7152 * G^gamma + .0722 * B^gamma
did the thing right.
/sasha
PGilbert wrote:Here is the code I am using to convert a color image to grey:GrayPic picname;bits
⍝ TRANSFORM THE COLORS OF A PICTURE ELEMENT INTO 256 SHADES OF GRAY
⍝ picname = NAME OF THE APL Picture ELEMENT
⍝ FOR A SINGLE PIXEL THE EQUATION IS: GRAY←256⊥3⍴⌊0.5+(+/256 256 256⊤RGB)÷3
:IF 0=⍴picname ⎕WI 'self' ⋄ picname," DOES NOT EXIST !" ⋄ →0 ⋄ :END
:IF ~'Picture'⊣(picname ⎕WI 'class') ⋄ picname," MUST BE A PICTURE !" ⋄ →0 ⋄ :END
bits←picname ⎕WI 'image'
bits←⌊0.5+(+/[⎕IO]256 256 256⊤bits)÷3
bits←256⊥(3,⍴bits)⍴bits
picname ⎕WI 'bitmap' bits
It is part of the workspace 'PicUtil' written in APL+Win that can be found on the APLWiki.
There is also a free dll (FreeImage) that can be used with more options. The Dyalog workspace with explanations can be found also on the APLWiki.
Regards,
Pierre Gilbert