I have an image which is white on a transparent background, but the white has some alpha channel around the object's edges (due to anti-aliasing). How could I make this pure white-on-transparent, by rounding the alpha channel so > 0.5 becomes white and <= 0.5 becomes transparent?
Asked
Active
Viewed 396 times
1 Answers
2
You need to threshold the alpha (transparency) channel at 50% thereby forcing all transparencies under 50% to zero and transparencies over 50% to 100%. Like this:
convert image.png -channel alpha -threshold 50% out.png

mahemoff
- 44,526
- 36
- 160
- 222

Mark Setchell
- 191,897
- 31
- 273
- 432
-
Thanks, this worked fine, and actually more useful than just rounding as I can tweak the %ge figure. – mahemoff Oct 17 '14 at 08:48
-
1Excellent - I love it when a plan comes together. By the way, if you need to tweak, and want finer granularity, you can remove the percent sign and use a value between 0-65535, so `-threshold 32768` would be equivalent to 50%. I am assuming you have a 16-bit quantisation ImageMagick - i.e. Q16. – Mark Setchell Oct 17 '14 at 09:04