I have a int representation of a color. What I want to do is if this color is too black or too white, I want to set background to a default color. I want to find if the color is too close to black or white using RGB or HSV representation is fine. By too black or too white, I mean to say I can set some threshold depending on the scale. Say there is a scale from 0 to 1 where 0 is black and 1 is white, I want to reject all the colors below 0.2 and above 0.8. I tried the below code but it actually does not work. This does not work since I see some other colors also get rejected which are not shades of black or white. Please help.
public static boolean isWhitish(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
return hsv[2] > 0.8;
}