使用Python Wand图像合成结果不正确的问题

2024-04-25 08:00:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我有3个图像需要合成在一起,但结果剂量从后效合成原始结果不一样。在后效中,我需要用32位的图像深度来做一些合成,我尝试了ImageMagick,结果是正确的,我可以用批处理命令来做,但是我需要做的层很大,处理时间也很长,然后我用python棒来做,我想我可以加快时间,但是我坚持这个,复合计算看起来都是负值。你知道吗

如何使用魔杖或其他库获得正确的结果?我也试过PythonMagick和pgmagick,但结果也是这样。谢谢

我使用的是Wand 0.5.1,ImageMagick版本是ImageMagick-7.0.8-Q16-HDRI(64位)

以下是我的代码和示例:

from wand import image as wi
from wand import api 

img = wi.Image()
img.read(filename='D:\\0225_red.jpg')
img.convert('TIFF')
img.depth=24
api.library.MagickSetOption(img.wand,'quantum:format','floating-point')
api.library.MagickSetOption(img.wand,'compose:clamp','off')

img2=wi.Image()
img2.read(filename='D:\\0225_pink.jpg')
img2.convert('TIFF')
img2.depth=24
api.library.MagickSetOption(img2.wand,'quantum:format','floating-point')
api.library.MagickSetOption(img2.wand,'compose:clamp','off')

img3=wi.Image()
img3.read(filename='D:\\0225_blue.jpg')
img3.depth=24
api.library.MagickSetOption(img3.wand,'quantum:format','floating-point')
api.library.MagickSetOption(img3.wand,'compose:clamp','off')

img.composite_channel('all_channels',img2 , 'minus_src')
img.composite_channel('all_channels',img3 , 'plus')
img.format = 'TIFF'
img.save(filename='D:\\0225_test.tif')

AE结果:

enter image description here

我的代码的结果:

enter image description here


Tags: imageapiformatimgreadlibrarywandfilename
1条回答
网友
1楼 · 发布于 2024-04-25 08:00:23

我怀疑这个问题与行动顺序有关。请尝试以下操作。。。你知道吗

from wand.image import Image

with Image(filename='D:\\0225_red.jpg') as img:
    img.options['quantum:format'] = 'floating-point'
    img.options['compose:clamp'] = 'off'
    with Image(filename='D:\\0225_blue.jpg') as blue:
        img.composite_channel('all_channels', blue, 'plus')
    with Image(filename='D:\\0225_pink.jpg') as pink:
        img.composite_channel('all_channels', pink, 'minus_src')
    img.save(filename='D:\\0225_test.tif')

相关问题 更多 >