How to colorize an 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
FlashT
Posts: 12
Joined: 2018-01-16T15:57:57-07:00
Authentication code: 1152

How to colorize an image?

Post by FlashT »

How do I colorize an image (in the meaning of PSP or PS)?

I mean so it would only have one color in different tones.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to colorize an image?

Post by Bonzo »

Please see this post and add the extra details: viewtopic.php?f=1&t=9620
FlashT
Posts: 12
Joined: 2018-01-16T15:57:57-07:00
Authentication code: 1152

Re: How to colorize an image?

Post by FlashT »

Ok... got an image:

Image

Colorize process:

1. Turning it into a greyscale:

Image

2. Colorizing it (for example to green):

Image

3. Output:

Image
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: How to colorize an image?

Post by GeeMack »

FlashT wrote: 2018-01-17T15:08:01-07:003. Output:

Image
From a Windows CMD prompt you can get very nearly that result with a command like this...

Code: Select all

convert input.png -colorspace gray -fill green -tint 100 tinted.png
With ImageMagick you would use "-tint" to preserve the blacks and whites while adding color to the mid tones. The operator "-colorize" would add a certain percentage of the fill color over the entire image. Try the same command above with "-colorize 50" instead of "-tint 100" to see the difference in results.
FlashT
Posts: 12
Joined: 2018-01-16T15:57:57-07:00
Authentication code: 1152

Re: How to colorize an image?

Post by FlashT »

On Debian, but will be the same...

Sorry, I didn't use imagemagick much before... and can't test it now... is "green" a named color? Can I use HTML color instead or something similar?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to colorize an image?

Post by Bonzo »

You can use:

Name Cyan

HEX #00ffff
You may need use ' around the colour '#00ffff'

RGB rgb\(0,255,255\)

RGBA rgba\(0,255,255,1\)

HSL hsl\(180,100,50\)

HSLA hsla\(180,100,50,1.0\)

CMYK cmyk\(100,0,0,0\)

CMYKA cmyka\(100,0,0,0,100\)
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: How to colorize an image?

Post by GeeMack »

FlashT wrote: 2018-01-17T15:27:19-07:00Sorry, I didn't use imagemagick much before... and can't test it now... is "green" a named color? Can I use HTML color instead or something similar?
Yes, "green" is recognized by IM as a color name, and is equal to "rgb( 0, 128, 0)" or "#008000". See THIS PAGE for a list of colors and an explanation of all the ways you can specify colors in IM. Any of these methods should work here.
FlashT
Posts: 12
Joined: 2018-01-16T15:57:57-07:00
Authentication code: 1152

Re: How to colorize an image?

Post by FlashT »

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

Re: How to colorize an image?

Post by fmw42 »

In the OPs screen snap, the hue=75 and saturation=128, do not make a green color. This would be the equivalent of GeeMack's command using HSV values.

Code: Select all

convert untouched.png -colorspace gray -fill "hsv(120,255,127.5)" -tint 100 result.png
You can see that from

Code: Select all

convert xc:"green" -colorspace hsv -depth 8 txt:
# ImageMagick pixel enumeration: 1,1,65535,hsv
0,0: (21845,65535,32896) #55FF80 hsv(120,100%,50%)

Converting % to the range 0 to 255 gives: hsv(120,255,127.5)

What tool was used by the OP in that screen snap to do the colorizing? What is the range of Hue and Saturation values in that tool?
FlashT
Posts: 12
Joined: 2018-01-16T15:57:57-07:00
Authentication code: 1152

Re: How to colorize an image?

Post by FlashT »

I've used (and still using) Paint Shop Pro 9 made in 2004 (the best graphics app ever made in my opinion, made by Jasc... when Corel bought it, they've ruined it totally). Hue and Saturation range is 0-255.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to colorize an image?

Post by fmw42 »

For hue of 75 that would be 360*75/255=106, which is not green (120). The value of 106 might still be a shade of green. But your saturation seems way off.

See:

Image

Are you sure about the range of saturation in your tool? Might range from -128 to 128 or the like, so that 128 is max saturation?

Those numbers you show just do not make sense
FlashT
Posts: 12
Joined: 2018-01-16T15:57:57-07:00
Authentication code: 1152

Re: How to colorize an image?

Post by FlashT »

I am totally sure, checked it to answer your question... both values are 0-255...

Image
Image

BTW... 0 is red as well as 255. You can see a color on bottom of value.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to colorize an image?

Post by fmw42 »

BTW... 0 is red as well as 255. You can see a color on bottom of value.
Yes, that makes sense if the range is 0 to 255. In normal hue the range is 0 to 360 with 0 and 360 being the same.

But that means your green color is slightly off as 75->106, but true green is 120. In Imagemagick green not rgb(0,255,0), but is rgb( 0, 128, 0). So a darker green at half the green channel. So its hue should still be 120.

Code: Select all

convert xc:"rgb( 0, 128, 0)" -colorspace hsb -depth 8 txt:
# ImageMagick pixel enumeration: 1,1,65535,hsb
0,0: (21845,65535,32896) #55FF80 hsb(120,100%,50%)

Thus it would be Hue=120 (range 0 to 360) or 120*255/360=85 (not 75), Saturation 100% or 255 and Brightness 50% or 127.5

Your Hue=75:

Code: Select all

convert untouched.png -colorspace gray -fill "hsb(75,100%,50%)" -tint 100 your_green_hsb_75_100_50.png
Image

Hue=85 (true green)

Code: Select all

convert untouched.png -colorspace gray -fill "hsb(85,100%,50%)" -tint 100 true_green_hsb_85_100_50.png
Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to colorize an image?

Post by anthony »

For additional information on specifying colors...
http://www.imagemagick.org/Usage/color_basics/#colors

And for the myriad methods and techniques available in re-coloring images...
http://www.imagemagick.org/Usage/color_mods/

For tinting...
http://www.imagemagick.org/Usage/color_mods/#tinting
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply