Page 1 of 1

Making semi-transparent white pixels in an image all a single color

Posted: 2018-10-18T09:03:44-07:00
by nihilazo
Hello, I have some images like these ones:
Image
Image

I would like to make the figures on the images (which are currently semi-transparent) be totally opaque, and go from the greyish color they are to being totally white (#ffffff). How would I go about this using convert? All of the images also have these different amounts of alpha on the figures, so I can't do a blind one-color-for-another replace.

Re: Making semi-transparent white pixels in an image all a single color

Posted: 2018-10-18T10:53:25-07:00
by GeeMack
nihilazo wrote: 2018-10-18T09:03:44-07:00I would like to make the figures on the images (which are currently semi-transparent) be totally opaque, and go from the greyish color they are to being totally white (#ffffff). How would I go about this using convert? All of the images also have these different amounts of alpha on the figures, so I can't do a blind one-color-for-another replace.
There are probably a few good ways to do this. My first thought was to threshold the alpha channel, and fill the positive with white. A command like this gets me pretty close to what you described...

Code: Select all

convert input.png -channel A -threshold 10% -channel RGB -fill white -colorize 100 output.png
You might be able to tweak the threshold percentage so it accommodates the range of alpha in your various images.

Re: Making semi-transparent white pixels in an image all a single color

Posted: 2018-10-18T11:20:05-07:00
by fmw42
Your alpha channel is the same as your base image. You can see that from comparing the results of

convert test.png -alpha off aoff.png
Image


convert test.png -alpha extract alpha.png
Image



My thought was to make the base image pure white and then threshold the alpha channel.

Image

Code: Select all

convert test.png -channel rgb -evaluate set 100% +channel -channel a -threshold 50% +channel test1.png
Image

Looking at GeeMack's solution, it appears to be similar but in the reverse order.

I thresholded the alpha channel more, so that the black lines in the image showed as transparency. If you do not want those outlines, then threshold at 0% (as user snibgo suggested below).

Re: Making semi-transparent white pixels in an image all a single color

Posted: 2018-10-18T11:21:22-07:00
by snibgo
As GeeMack says. To change "partially transparent" to "fully opaque", while leaving fully transparent unchanged, use "-threshold 0".

Re: Making semi-transparent white pixels in an image all a single color

Posted: 2018-10-19T12:47:36-07:00
by nihilazo
Thank you everyone! This works perfectly.