francisMi
francisMi

Reputation: 935

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?

Upvotes: 1

Views: 2382

Answers (3)

avh4
avh4

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.

http://docs.oracle.com/javase/7/docs/api/java/awt/Color.html#RGBtoHSB%28int%2C%20int%2C%20int%2C%20float%5B%5D%29

Upvotes: 1

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272557

Convert RGB to HSL, and threshold the hue (H) component.

Upvotes: 3

ArtemStorozhuk
ArtemStorozhuk

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

Related Questions