I am working on a program where I take RGB values from a portion of an image. I want to remove the darkness in the color and make it bright. What I do is I use Color.RGBtoHSB
I then take the brightness channel and set it to the highest value it can be in range then convert the HSB back to RGB. However, when I do this the color changes completely. Here is an example with dark red and it turning to purple and the code I use to do this.
System.out.println("Before Conversion:");
System.out.println("R: " + rAvg + "\nG :" + gAvg + "\nB :" + bAvg);
Color.RGBtoHSB(rAvg, gAvg, bAvg, hsv);
hsv[2] = 100; //Set to max value
System.out.println("H: " + hsv[0] * 360 + "\nS: " + hsv[1] * 100 + "\nV :" + hsv[2]);
int rgb = Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]);
System.out.println("After conversion");
Color color = new Color(rgb);
System.out.println("R: " + color.getRed());
System.out.println("G: " + color.getGreen());
System.out.println("B: " + color.getBlue());
Output:
Before Conversion:
R: 128
G :39
B :50
H: 352.58426
S: 69.53125
V :100.0
After conversion
R: 158
G: 126
B: 233
The brightness, hsv[2]
, needs to be a value between 0 and 1. Try these two lines of code:
hsv[2] = 1; //Set to max value
System.out.println("H: " + hsv[0] * 360 + "\nS: " + hsv[1] * 100 + "\nV :" + hsv[2] * 100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With