Colorizing images

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
kriko

Colorizing images

Post by kriko »

Hello!

I have a bunch of images like this:
Image

and I would like to chage their colours, basically just replacing blue shades.
I experimented a bit from wiki, but the closest I got is this:

Code: Select all

convert cal_newevent.gif -fill orange -tint 110 tint.png
Image

Which is not really good. I'm not even sure how is this operation called properly (tint, colorize?) - I'm new to graphics.
Can someone give me some hints for solving this problem?

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

Re: Colorizing images

Post by fmw42 »

kriko wrote:Hello!

I have a bunch of images like this:
Image

and I would like to chage their colours, basically just replacing blue shades.
I experimented a bit from wiki, but the closest I got is this:

Code: Select all

convert cal_newevent.gif -fill orange -tint 110 tint.png
Image

Which is not really good. I'm not even sure how is this operation called properly (tint, colorize?) - I'm new to graphics.
Can someone give me some hints for solving this problem?

Thanks!
You can use the IM function -modulate to rotate the colors (by changing the hue in HSB colorspace)

convert calnewevent.gif -modulate 100,100,50 calnewevent_green.gif

where the 3 numbers are brightness, saturation and hue. 100 means no change. You may have to play with the third number to get the color you want as the results seem to depend upon what color your image is to begin with.

When I used 50, the result was a green color. When I used 0, the result was kind of yellow brown. When I used 150 (or -50), the result was magenta


see:
http://www.imagemagick.org/script/comma ... p#modulate
http://en.wikipedia.org/wiki/HSL_color_space
Last edited by fmw42 on 2008-10-26T11:49:07-07:00, edited 1 time in total.
kriko

Re: Colorizing images

Post by kriko »

Thank you!
That was exactly what I was looking for.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Colorizing images

Post by Bonzo »

I have been modifying a forum and this could have saved me a lot of time if I had known about it before. I will remember it the next time I do it :D
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Colorizing images

Post by anthony »

It is a good idea for this type of work for the images to first be mapped to grayscale, and then to a red scale. After that rotations
can be coordinated for multiple images and hues (with red at 100)

Alternativally the grayscale version can be re-maped using the newer operator +level-colors ,{color}
The ',' is important as it means the first color will be the normal 'black' default, and you are only wanting to remap the white color.

for example try....

Code: Select all

convert image.png -colorspace gray +level-colors ,purple  image_purple.png
See IM examples, color modifications, Level Adjustment by Color
http://www.imagemagick.org/Usage/color/#level-colors

Especially if you wait a day or so for the new examples I just added.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kriko

Re: Colorizing images

Post by kriko »

Thank you, I'll take a look.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Colorizing images

Post by anthony »

Looking at your image again you have both black and white in your image you will want to preserve. What you wnt is to map the mid-gray color of a pure grayscale image (-colorspace gray) using -tint.

So you almost had it right, you just needed to remove the old mid-tone color back to a grey first. You can also adjust the gray as well using -tint with a gray color to get the base image right.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kriko

Re: Colorizing images

Post by kriko »

Code: Select all

for i in * ; do convert $i -tint gray +level-colors purple $i; done
convert: invalid argument for option `gray': -tint.

Are you sure it is right?
Last edited by kriko on 2008-10-27T13:41:25-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Colorizing images

Post by fmw42 »

kriko wrote:

Code: Select all

for i in * ; do convert $i -tint gray +level-colors purple $i; done
convert: invalid argument for option `gray': -tint.
Are you sure it is right?
Check your IM version. level-colors was made available only at IM v6.2.4-1
kriko

Re: Colorizing images

Post by kriko »

I upgraded imagemagick and now it's fine. I'm getting better and better results, currently using parameters:

Code: Select all

convert cal_addevent.gif -colorspace gray -tint 40 +level-colors red, alpha.gif
Update: this sample seems to be perfect for my needs:

Code: Select all

for i in * ; do convert $i -colorspace gray -fill "rgb(100,150,110)" -tint 110 $i; done;
Thank you guys for all help!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Colorizing images

Post by anthony »

kriko wrote:I upgraded imagemagick and now it's fine. I'm getting better and better results, currently using parameters:

Code: Select all

convert cal_addevent.gif -colorspace gray -tint 40 +level-colors red, alpha.gif
Update: this sample seems to be perfect for my needs:

Code: Select all

for i in * ; do convert $i -colorspace gray -fill "rgb(100,150,110)" -tint 110 $i; done;
Thank you guys for all help!
You better make sure you set the fill color before tinting, like you di for your second example.

If you tint the image with pure red, then you can use -modulate to rotate the colors through the spectrum to produce a range of different colored images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply