Page 1 of 1

How to colorize an image?

Posted: 2018-01-17T07:04:47-07:00
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.

Re: How to colorize an image?

Posted: 2018-01-17T07:12:48-07:00
by Bonzo
Please see this post and add the extra details: viewtopic.php?f=1&t=9620

Re: How to colorize an image?

Posted: 2018-01-17T15:08:01-07:00
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

Re: How to colorize an image?

Posted: 2018-01-17T15:19:42-07:00
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.

Re: How to colorize an image?

Posted: 2018-01-17T15:27:19-07:00
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?

Re: How to colorize an image?

Posted: 2018-01-17T15:38:17-07:00
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\)

Re: How to colorize an image?

Posted: 2018-01-17T15:44:40-07:00
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.

Re: How to colorize an image?

Posted: 2018-01-17T15:46:30-07:00
by FlashT
Thank you! :-)

Re: How to colorize an image?

Posted: 2018-01-17T17:01:47-07:00
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?

Re: How to colorize an image?

Posted: 2018-01-17T17:37:44-07:00
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.

Re: How to colorize an image?

Posted: 2018-01-17T17:59:28-07:00
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

Re: How to colorize an image?

Posted: 2018-01-17T18:07:55-07:00
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.

Re: How to colorize an image?

Posted: 2018-01-17T20:23:49-07:00
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

Re: How to colorize an image?

Posted: 2018-01-18T18:17:14-07:00
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