imagemagickalphamonochrome

ImageMagick - rounding the alpha channel


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?


Solution

  • 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
    

    enter image description here

    enter image description here