Detect only red pixels in Java
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?
Take a look at YCrCb color space.
Simple algorithm: convert your RGB image to YCrCb, extract red channel and make a threshold.
Convert RGB to HSL, and threshold the hue (H) component.
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.