Archived

This topic is now archived and is closed to further replies.

faet83

Color Search Algorithm

Recommended Posts

faet83    122
I''m trying to search for a specific color in an image. heres what i''m thinking. int img_x, img_y; int x, y; for( x=0; x < img_x; x++ ) { for( y=0; y < img_y; y++ ) { if( img->pixelcolor == Search_Color ) { // if image color is equal to predefined color // output only that color to a seperate image file // creating an image of only the search_color } } } is there a better way to do this? -= Off World Technologies, Inc. =-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
That''s it, basically.

Keep in mind that your colors actually have three components, though: rgb or hsv depending on the color space you use. Also, the colors will rarely exactly match up from pixel to pixel, so you probably want to check within a tolerance.

Something like this might work: ( abs(r - targetr) < 5) && (abs (g-targetg) < 5) && (abs (b - targetb) < 5)

I just picked 5 out of the air. In practice you''ll want to experiment with the tolerance there until you find something that works well for your application.

Share this post


Link to post
Share on other sites