why grey color looks violet?

Using (or providing) components based on the "Win32" framework

why grey color looks violet?

Postby askom on Sun Nov 26, 2017 10:34 pm

Hello all,

I transform RGB image (bitmap) to grey scale.
The quick and rough way is just to average matrices of R, G and B values.
More precisely I have to do weighted average.

Any way, I get an image with one color grades, but it is not grey color??
It is always violet, like attached.

Why?

Thanks a lot,
Sasha.
Attachments
1.bmp.pdf
(9.82 KiB) Downloaded 18 times
askom
 
Posts: 30
Joined: Fri Apr 09, 2010 7:22 pm

Re: why grey color looks violet?

Postby Phil Last on Sun Nov 26, 2017 10:44 pm

Can you show us the maths?

I'm seeing a single blue on black.
User avatar
Phil Last
 
Posts: 441
Joined: Thu Jun 18, 2009 6:29 pm

Re: why grey color looks violet?

Postby ray on Mon Nov 27, 2017 3:51 pm

"..the normal eye's colour response is not linear, the strongest response is to green (59%), then red (30%) and lowest to blue(11%)." (Taken from my Vector artcale "Windows BMP Bitmap Files and APL" vol 10 no 1 July 1993.)

If you have mixed the RGB colours in equal proportions, the blue content will be over represented, hence not grey.

For printing, an alternative to a RGB grey scale is Monochrome. By just using black and white ink, (should that be "bi-chrome"?), at a higher resolution with "dithering".

That is to say, to produce a 64 grey scale, each RGB pixel is replace by a 8x8 "boolean" array. By varying the total numbers of "1" in the array the required intensity of the grey can be achieved.

The actual position of each "1" in the array need to chosen with some care to prevent "Moiré" patterns appearing. I advocate creating the first 8 arrays (intensity 1-8 out of 64) using an "8 Queens on a chessboard" algorithm (adding 1 queen at each level), and then repeating this process starting from different squares, till all 64 are filled. (In fact this produces 65 levels, one pure white and 63 greys, and one pure black.)

I hope this helps.
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 111
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: why grey color looks violet?

Postby gil on Tue Nov 28, 2017 8:08 pm

Hard to say without seeing your code, but my guess is that if you are creating 24-bit images but only write values in the range 0-255, then you effectively only use the blue channel. You'd need to encode it using all 3 channels to get gray:
Say for a given pixel you calculate an average of 200, rather than writing the value 200 you encode it as a triplet of 200:
      256⊥3/200
gil
 
Posts: 53
Joined: Mon Feb 15, 2010 12:42 am

Re: why grey color looks violet?

Postby askom on Thu Nov 30, 2017 9:52 pm

Phil,

thanks a lot for your request. Preparing "math" to answer to you I found that everything works well:-))

⍝ google ‘lena.bmp’ for a favorite testing image (or use any
other image.bmp)
⍝ put it to your current directory and create bitmap:
'bmp'⎕wc 'bitmap' ('file' 'lena.bmp')
⍴cbits←bmp.CBits
512 512
'f' ⎕wc 'form'
f.Picture←bmp
⍝ red, green and blue mixture for each pixel
⍴rgb←(3/256)⊤cbits
3 512 512
⍝ what does matlab and others suggest?
⍝ google: convert rgb to grey scale
⍝ Y = .2126 * R^gamma + .7152 * G^gamma + .0722 * B^gamma
w←.2126 .7152 .0722
⍴grey←⌊.5+w+.×rgb
512 512
⍝ the range is
(⌊/,⌈/),grey
9 240
⍴grey←256⊥⊃3/⊂grey
512 512
'gbmp'⎕WC'bitmap'('cbits' grey)
f.Picture←gbmp
Well, it looks like expected...

Regards,
Sasha.

Phil Last wrote:Can you show us the maths?

I'm seeing a single blue on black.
askom
 
Posts: 30
Joined: Fri Apr 09, 2010 7:22 pm

Re: why grey color looks violet?

Postby askom on Thu Nov 30, 2017 10:10 pm

Hi Ray,

Thank you for your respond and very nice to contact you again!

Your answer sounds a bit depressing... About 8x8 arrays... Do you see my post, that the problem is resolved easily?

Regards,
sasha

ray wrote:"..the normal eye's colour response is not linear, the strongest response is to green (59%), then red (30%) and lowest to blue(11%)." (Taken from my Vector artcale "Windows BMP Bitmap Files and APL" vol 10 no 1 July 1993.)

If you have mixed the RGB colours in equal proportions, the blue content will be over represented, hence not grey.

For printing, an alternative to a RGB grey scale is Monochrome. By just using black and white ink, (should that be "bi-chrome"?), at a higher resolution with "dithering".

That is to say, to produce a 64 grey scale, each RGB pixel is replace by a 8x8 "boolean" array. By varying the total numbers of "1" in the array the required intensity of the grey can be achieved.

The actual position of each "1" in the array need to chosen with some care to prevent "Moiré" patterns appearing. I advocate creating the first 8 arrays (intensity 1-8 out of 64) using an "8 Queens on a chessboard" algorithm (adding 1 queen at each level), and then repeating this process starting from different squares, till all 64 are filled. (In fact this produces 65 levels, one pure white and 63 greys, and one pure black.)

I hope this helps.
askom
 
Posts: 30
Joined: Fri Apr 09, 2010 7:22 pm

Re: why grey color looks violet?

Postby askom on Thu Nov 30, 2017 10:13 pm

I sent some "code" here& what is opinion now? thanks.

/sasha

gil wrote:Hard to say without seeing your code, but my guess is that if you are creating 24-bit images but only write values in the range 0-255, then you effectively only use the blue channel. You'd need to encode it using all 3 channels to get gray:
Say for a given pixel you calculate an average of 200, rather than writing the value 200 you encode it as a triplet of 200:
      256⊥3/200
askom
 
Posts: 30
Joined: Fri Apr 09, 2010 7:22 pm

Re: why grey color looks violet?

Postby gil on Fri Dec 01, 2017 7:52 am

The code you posted looks correct. Unless you changed your code since you posted the question I can't explain why you got a blue on black image before.

Well, the important thing is it's working now :)
gil
 
Posts: 53
Joined: Mon Feb 15, 2010 12:42 am

Re: why grey color looks violet?

Postby PGilbert on Fri Dec 01, 2017 3:49 pm

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
User avatar
PGilbert
 
Posts: 360
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada


Return to Windows: GUI, COM/OLE/ActiveX

Who is online

Users browsing this forum: No registered users and 1 guest