【问题标题】:How to convert this ImageMagick command for white background removal to Python Wand module?如何将此用于去除白色背景的 ImageMagick 命令转换为 Python Wand 模块?
【发布时间】:2022-01-26 21:19:51
【问题描述】:

我指的是@fmw42 和他出色的 ImageMagic 命令,可以将白色背景变为透明背景。我修改了他的原始命令以使用最新版本的 ImageMagick。

magick test_imagemagick.jpg -fuzz 25% -fill none -draw "alpha 0,0 floodfill" -channel alpha -blur 0x1 -level 50x100% +channel  result.png

这在命令行上很棒,但我很难理解如何在 Python Wand 中实现它。

这是我到目前为止所拥有的,这并不多,因为我不知道如何映射两个文档中的信息。s

with Image(filename= 'test_imagemagick.jpg') as img:
   img.fuzz = 0.25 * QUANTUM_RANGE  # 25%
   img.fill_color = 'transparent'

【问题讨论】:

    标签: python imagemagick wand


    【解决方案1】:

    在 Python/Wand 中试试这个命令:

    from wand.image import Image
    from wand.drawing import Drawing
    from wand.color import Color
    from wand.display import display
    
    with Image(filename='logo:') as img:
        with img.clone() as copied:
            copied.fuzz = 0.25 * img.quantum_range
            with Drawing() as draw:
                draw.fill_color = Color('transparent')
                draw.matte(x=0.0, y=0.0, paint_method='floodfill')
                draw(copied)
            copied.alpha_channel = 'extract'
            copied.blur(radius=0.0, sigma=2)
            copied.level(black=0.5, white=1, gamma=1.0)
            img.composite(copied, left=0, top=0, operator='copy_opacity')
            img.format='png'
            display(img)
            img.save(filename='logo_transparent_antialiased.png')
    

    【讨论】:

      猜你喜欢
      • 2015-02-18
      • 2023-03-25
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      相关资源
      最近更新 更多