0

I would like to write the Wand equivalent of:

composite -stereo 0 right.tif left.tif output.tif

I think the 0 is an x-axis offset and is probably not be relevant. I have bodged together some bits and pieces from other posts and the result is good, but it's a bit long-winded. Is this the best that can be done?

#! /usr/bin/python
from wand.image import Image
from wand.color import Color

# overlay left image with red
with Image(filename='picture1.tif') as image:
    with Image(background=Color('red'), width=image.width, height=image.height) as screen:
        image.composite_channel(channel='all_channels', image=screen, operator='multiply')
    image.save(filename='picture1red.tif')

# overlay right image with cyan
with Image(filename='picture2.tif') as image:
    with Image(background=Color('cyan'), width=image.width, height=image.height) as screen:
        image.composite_channel(channel='all_channels', image=screen, operator='multiply')
    image.save(filename='picture2cyan.tif')

# overlay left and right images
with Image(filename='picture1red.tif') as image:
    with Image(filename='picture2cyan.tif') as screen:
        image.composite_channel(channel='all_channels', image=screen, operator='add')
    image.save(filename='3Dpicture.tif')

1 Answers1

0

You have the right approach for creating a new image with red (left) & cyan (right) channels. However the multiply and add composite operators on all_channels is not needed. If we argue that cyan = green + blue; we can simplify your example.

with Image(filename='picture1.tif') as left:
    with Image(filename='picture2.tif') as right:
        with Image(width=left.width, height=left.height) as new_image:
            # Copy left image's red channel to new image
            new_image.composite_channel('red', left, 'copy_red', 0, 0)
            # Copy right image's green & blue channel to new image
            new_image.composite_channel('green', right, 'copy_green', 0, 0)
            new_image.composite_channel('blue', right, 'copy_blue', 0, 0)
            new_image.save(filename='3Dpciture.tif'))
emcconville
  • 23,800
  • 4
  • 50
  • 66
  • The last ')' needs removing. I thought it must be possible, thanks! Your code is much slicker than mine, and it will save me having to worry about managing the intermediate files that mine created. –  Apr 19 '15 at 18:59