Replace background colour to any hex code

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
joshuafinny
Posts: 16
Joined: 2016-01-11T05:12:11-07:00
Authentication code: 1151

Replace background colour to any hex code

Post by joshuafinny »

I have a set of images in a white or off white background. I want to convert the background to a particular hex value (#f1f0ee).

Tried using convert image -fuzz XX% -fill red -opaque white result

The problem here is, it will consider everything white, even parts of the product. Also, the edges need refinement, which does not happen using the above. I would like to perform this action in bulk.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Replace background colour to any hex code

Post by Bonzo »

I found this interesting post a few years ago: http://tech.natemurray.com/2007/12/conv ... arent.html
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Replace background colour to any hex code

Post by fmw42 »

It might help, if you provide an example image. Also always provide your IM version and platform, since syntax may differ.
joshuafinny
Posts: 16
Joined: 2016-01-11T05:12:11-07:00
Authentication code: 1151

Re: Replace background colour to any hex code

Post by joshuafinny »

fmw42 wrote:It might help, if you provide an example image. Also always provide your IM version and platform, since syntax may differ.
IM Version 6.9.4
Windows Platform

Sample Image:
http://i.imgur.com/4Htli6m.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Replace background colour to any hex code

Post by fmw42 »

Try this:

Code: Select all

convert 4Htli6m.jpg -fuzz 1% -fill "#f1f0ee" -opaque white result.jpg
joshuafinny
Posts: 16
Joined: 2016-01-11T05:12:11-07:00
Authentication code: 1151

Re: Replace background colour to any hex code

Post by joshuafinny »

fmw42 wrote:Try this:

Code: Select all

convert 4Htli6m.jpg -fuzz 1% -fill "#f1f0ee" -opaque white result.jpg
Great!! Thanks!
Post Reply