Page 1 of 1

convert black background

Posted: 2012-01-16T17:23:12-07:00
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 :-(

Re: convert black background

Posted: 2012-01-16T17:46:07-07:00
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

Re: convert black background

Posted: 2012-01-22T20:50:12-07:00
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.