I have three RGB images, but each one has only 1 non-zero channel (ie. one has a red channel with 0's in the blue and green channels) and I want to combine them into a single RGB image with the correct channel from each.
I apologise for my phrasing, I don't know much of the terminology (which really isn't helping my search queries)
I think you can use Image.merge
here and take the appropriate channels from each image. Note that I'm using requests.get(...)
and BytesIO
here to pull down from the linked images but you can just use Image.open(...)
directly on the filename instead if you have them locally.
from io import BytesIO
from PIL import Image
import requests
red = Image.open(BytesIO(requests.get('https://i.stack.imgur.com/EKQW4.jpg').content))
green = Image.open(BytesIO(requests.get('https://i.stack.imgur.com/Xel7l.jpg').content))
blue = Image.open(BytesIO(requests.get('https://i.stack.imgur.com/vyrqR.jpg').content))
combined = Image.merge('RGB', (red.getchannel('R'), green.getchannel('G'), blue.getchannel('B'))
combined.save('output_image_name.jpg')
And that'll give you something like:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.