Recent

Author Topic: Difference in Red, blue and green values of a pixel in Windows and Ubuntu OS  (Read 5638 times)

newman

  • Jr. Member
  • **
  • Posts: 75
Hi,

I am trying to create a program that captures a image from a webcam, the image will need to be analysed, for this I use the Canvas.Pixels function  to extract the TColor value of the pixel, from this I get the Red, green and blue components using Graphics.Red, Graphics.Blue and Graphics.Green functions.

I find that the red, blue and green values of the pixels (same pixel is analysed) are different in Windows and Linux. Please remember that the pixel being checked is same in Windows and Linux.

Could anyone explain why this difference is there ??? Shouldn't the values be same in Windows and Linux ???

thanks
nm


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Webcams have settings to calibrate (autobalance) colors  and intensities.

Differing drivers might do this differently. Or even in a different mode altogether.

newman

  • Jr. Member
  • **
  • Posts: 75
I use the same JPEG file in windows and Linux..and still there is difference. Using Pinta in Linux I find that the Red, blue and green values match the ones in Windows..

However in Lazarus the values are entirely different.

I use this code.

var
 tc:TColor;

tc:= pbForm.Canvas.Pixels[X,Y];
r:= Graphics.Red(tc);
b:= Graphics.Blue(tc);
g:= Graphics.Green(tc);

Here X and Y are derived from the PaintBox, X and Y coordinates of MouseMove function...

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
tc:= pbForm.Canvas.Pixels[X,Y];
Have you tried to have a one-colored fill JPEG?
Did you check that X,Y in Lazarus are counted from 0, and X,Y in a photo editor may count from 0 and may count from 1 - here you might get a 1 pixel shift, and obviously different values for different X,Y.
How different are the values? I mean, are they absolutely different, or slightly different?

(UPD)
Quote
X and Y coordinates of MouseMove function...
You may get significantly different values here, as there is a gap between the window "top" and the control (which is DIFFERENT in Windows and Linux).
« Last Edit: September 08, 2017, 06:13:24 pm by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
However in Lazarus the values are entirely different.

You can try the tool I wrote some time ago to see if it works correctly:
http://forum.lazarus.freepascal.org/index.php/topic,37242.msg252828.html#msg252828

newman

  • Jr. Member
  • **
  • Posts: 75
thanks for the replies...I will check the tool, however I fail to understand why the very same project works in Windows whereas in Ubuntu I get different results..

The values are absolutely different...

as obtained from Pinta (ms paint also very similar values all less than 50)
Red=40
Green=57
Blue=21

While in lazarus application it is

Red=88
Green=95
Blue=87

Very rarely do rgb values go below 40...

The image I use contains some black sections and lighter sections,  I noticed while checking with Pinta (and MS paint) that lower the r,g,b values the darker the pixel color, however in my lazarus application
 even the lighter segments have high values..

 
« Last Edit: September 08, 2017, 06:28:03 pm by newman »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Okay, my guess is:

Programmers usually define RGB values using byte (0 .. 255) but designers usually define that values using percentage (0 .. 100).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Okay, my guess is:

Programmers usually define RGB values using byte (0 .. 255) but designers usually define that values using percentage (0 .. 100).
no rgb is always 0..255, 0..100 is CMY/CMYK in which case a a convertion is needed.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

newman

  • Jr. Member
  • **
  • Posts: 75
Thanks everyone,

I created a new application, I tested out the Canvas.Pixels function on an TImage, and found that rgb values matched those of Pinta and Windows....clearly there is a bug in my program...that I need to figure out..


thanks everyone for the help..
nm


Akira1364

  • Hero Member
  • *****
  • Posts: 561
Hi,

I am trying to create a program that captures a image from a webcam, the image will need to be analysed, for this I use the Canvas.Pixels function  to extract the TColor value of the pixel, from this I get the Red, green and blue components using Graphics.Red, Graphics.Blue and Graphics.Green functions.

I find that the red, blue and green values of the pixels (same pixel is analysed) are different in Windows and Linux. Please remember that the pixel being checked is same in Windows and Linux.

Could anyone explain why this difference is there ??? Shouldn't the values be same in Windows and Linux ???

thanks
nm

What is the Canvas.Pixels value when you build and run the application on Linux? (Presumably under GTK2, as it seems to be the only Linux widgetset that really works somewhat properly...) That's the value you should be comparing to the Windows canvas value, not the one you get from whatever Pinta is.
« Last Edit: September 09, 2017, 04:48:03 am by Akira1364 »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Difference in Red, blue and green values of a pixel in Windows and Ubuntu OS
« Reply #10 on: September 09, 2017, 03:17:22 pm »
rgb555? rgb565? I suspect it is a format issue. https://en.wikipedia.org/wiki/High_color
Specialize a type, not a var.

BeniBela

  • Hero Member
  • *****
  • Posts: 905
    • homepage
Re: Difference in Red, blue and green values of a pixel in Windows and Ubuntu OS
« Reply #11 on: September 09, 2017, 10:09:47 pm »
Ubuntu must be more red, because open-source is communistic idea

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: Difference in Red, blue and green values of a pixel in Windows and Ubuntu OS
« Reply #12 on: September 10, 2017, 03:59:56 am »
Ubuntu must be more red, because open-source is communistic idea

*knows that BeniBela is German and is strongly resisting the urge to make a World War 2 joke about why he dislikes communism so much*

But honestly that was pretty funny...... not sure these forums are the right place for politics though? (If anyone's wondering, I'm just a boring Canadian capitalist!)

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Difference in Red, blue and green values of a pixel in Windows and Ubuntu OS
« Reply #13 on: September 10, 2017, 05:05:45 am »
Behind the curtain capitalism and communism is exactly the same... and will always be the same!
Of course everybody standing in front of the PUNCH and JUDY SHOW shouldn't know that... it's a nice tool/game...

Yeah... I couldn't deny myself...  there are too many people out there who haven't yet understood this...  :)
... and sometimes a little bit more salt in the soup is very nice...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

 

TinyPortal © 2005-2018