Skip to content
Advertisement

Tag: python-imaging-library

Speeding up applying mapping to an image

I’m trying to convert an RGB to a gray-value image of the same size (with values between 0 and 1). The mapping is done by a dictionary called MASK_LUT_IDX which takes in a tuple (RGB) and returns the corresponding value. The current code is 2x faster than before, but still takes 1.5s (according to timeit), which is proving to be

How to create overlapping semitransparent shapes on semitransparent background with PIL

I’m trying to create image with semitransparent shapes drawn on transparent background. For some reason instead of staying transparent, the shapes are completely covering those beneath them. My code: I would expect the result to look something like (except for background not being transparent):but it looks like: When I try to save it as GIF with img.save(“foo.gif”, “gif”), result is

What is the difference between images in ‘P’ and ‘L’ mode in PIL?

According to https://pillow.readthedocs.io/en/3.1.x/handbook/concepts.html#concept-modes, What are the difference between them? Can we convert from one to another? What are the examples of image for both mode? Answer Normally, images are RGB, which means they have 3 channels, one for red, one for green and one for blue. That normally means that each pixel takes 3 bytes of storage, one for red,

Faster bit-level data packing

An 256*64 pixel OLED display connected to Raspberry Pi (Zero W) has 4 bit greyscale pixel data packed into a byte (i.e. two pixels per byte), so 8192 bytes in total. E.g. the bytes become Converting these bytes either obtained from a Pillow (PIL) Image or a cairo ImageSurface takes up to 0.9 s when naively iterating the pixel data,

Advertisement