Select Similar Colors and make transparent

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
kamdeng

Select Similar Colors and make transparent

Post by kamdeng » 2006-07-21T18:15:41-07:00

Hello ImageMagick Users,

I am a first time ImageMagick user and a first time poster on these forums.

Anyway, I'm not sure if this has been asked or answered yet, but I had a hard time finding a solution that worked.

My problem is I need to bulk edit about 20,000 images. The source images are JPGs. They have an image in the center with a white background. I need to change the white background into a transparent background either in GIF or PNG format. PNG is preferred because of the way it handles transparency. The destination is Flash, so the IE PNG bug is not a big deal.

Here is an example of what I need done (I did this in a GUI graphics editor)

Original JPG File
Image

GIF with Transparency
Image

PNG with Transparency
Image

I did find a solution which I believe is the answer, but it did not work for me.
http://studio.imagemagick.org/discussio ... php?t=6091

I tried using the suggested command:

Code: Select all

 convert image.jpg -fill none -draw 'color 0,0 floodfill' output.gif
I also tried with a -fuzz 50% option, but that did not help.

This is the output of

Code: Select all

 convert image.jpg -transparent #FFFFFF -fuzz 50% image.gif
Image

Close, but obviously, not what I am looking for. Any ideas? Thanks in advance.

User avatar
magick
Site Admin
Posts: 11042
Joined: 2003-05-31T11:32:55-07:00

Post by magick » 2006-07-21T18:58:09-07:00

We're using ImageMagick 6.2.8-5 with this command to return expected results:
  • convert image.jpg -fuzz 10% -transparent white image.gif

kamdeng

Post by kamdeng » 2006-07-22T08:30:44-07:00

magick wrote: We're using ImageMagick 6.2.8-5 with this command to return expected results:
  • convert image.jpg -fuzz 10% -transparent white image.gif


That did work. Thanks for the help.

However, here is the new issue. There are some images among the 20,000 that are like the image below:

Original JPG
Image

GIF with Transparency after command
Image

The content inside the J is actually white color that I would like to keep, but the command above is removing that white color and making it transparent. I would actually like to only remove the white that is contiguous on the outside background. Is there anyway that this is possible?

User avatar
magick
Site Admin
Posts: 11042
Joined: 2003-05-31T11:32:55-07:00

Post by magick » 2006-07-22T11:52:51-07:00

Try this command with ImageMagick 6.2.8-5:
  • convert AL0584.jpg -fuzz 15% -fill none -draw 'matte 0,0 floodfill' output.gif

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony » 2006-07-23T19:11:38-07:00

These methods of course does not re-add any transparency anti-alising.
This is one area that needs some work, and images with a specific colored border (especially black) is a hot canidate for study.

Currently there is some promising reseach for a universal background eliminator with edge anti-alising handling at...
http://www.lsus.edu/sc/math/rmabry/imag ... tireplace/

However it should be posible to use a set of 'fuzzy fills' to locate the area that needs anti-aliasing to be added for background fills, and re-add it without
the hard aliased transparency the above provides.

Many GUI image programs do this as a form of 'feathered selection' so it should be posible to translate this into IM.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply