Answer the question
In order to leave comments, you need to log in
How to make Pillow.Image.alpha_composite logic run on GPU?
Hey!
In the Pillow library, the Image class has a wonderful function - alpha_composite. If she slips two Images in the RGBA profile, then she will glue the two images very correctly, namely:
1. If both images had transparent areas, then the resulting image will also be transparent.
2. If the one that is placed on top has a translucent area, then the one below will correctly "shine through" through the top
3. If it is opaque on top, then it ignores the underlying pixels.
The problem is that she does it rather slowly. I ran in multiprocessing on all cores, but it seems that this is the limit for the CPU, even Pillow-SIMD does not give a noticeable gain.
So I turned my attention to the GPU. But then another problem arose - no other library that I tried has a mode in which Pillow.Image.alpha_composite works - or I did not figure it out. OpenCV in all modes in which I tried and according to all the advice from SO does not do what is needed - the transparent pixels of the upper image are either not taken into account, or black is replaced with a transparent color in the image itself. pyVips in Image.composite mode does the same as OpenCV.
Can you please tell me how to glue images like Pillow.Image.alpha_composite on GPU? Maybe not even in Python.
Answer the question
In order to leave comments, you need to log in
even Pillow-SIMD does not give a noticeable gain
$ pip uninstall pillow
$ CC="cc -mavx2" pip install -U --force-reinstall pillow-simd
im.save('png.png', compress_level=1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question