convert black 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
sozin
Posts: 1
Joined: 2012-01-16T17:13:56-07:00
Authentication code: 8675308

convert black background

Post by sozin »

Hello, I am stumped on what should be a very basic operation: converting a black background to a white background. I'm running on windows with Version: ImageMagick 6.7.4-2 2011-12-22 Q16 http://www.imagemagick.org.
  • the image file I'm trying to convert can be found here.
  • From the convert man page, I've tried various combinations of -flatten, -fill, -opaque, -transparent, -transparent-color, and -background, but regardless of what I try the converted image is always identical to the original
  • various examples from different web searches have yielded the same (non)result
  • I'm not attached to any particular output format - jpg, png, etc are all fine
When I run identify on the image, I get:
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
thank you in advance, I feel like I'm missing something basic here :-(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert black background

Post by fmw42 »

You need to do a fuzzy floodfill of the black background with white. try

convert 6711287257_1c65829b2f_b.jpg -fuzz 10% -fill white -draw "color 0,0 floodfill" 6711287257_1c65829b2f_b_floodfill.png

see
http://www.imagemagick.org/Usage/draw/#color

or
http://www.imagemagick.org/Usage/color_ ... #floodfill
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert black background

Post by anthony »

sozin wrote:Hello, I am stumped on what should be a very basic operation: converting a black background to a white background.
Their is NOTHING simple about it. It can be simple IF the the image is simple, and that is what the pointers previously given will deal with. But simple images are very very rarely the case!


Exactly what you an do really depends on what the image looks like, and many tenchinques are covered in
ImageMagick Examples (v6), Background Removal,
http://www.imagemagick.org/Usage/masking/#bg_remove

The last technique, Background Removal using Two Backgrounds
http://www.imagemagick.org/Usage/maskin ... background
allows for perfect background masking and extraction of the foreground image complete with semi-transparent anti-aliasing edge pixels. However to do this you need more information than just one image can provide, specifically the same foreground image on two different (and known) backgrounds (not necessary a solid color background, though that is simpler).

Your example image however looks like someone badly converted from white background to a black background, and a simple flood fill method should be able to restore the white background. But replacing that white background will NOT be so simple.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply