How to remove semitransparent pixels

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Wolfgange
Posts: 2
Joined: 2015-06-03T15:23:09-07:00
Authentication code: 6789

How to remove semitransparent pixels

Post by Wolfgange »

I would like to remove pixels with less than ~20 opacity, and "Anti-erase" anything else. (I'm not quite sure of the technical name for it, but what I mean by "Anti-erase" is to make the pixel the same color with no transparency).

I've already tried this:

Code: Select all

convert -alpha off input.png miff:- | convert -transparent white - miff:- | convert -transparent black - output.png
But the problem is, I'm left with random pixels that were really transparent, now completely shown, and the pure white and black of the image is now transparent. Is there a way I can achieve the results I want? Here is a sample image input and output:
Image
Wolfgange
Posts: 2
Joined: 2015-06-03T15:23:09-07:00
Authentication code: 6789

Re: How to remove semitransparent pixels

Post by Wolfgange »

I've solved my problem. By converting to gif and back, the semitransparent pixels are automatically either removed or "Anti-erased". Thus, this works perfectly:

Code: Select all

convert input.png gif:- | convert - output.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to remove semitransparent pixels

Post by fmw42 »

It would have been nice if you had provided the source image by itself. So, I cropped it out and called it Example2.png. The following seems to work for me.

Code: Select all

convert Example2.png -channel alpha -threshold 20% +channel NewExample2.png
In the future, please always provide your version of Imagemagick and your platform. Syntax may be different on Windows than Unix systems.
Post Reply