Is It Possible To Mask An Image In Python Imaging Library (pil)?
I have some traffic camera images, and I want to extract only the pixels on the road. I have used remote sensing software before where one could specify an operation like img1 * i
Solution 1:
The Image.composite
method can do what you want. The first image should be a constant value representing the masked-off areas, and the second should be the original image - the third is the mask.
Solution 2:
You can use the PIL library to mask the images. Add in the alpha parameter to img2, As you can't just paste this image over img1. Otherwise, you won't see what is underneath, you need to add an alpha value.
img2.putalpha(128)
#if you put 0 it will be completly transparent, keep image opaque
Then you can mask both the images
img1.paste(im=img2, box=(0, 0), mask=img2)
Post a Comment for "Is It Possible To Mask An Image In Python Imaging Library (pil)?"