I am working on a program where I take RGB values ββfrom part of an image. I want to remove the darkness in color and make it bright. What I do, I use Color.RGBtoHSB Then I take the brightness channel and set it to the highest value that can be in the range, and then converts the HSB back to RGB. However, when I do this, the color changes completely. Here is a dark red example and it turns purple and the code I use for 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
source share