python - 将 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, 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 可以进一步评论。
推荐阅读
- vue.js - v-on:click 永远不会触发 Nuxt 组件中的按钮,因为中间件
- emulation - 需要不良的编码习惯
- javascript - 如何解决:EEXIST:文件已存在,在 React Native 中生成 apk 后 mkdir 'C:\Users\OKR\Desktop\MeetUp' 失败?
- python - 获取大于值的索引并保持值
- javascript - 基于变量在条形刻度上绘制一个点
- azure - 在 Azure SQL 数据流任务中从 JSON 映射列
- nativescript-angular - 如何在 Playground online 中包含 Localize 模块
- python - Python - 如何按执行顺序将独特函数与共享结果并行化?
- wordpress - 如何阻止带有 nginx 和 apache 的 varnish 上的 wordpress 网站通过 http 加载?
- debugging - WebStorm 调试器无法启动服务器?