如何解决将 ImageMagick 命令转换为 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,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 可以进一步评论。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。