Reputation: 935
I need to detect all the red pixels in an image using Java. What 's the best way to do this?
Only supposing a pixel is red when the Red RGB-value is > 200 isn't good enough (see this table).
So is there a better way to do this? Or is there some red-color-rgb algorithm?
Upvotes: 1
Views: 2382
Reputation: 2655
As you suggested, you probably want to do some comparison in HSB space. You'll probably want to define an appropriate rage for all three values based on what your expectations are.
You can use Color.RGBtoHSB
to get the values from a given color.
Upvotes: 1
Reputation: 272557
Convert RGB to HSL, and threshold the hue (H) component.
Upvotes: 3
Reputation: 8725
Take a look at YCrCb color space.
Simple algorithm: convert your RGB image to YCrCb, extract red channel and make a threshold.
Upvotes: 3