• Advertisement

Archived

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

Color Search Algorithm

This topic is 5822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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

  • Advertisement