2015-03-03 48 views
0

的,我想写出魔杖相当于:棒相当于复合-stereo

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

我认为0是x轴偏移和可能是不相关的。我已经把其他帖子中的一些小部分联系在一起,结果很好,但是有点冗长。这是可以做到的最好的吗?

#! /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

您有正确的方法用红色(左)&青色(右)通道创建新图像。但all_channels上的multiplyadd复合运营商是不需要的。如果我们认为cyan = green + blue;我们可以简化你的例子。

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')) 
+0

最后的')'需要删除。我认为这一定是可能的,谢谢!你的代码比我的更冷静,它可以让我不用担心管理我创建的中间文件。 – ChrisOfBristol 2015-04-19 18:59:02