【发布时间】:2021-01-25 12:59:37
【问题描述】:
如何将灰度图像转换为具有可定义阈值的 1 位黑/白,但保持现有透明度/alpha?
现有问题错过了我问题的透明度部分。
另外,我需要在 macOS 的命令行上执行此操作。 ImageMagick 的convert 是一种选择,但不是唯一选择。
要求的行为:
- 低于可定义阈值的像素为黑色
- 高于可定义阈值的像素为白色
- 透明像素保持不变
我手动准备了这个“目标”图像:
我尝试过的:
-
$ 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
【问题讨论】:
标签: command-line graphics imagemagick-convert