How can I replece a color into a image?

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
kali

How can I replece a color into a image?

Post 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)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

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

Post by rmagick »

Use the -opaque option. Here's an example. http://www.imagemagick.org/Usage/color/#opaque
kali

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

Post 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

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

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

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply