Reputation: 4122
How can I convert a greyscale image to 1-bit black/white with definable threshold, but maintaining existing transparency/alpha?
Existing questions miss out the transparency part of my question.
Also, I need to do this on the command-line in macOS. ImageMagick's convert
is one option, but not the only option.
Required behaviour:
I prepared this "goal" image manually:
What I have tried:
$ 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
$ convert -depth 1 -colors 3 -alpha set in.png out.png
Any thoughts appreciated!
Image Ref: http://www.studentshow.com/gallery/6097929/Pyramid-Module-Value-Grayscale
Upvotes: 4
Views: 2814
Reputation: 53081
This works for me on IM 6.9.11.34 Q16 Mac OSX Sierra.
convert in.png -colorspace gray -channel rgb -threshold 50% +channel out.png
(In the above, you specify that the threshold should be applied only to the rgb channels and not the alpha via -channel rgb. After the threshold, I turn on all the channels again)
Upvotes: 6