We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Processing calculating hue wrong??
Page Index Toggle Pages: 1
Processing calculating hue wrong???? (Read 628 times)
Processing calculating hue wrong????
Feb 27th, 2010, 3:38pm
 
I'm confused by this. I picked a colour from the colour selector in Processing  (red: 78 green: 116 blue: 97) - and it indicated the hue was 150.

I then wrote this little program to check a hue-calculating formula I found on Wikipedia.

Code:
color c = color(78, 116, 97); //hue 150

float phue = hue(c);
float chue = 180/PI*atan2( sqrt(3)*(green(c)-blue(c)) , 2*red(c)-green(c)-blue(c) );

println("Processing Hue: " + phue);
println("Calculated Hue: " + chue);


Results:

Processing Hue: 106.25
Calculated Hue: 149.99998

Something weird is going on here. The formula returns the correct hue originally chosen, but Processing's hue function calculates it as 106.25.

I checked with the colour picker in Photoshop to make sure it wasn't the colour selector in Processing that was reporting the hue incorrectly....it wasn't.

Is this a bug in Processing, or have I missed something?


Re: Processing calculating hue wrong????
Reply #1 - Feb 27th, 2010, 5:14pm
 
hello

The default colorMode in processing ranges from 0 to 255,
seems like you are calculating in 360 range
106.25 * 360.0 / 255.0 = 150.0
Re: Processing calculating hue wrong????
Reply #2 - Feb 27th, 2010, 6:06pm
 
Oh yeah...of course. I feel stupid now.

Code:
color c = color(78, 116, 97); //hue 150

colorMode(HSB, 360, 100, 100);
float phue = hue(c);
colorMode(RGB, 255, 255, 255);
float chue = 180/PI*atan2( sqrt(3)*(green(c)-blue(c)) , 2*red(c)-green(c)-blue(c) );

println("Processing Hue: " + phue);
println("Calculated Hue: " + chue);


Processing Hue: 150.0
Calculated Hue: 149.99998
Page Index Toggle Pages: 1