简体   繁体   English

Python Wand将tiff更改为min-is-white

[英]Python Wand change tiff to min-is-white

I need to convert files to tiff where photometric is set "min-is-white" (white is zero) to comply with the required standards. 我需要将文件转换为tiff,其中光度计设置为“min-is-white”(白色为零)以符合所需标准。 I'm using Wand to interact with Photomagick but every I save a bilevel tiff file, it creates a min-is-black. 我正在使用Wand与Photomagick进行交互,但每次我保存一个双层tiff文件,它会创建一个min-is-black。

How can I get Wand to saves it where White is Zero? 如何将魔杖保存在白色为零的地方? Is it even possible? 它甚至可能吗?

Mark's comments are correct. 马克的评论是正确的。 You need to set the -define property for ImageMagick. 您需要为ImageMagick设置-define属性。

For , you'll have to extent the core wand.api.library to connect MagickWand's C-API MagickSetOption method. 对于 ,你必须扩展核心wand.api.library以连接wand.api.library的C-API MagickSetOption方法。

from ctypes import c_void_p, c_char_p
from wand.api import library
from wand.image import Image

# Tell python about the MagickSetOption method
library.MagickSetOption.argtypes = [c_void_p,  # MagickWand * wand
                                    c_char_p,  # const char * option
                                    c_char_p]  # const char * value

# Read source image
with Image(filename="/path/to/source.tiff") as image:
    # -define quantum:polarity=min-is-white
    library.MagickSetOption(image.wand,          # MagickWand
                            "quantum:polarity",  # option
                            "min-is-white")      # value
    # Write min-is-white image
    image.save(filename="/path/to/min-is-white.tiff")

You can verify the resulting image with the identify utility. 您可以使用identify实用程序验证生成的图像。

identify -verbose /path/to/min-is-white.tiff | grep photometric
#=> tiff:photometric: min-is-white

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM