簡體   English   中英

將 ImageMagick 命令轉換為 Wand Python

[英]Convert ImageMagick command to Wand Python

我想知道如何使用 Wand 庫將此工作命令行序列從 ImageMagick 轉換為 Python 腳本:

/usr/local/bin/convert pic.png -alpha off +dither -colors 2 -colorspace gray -normalize -statistic median 1x200 -negate -format "%[fx:mean*w*h]" info:

我當前的 Python 代碼是:

with Image(filename= 'pic.png') as img:
    with img.clone() as img_copy1:
        img_copy1.alpha_channel = False
        img_copy1.quantize(number_colors= 2, colorspace_type='gray', dither= True)
        img_copy1.normalize()
        img_copy1.negate(grayscale= True)

但我仍然不知道如何計算作為垂直特征一部分的像素數......

更新:

感謝@fmw42,我修改了我的代碼

with wand.image.Image(filename='pic.png') as img:
    with img.clone() as img_copy1:
        img_copy1.alpha_channel = False
        img_copy1.quantize(number_colors= 2, colorspace_type='gray', dither= True)
        img_copy1.normalize()
        img_copy1.statistic("median", width = 1, height = 200)
        img_copy1.negate()
        img.options['format'] = '%[fx:mean*w*h]'
        print(img.make_blob('INFO'))

這是我從 Eric McConville(Wand 開發人員)那里得到的一個例子,用於進行 fx: 計算。 這應該給你一個線索如何做你的。

from wand.image import Image
with Image(filename='zelda.png') as img:
  img.options['format'] = '%wx%h'
  print(img.make_blob('INFO'))

如果現在有更好的方法,Eric 可以進一步評論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM