How to replace color with another

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
NyzeAustria

How to replace color with another

Post by NyzeAustria »

Hello Community

I have a base image that looks like that

OrigImage

I need to change the color of this arrow based on a selection from a color picker.
Basicly i tried this with Photoshop and the result looks like this. I used a simple color overlay with RGB(255,0,0)

Result Image

My goals is to do this with IM so i looked up the tinting samples which uses -colorize. But -colorize just blends the image with a fill color rather than overlay the base with the new color. I don't know how to get this work that it looks like in Photoshop.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to replace color with another

Post by Bonzo »

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to replace color with another

Post by fmw42 »

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

Re: How to replace color with another

Post by anthony »

Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
NyzeAustria

Re: How to replace color with another

Post by NyzeAustria »

Thx

I looked at the samples. But how can i modulate my image to an exactly value in RGB like
R:101 G:237: B159. Playing with the HUE value from 0 to 360 gives only 360 possible colors. I don't understand how this exactly works. I am a really noob to graphics.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to replace color with another

Post by fmw42 »

you will have to convert RGB colors to HSL or HSB colors. There are many online tools that will do that for you. You provide the RGB and it tells you the HSL or HSB. See for example:

http://serennu.com/colour/hsltorgb.php
http://web.forret.com/tools/color.asp

You can do a Google search and probably find others or even tools to download. For example many imaging tools like photoshop, etc have these built in.

Also note that in IM, you can provide floating point values to -modulate.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to replace color with another

Post by anthony »

NyzeAustria wrote:Thx
Playing with the HUE value from 0 to 360 gives only 360 possible colors. I don't understand how this exactly works. I am a really noob to graphics.
The number is floating point, not integer! and it goes from 0 to 200 (the results is the same for those two values) with a value of 100 for no change.

Read the 'Usage Guide' link!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to replace color with another

Post by anthony »

Another way is to convert the image provided to a grayscale!
You can then tint that grayscale so that anything that was pure 50% gray becomes the exact color specified using -fill {color} -tint 100

See 'Tint' on the same IM Examples page
http://www.imagemagick.org/Usage/color/#tint


Hmmm looking at the operator again, it seems I was wrong, pure grays do not become the exact color! I will need to study this further, and either get that fixed, or find out what it really is going.

In the mean time their are DIY alternatives.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
NyzeAustria

Re: How to replace color with another

Post by NyzeAustria »

Is there still no solution for this? Don't know how to get this work!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to replace color with another

Post by fmw42 »

I believe we have given you many solutions. If we have misunderstood your problem, please clarify with examples of what you have and what you need. It does not have to be the same solution as PS, but simply get you the same kind of results.

The easiest way is

convert image -colorspace gray +level-colors color1,color2 output

see

http://www.imagemagick.org/Usage/color/#level-colors
http://www.imagemagick.org/Usage/color/#tinting
Post Reply