command-line - 将灰度图像转换为具有可定义阈值的 1 位黑/白,保持透明度?
问题描述
如何将灰度图像转换为具有可定义阈值的 1 位黑/白,但保持现有的透明度/alpha?
现有问题错过了我问题的透明度部分。
另外,我需要在 macOS 的命令行上执行此操作。ImageMagickconvert
是一种选择,但不是唯一的选择。
要求的行为:
- 低于可定义阈值的像素为黑色
- 高于可定义阈值的像素为白色
- 透明像素保持不变
我手动准备了这个“目标”图像:
我试过的:
$ convert -threshold 50% in.png out.png
- 超过阈值的所有东西都变成白色
- 低于阈值的一切都变得透明!
$ convert -white-threshold 50% in.png out.png
- 超过阈值的所有东西都变成白色
- 低于阈值的一切都变得透明!
$ convert -black-threshold 50% in.png out.png
- 超过不同阈值的所有东西都变成白色
- 什么都不会变黑!
$ convert +dither -monochrome in.png out.png
- 抖动禁用
- 1 位转换锁定到 50%,但按预期执行
- 但是:透明像素变黑了!
$ convert -depth 1 -colors 3 -alpha set in.png out.png
- 差不多好了
- 但是:阈值无法定义!
任何想法表示赞赏!
图片参考: http: //www.studentshow.com/gallery/6097929/Pyramid-Module-Value-Grayscale
解决方案
推荐阅读
- javascript - 没有得到 Radio input Javascript 的值
- java - 如何将带有用户名和密码的代理添加到 Jsoup?
- makefile - 使用 makefile 编译 petsc 包含的代码,“.f90”失败,但“.F90”通过
- c++ - 嵌套类的成员没有被构造函数初始化
- windows - 为什么 Process Explorer 需要调试符号来显示内核内存限制?
- asp.net-mvc - ASP.NET MVC - 添加到视图模型列表并提交
- c# - 在 C# 中基于复选框选择(自定义活动开发)验证输入字段
- delphi - 试图让 Webauthn 运行
- python - 如何在 Python 中为水平条形图绘制百分比标签?
- c++ - 如何使用 mongocxx/bsoncxx 驱动程序 (C++) 将 JPEG / PDF 文件上传到 mongodb