Remove Solid Color Background

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
pogonomic
Posts: 3
Joined: 2018-05-09T15:28:21-07:00
Authentication code: 1152

Remove Solid Color Background

Post by pogonomic »

Need to sap the pink out of an image but the pink comes in variants. e.g. #F700F8 #F800F7 #F700FF #FF00FF, etc

Base command: magick convert bear.png -transparent #F800F7 bear2.png

I've also tried -fuzz (1-100% and massive integers), -trim, and -transparent-color but still comes out with spotted background.
Any help is appreciated. Using the latest version.

Original:
Image
Result:
Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove Solid Color Background

Post by snibgo »

Please say what version of IM you use, on what platform.

For v7, I suggest you use "magick" not "magick convert".

For me, v7.0.7-28 on Windows 8.1, this works fine:

Code: Select all

magick k2svX7r.png -fuzz 5% -transparent #F800F7 out.png
If you are using Windows BAT, don't forget to double the %.
snibgo's IM pages: im.snibgo.com
pogonomic
Posts: 3
Joined: 2018-05-09T15:28:21-07:00
Authentication code: 1152

Re: Remove Solid Color Background

Post by pogonomic »

Ah perfect, that did work. Thank you!

v7.0.7-31-Q16-x64; Win 7 Pro 64

Any suggestions on skimming that last little pink edge?

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove Solid Color Background

Post by fmw42 »

Either increase the fuzz value or extract the alpha channel after using the -fuzz command and antialias it with a blur.

For the latter, you can try the following

Code: Select all

magick k2svX7r.png -fuzz 5% -transparent #F800F7 -channel alpha -blur 0x2 -level 50x100% +channel output.png
If in a bat file, you need to double the % to %%
pogonomic
Posts: 3
Joined: 2018-05-09T15:28:21-07:00
Authentication code: 1152

Re: Remove Solid Color Background

Post by pogonomic »

Thank you very much! :]
Post Reply