I am trying to create images with 10-bit/color (Bit Depth) using Image module. I wrote the following snippet, but resulting in 8-bit/color:
from PIL import Image
im = Image.new("RGBA", (256, 256))
pix = im.load()
for y in range(256):
for x in range(256):
pix[x, y] = (1023, 1023, 1023, 255)
im.show()
im.save("10bit.jpg")
While image successfully writes the new file, it still encoded as an 8-bit channel:
$ exiftool 10bit.png
Bit Depth : 8
$ file 10bit.png
10bit.png: PNG image data, 256 x 256, 8-bit/color RGBA, non-interlaced
My goal here to write Deep color (40-bit) images:
Deep color consists of a billion or more colors.[15] 230 is 1,073,741,824. Usually this is 10 bits each of red, green, and blue (10 bpc). If an alpha channel of the same size is added then each pixel takes 40 bits.
What I am missing here? Is there another way to create 10-bit alpha-channeled images? (opencv, etc.)
CodePudding user response:
You can't do that with PIL/Pillow
. The available modes are described here and there are no RGB modes with more than 8-bits per pixel.
I would suggest you use Numpy
with HxWx3
channels of np.uint16
to create your images and process them with scikit-image
, or OpenCV or wand, like this:
import numpy as np
# Crete empire black image
image = np.zeros((H,W,3), np.uint16)
You don't say explicitly what format you want to write the results in. If you clarify that, maybe I (or somebody else) can suggest a Python library.