Decision
color=$( convert filename.png -format "%[pixel:p{0,0}]" info:- ) convert filename.png -alpha off -bordercolor $color -border 1 \ \( +clone -fuzz 30% -fill none -floodfill +0+0 $color \ -alpha extract -geometry 200% -blur 0x0.5 \ -morphology erode square:1 -geometry 50% \) \ -compose CopyOpacity -composite -shave 1 outputfilename.png
Explanation
It is a little longer than simple answers, but it gives better results. : (1) The quality is superior to smooth alpha, and (2) only the background is removed as against the same color. (A "background" is defined as approximately the same color as the top left pixel, using a fill from the edge of the image.)
In addition, the alpha channel is also destroyed by half a pixel to avoid the halo. Of course, ImageMagick's morphological operations (yet?) Work at the subpixel level, so you can see that I inflate the alpha channel to 200% before blurring.
Comparison of Results
Here is a comparison of a simple approach ("-fuzz 2% -transparent white") compared to my solution when the ImageMagick logo . I flattened both transparent images onto a saddle brown background to make differences in the differences (click for originals).

Note that the beard of the master has disappeared in a simple approach. Compare the faces of the wizard to see how smooth alpha helps smoothly move in the background.
Of course, I fully admit that there are times when you might want to use a simpler solution. (For example: itβs a lot easier to remember, and if you convert to GIF, you are limited to 1-bit alpha anyway.)
mktrans shell script
Since it is unlikely you will need to re-type this command, I recommend wrapping it in a script. You can download the BASH script shell from github , which executes my proposed solution. It can run on multiple files in and contains useful comments if you want to customize things.
bg_removal script
By the way, ImageMagick actually comes with a script called "bg_removal" which uses the fill in the same way as my solution. However, the results are small because it still uses 1-bit alpha. Also, the bg_removal script is slower and a bit more difficult to use (it requires you to specify two different fuzz values). Here is an example of output from bg_removal.

hackerb9 Jun 14 '17 at 10:57 2017-06-14 10:57
source share