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 & HelpOther Libraries › RANGE OF a particular COLOR
Page Index Toggle Pages: 1
RANGE OF a particular COLOR (Read 1678 times)
RANGE OF a particular COLOR
Nov 29th, 2009, 5:19am
 
You draw with a red marker on a white paper and capture a video. When you want to track the red marked sketch, I can only detet a particular value but I need to detect a range of red colors. Can any one guide to track a range of red values?
Re: RANGE OF a particular COLOR
Reply #1 - Nov 29th, 2009, 7:18am
 
you can use HSB mode instead of RGB mode.
on the HSB color space, it is relatively easy to define the distance representing the color similarity, i think.
like
http://www.geocities.jp/classiclll_newweb/SimilarColorProcessor4/applet/index.html
Re: RANGE OF a particular COLOR
Reply #2 - Nov 30th, 2009, 7:58am
 
Hi Classiclll,

Great, many thanks. Your example is quite good and advanced.

I am a beginer. Is there a simple way of tracking a range of colors?

Re: RANGE OF a particular COLOR
Reply #3 - Nov 30th, 2009, 8:35am
 
Not tested but should work.

Code:

color cl1 = color(random(255),random(255),random(255));
color cl2 = color(random(255),random(255),random(255));

if(isIn(cl1.hue(), cl2.hue()) && isIn(cl1.saturation, cl2.saturation) && isIn(cl2.brightness, cl2.brightness)) {

}

boolean isIn(int value, int test){
return value>test - 10 && value < test + 10; //10 is your range
}
Re: RANGE OF a particular COLOR
Reply #4 - Nov 30th, 2009, 8:53am
 
though it is a little heavy, i like

sqrt(pow(hue(a)-hue(b),2)+pow(saturation(a)-saturation(b),2)+pow(brightness(a)-b
rightness(b),2)) < tol

rather than

{abs(hue(a)-hue(2))+abs(..)+abs(..)}/3 < tol
Re: RANGE OF a particular COLOR
Reply #5 - Nov 30th, 2009, 11:51am
 
For what it's worth, here's an ancient color tracker class from 2003 for Processing ALPHA. The example won't run anymore without some changes to the Capture setup, but the VTracker class itself should be still usable:

http://toxi.co.uk/p5/vTracker/vTrackerCol.pde
Re: RANGE OF a particular COLOR
Reply #6 - Nov 30th, 2009, 12:06pm
 
Alternatively you might also want to look at the colorutils library and its TColor or Hue classes.

You could do something like: Code:

import toxi.color.*;
import toxi.math.*;

TColor trackColor=TColor.newRGB(#ff0000);
float tolerance= 0.5;
...
// check captured pixels
for(int y=0; y<height; y+=2) {
 for(int x=0; x<width; x+=2) {
   TColor col=TColor.newARGB(get(x,y));
   if(col.distanceToHSV(trackColor)<tolerance) {
     // bingo
   }
 }
}


TColor also can calc the distance in RGB or CMYK space and has a method to return the closest of the 12 major hues of the color wheel (getClosestHue()).

See:
https://dev.postspectacular.com/docs/colorutils/toxi/color/TColor.html
https://dev.postspectacular.com/docs/colorutils/toxi/color/Hue.html
Page Index Toggle Pages: 1