0

I want to power an E-Ink Display, and for that, I need 2-bit images. I am currently using Pillow to create an image and save it, but the options are only 1-bit and 8-bit for B&W / grayscale images:

from PIL import Image

im1 = Image.new('1', (600, 800), color=1)
# creates 1-bit image, background color options range from 0 to 1, black and white

im2 = Image.new('1', (600, 800), color=123)
# creates 8-bit image, background color options range from 0 to 255, grayscale

Can I create/save 2-bit images? Or alternatively, is there some way to convert them afterwards?

I am aware of this post: converting images to indexed 2-bit grayscale BMP. I wonder whether there is a more efficient way.

martineau
  • 119,623
  • 25
  • 170
  • 301
josh
  • 9
  • 1
  • 3
  • Does this answer your question? [converting images to indexed 2-bit grayscale BMP](https://stackoverflow.com/questions/35797988/converting-images-to-indexed-2-bit-grayscale-bmp) – Alderven Sep 10 '20 at 09:22
  • @Alderven yes, kinda! Thank you! I was just wondering, wether there is a more efficient way. – josh Sep 10 '20 at 09:29

1 Answers1

0

You have several options:

  • storing two 1bpp images instead of one and merging/splitting when necessary;

  • packing/unpacking four 2b pixels in a 8b one;

  • using image format with native 2bpp support (I guess TIFF and GIF do but unsure if they pack appropriately); you might need to integrate the original libraries;

  • if you are willing to program it yourself, a more compact solution could be with run-length encoding of the 4bpp data (unless the images are noisy or dithered, there will be long runs of constant value), and an ad-hoc file format.

The first option has the advantage that you can visualize the images with standard tools (but imagine the combination).

  • Thank you so much! I will try these options, I think the first one will be good for my application. Thank you! – josh Sep 10 '20 at 12:04