Page 1 of 1

How can I replece a color into a image?

Posted: 2008-11-27T11:53:49-07:00
by kali
I wolud fill - dinamically - another color at the place of a specific color... In other words I want use the "fill" tool of common grapfhic programs using imagemagick.


For example this image has two colors: black and white.. I would transform black to red.. to green.. to... another color :)

Image

Thanks!! (sorry my english)

Re: How can I replece a color into a image?

Posted: 2008-11-27T12:07:02-07:00
by fmw42
kali wrote:I wolud fill - dinamically - another color at the place of a specific color... In other words I want use the "fill" tool of common grapfhic programs using imagemagick.


For example this image has two colors: black and white.. I would transform black to red.. to green.. to... another color :)

Image

Thanks!! (sorry my english)
The easiest way to change from black and white to any other colors is to use Anthony's new +level-colors, for example:

convert bw_image.jpg +level-colors red,blue rb_image.jpg

This will convert black to red and white to blue. You can assign any valid IM colors.

see

http://www.imagemagick.org/Usage/color/#level_plus
http://imagemagick.org/script/color.php

Re: How can I replece a color into a image?

Posted: 2008-11-27T12:07:53-07:00
by rmagick
Use the -opaque option. Here's an example. http://www.imagemagick.org/Usage/color/#opaque

Re: How can I replece a color into a image?

Posted: 2008-11-27T12:11:29-07:00
by kali
rmagick wrote:Use the -opaque option. Here's an example. http://www.imagemagick.org/Usage/color/#opaque

Thank your reply

I have solve using: convert mucca.jpg -fuzz 30% -fill red -opaque black balloon_red.gi

:)

Re: How can I replece a color into a image?

Posted: 2008-11-30T18:10:36-07:00
by anthony
DO NOT USE -opaque This method only changes ONE exact or near-exact color (or NOT (+ form) that color) to another color without regard to color shades and anti-aliasing.

As given previously you can use the greyscale to color gradient replacement using +level-colors or turn white into transparency (negate to make black transparent) and set the other color using -alpha shape

given your original image as "cow.jpg"
This generates a red on white cow, without edge aliasing problems!

Code: Select all

convert cow.jpg +level-colors red, cow_red.jpg
See IM examples Level change by color

You will definatally NOT get such a 'clean' color change using -opaque