Pregunta

I am able with an BufferedImage to obtain the RGB values for every pixel of a 640x640 image, the output looks like this:

[...]
Pixel :(640, 634) RGB: 166 94 82
Pixel :(640, 635) RGB: 166 94 80
Pixel :(640, 636) RGB: 163 91 77
Pixel :(640, 637) RGB: 157 88 73
Pixel :(640, 638) RGB: 157 88 73
Pixel :(640, 639) RGB: 159 90 74
Pixel :(640, 640) RGB: 158 89 73
This image has 69197 colors.

I need to classify each of the RGB colors obtained this way into 3-bit RGB (8 colors), I would need to have an idea on how to do this... How to know the range of RGB for each of the 8 colors of the 3-bit RGB. Thanks!

¿Fue útil?

Solución

Your resulting image will have 1 bits for each color component.

For red for instance you should do this:

 red1Bit = redOriginal > 127 ? 1 : 0;

You should do the same for blue and green as well.

Otros consejos

A 24-bit RGB palette uses 8 bits for each of the red, green, and blue color components:

RGB([0..255], [0..255], [0..255]).

A 3-bit RGB palette uses 1 bit for each of the red, green and blue color components:

RGB([0..1], [0..1], [0..1]).

Since the range of each channel is only two values, you need to reduce the 8-bit encoding to a 1 bit encoding. To do this, divide by half of the maximum value in an eight bit encoding (255 / 2 = 127)

You can use integer division for the conversion of each RGB compenent:

3 bit R : (8-bit Red Value) / 127
      G : (8-bit Green Value) / 127 
      B : (8-bit Blue Value) / 127 

Example:

3 bit R : (56) / 127 = 0
      G : (225) / 127 = 1
      B : (127) / 127 = 1
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top