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 & HelpPrograms › compare colours
Page Index Toggle Pages: 1
compare colours (Read 1653 times)
compare colours
Jun 3rd, 2010, 4:07pm
 
hi,

i want to compare a one pixel image to a colour value in RGB. I want to do it with "for" and "if" commands, but i think it will get realy slow in the way i do it (i'm not a compact coder) I want it to take a range of a colour value, example:
insert red> compare to pixel images, if it's yellow, or dark red or orange, it's okay.

But how can i do this?
I was thinking to do something like R value 221 and take a range of 191 to 251.  And this for every value.

Sorry for my english Smiley

I've found a topic about this matter, but it doesn't ansfer my question.
Re: compare colours
Reply #1 - Jun 3rd, 2010, 6:07pm
 
once you load the image (PImage myImg=loadImage("pixel.png");) and get the color of the pixel (color pixelColor = myImg.get(0,0)), you can extract each RGB value from it using:

float r1 = red(pixelColor)
float b1 = blue(pixelColor)
float g1 = green(pixelColor) ...

then it's easy to test the range of variance for each value.
Re: compare colours
Reply #2 - Jun 4th, 2010, 1:27am
 
Note that in some cases, you might be more interested in the hue() of the pixel than in the raw RGB data.
Re: compare colours
Reply #3 - Jun 4th, 2010, 3:47am
 
He lelijkerd,

Use HSB as colorMode. Like PhiLo suggested, you can set ranges there more easily.

I'd suggest you make a certain subdivision (resolution) of hues, saturation and brightness. While the hue should be divided in around 10-12 "colors", this subdivision may be much more coarse (3) for the saturation & brightness if you ask me.
Page Index Toggle Pages: 1