Reputation: 61
Lets say I want to take my RGB image and swap its green channel completely for, say the blue channel of another image. What would be the best way to go about that? My first thought was it would live in ImageChops, but that seems to be all-channel compositing functions.
Upvotes: 2
Views: 3823
Reputation: 61
Coworker found it. Getalpha and putalpha are too specific as I need the other channels. Image.getdata and Image.merge were what I ended up needing (well, I actually baked down a couple full images to "L" before merging)
Example in case anyone has the same question later:
R, G, B= im.getdata(0), im.getdata(1), im.getdata(2)
newImage = Image.merge("RGB", [R,G,B])
The code I used that baked down to one channel first:
specChannel = Image.open(os.path.join(self.info['stagingFolder'], "specular.png")).convert("L")
glossChannel = Image.open(os.path.join(self.info['stagingFolder'], "gloss.png")).convert("L")
BlankIm = Image.new("L", (512,512), (255))
mask2Im = Image.merge("RGBA", [specChannel,BlankIm,BlankIm,glossChannel])
Upvotes: 4