8

I've multiple PNG image files, one per channel: red, green, blue and yellow.

How I could merge them into one RBGA image?

So far I tried the following

from PIL import Image

red    = Image.open('red.png')
green  = Image.open('green.png')
blue   = Image.open('blue.png')
yellow = Image.open('yellow.png')
rgb = Image.new('RGB', (blue.width, blue.height))
for im in [red, green, blue, yellow]:
    rgb.paste(im, (0, 0))
rgb

Obviously it's not working as I'm just overriding the previous image. Any ideas?

Update: thanks to the comments bellow it turns out I can merge the red, green and blue files with:

rgb = Image.merge("RGB",(red,green,blue))

This is gives something like the follwing result: enter image description here

The question now is how I could use the yellow file?

bachr
  • 5,780
  • 12
  • 57
  • 92
  • 1
    Maybe this could help https://stackoverflow.com/questions/10443295/combine-3-separate-numpy-arrays-to-an-rgb-image-in-python – Shai Léger Oct 14 '18 at 21:09
  • 1
    Or this one https://gis.stackexchange.com/questions/180534/merge-rgb-band-using-python – Shai Léger Oct 14 '18 at 21:10
  • 1
    You're aware that yellow is a combination of red and green in the RGB colorspace, right? How should those two components be added to the RGB image being created? What should happen if the total of one of those color components exceeds (also called over-flows) the maximum allowed value it can have? – martineau Oct 14 '18 at 21:18
  • @martineau first thanks, I completely missed that yellow is red+green. I have the four files red, green, blue, yellow that's been given, I was just trying to visualize them. – bachr Oct 14 '18 at 21:25
  • It's possible to combine them, you just need to define what you want to happen when a red or green component from the yellow image is added to the corresponding component of the image being built and the sum overflows the maximum component value. – martineau Oct 14 '18 at 21:30
  • @martineau I uploaded the result when using the red, green, and blue. Can you suggest a way to combine this with yellow to soften the image? – bachr Oct 14 '18 at 21:34
  • _Soften_ the image? Please define that better, preferably mathematically in terms of RGB components. – martineau Oct 14 '18 at 21:40
  • You may want to look at this: https://personalpages.manchester.ac.uk/staff/d.h.foster/Research/My_PDFs/Foster_Amano_JOSAA_19.pdf – Sandipan Dey May 01 '19 at 06:58

0 Answers0