I need to save a tiff image with 4 channels, specifically R,G,B and A channels.
When I try using Image.save()
to save a tiff with 4 channels, the resulting image is an RGBA image but when examining the tiff in Photoshop the only channels are RGB, without the Alpha. Is there any way to merge 4 channels to a RGBA image, with a 4th channel (a separate alpha channel)?
Below is an example of what I’ve tried
from PIL import Image
# import image A
inputImageA = Image.open(input_imageA_path)
# import image B
inputImageB = Image.open(input_imageB_path)
# split channels
R, G, B, A = inputImageA.split()
alpha_channel = inputImageA.split()[-1]
# merge 4 channels back into a single image
outputImage = Image.merge("RGBA", [R,G,B,alpha_channel])
# save the new image
outputImage.save(ouput_image_path)
In this example the resulting output image only has 3 channels (RGB).
Please see below image for a visual explanation of what I’m trying to do:
2
Answers
I figured out a solution to this issue using the OpenCV2 library instead of PIL. See below how I did it:
Updated Answer
Ok, I think you mean this now:
Which makes
start.png
:plus
alpha.png
:into
result.tif
:Original Answer
Here’s a simple example of creating and saving a 4 channel, RGBA TIFF: