On 30/03/2008, Gokce Taskan <[EMAIL PROTECTED]> wrote: > I've been searching all over the internet for a method to convert an > image to a 8 color (3-bit) image. I've used these: > I am trying find a method to output a resonable image which would look > like the one in > http://en.wikipedia.org/wiki/List_of_monochrome_and_RGB_palettes#3-bit_RGB > > Do you have any advices?
To convert a 24-bit RGB image to a 3-bit one, just take the top bit from each channel and OR them together. In C: bit3 = ((r & 128) >> 5) | ((g & 128) >> 6) | ((b & 128) >> 7) You can make it look much better with a dither. A 2D error diffusion dither is fast and works well. To convert back to 24-bit RGB (again, in C): unsigned char lut[2] = {0, 255} r = lut[(bit3 & 4) >> 2] g = lut[(bit3 & 2) >> 1] b = lut[bit3 & 1] John _______________________________________________ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig