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.
Page Index Toggle Pages: 1
Color filter (Read 925 times)
Color filter
Oct 21st, 2007, 2:47am
 
To make a color tracking application for the first time, i'm hacking http://www.roborealm.com/tutorial/color_object_tracking_2/slide010.php

It uses 'RGB filter' for extracting the target color area, yet due to my ignorance on image processing, I can't understand how exactly it works and how to implement it. Even though there are related pages...:
http://www.roborealm.com/help/RGB%20Filter.php
http://www.roborealm.com/help/Color_Filter.php
Re: Color filter
Reply #1 - Oct 26th, 2007, 1:41pm
 
you'll first need to extract red, green and blue components of each pixel of your image :

Code:
int c = img[myPixel];
int r = red(c);
int g = green(c);
int b = blue(e);


here is another way to do it, using shift and bit mask, which are faster instructions (same result) :
Code:
int c = img[myPixel];
int r = c >> 16 & 0xFF;
int g = c >> 8 & 0xFF;
int b = c & 0xFF;


then, apply the given formula :
Code:

// blue filter :
b = (b - r) + (b - g);
r = 0;
g = 0;
// output :
c = color(r, g, b);
pixels[myPixel] = c;


this should be a good starting point. you can enhance your code with normalization stuff etc., as said in the tutorial.
Page Index Toggle Pages: 1