Need assistance on colorizing a grayscale image without affecting black/white hues

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
BenFacilis
Posts: 2
Joined: 2016-07-18T13:34:55-07:00
Authentication code: 1151

Need assistance on colorizing a grayscale image without affecting black/white hues

Post by BenFacilis »

Here's another original image:
https://postimg.org/image/bpig021c1/

What I'm trying to achieve:
https://postimg.org/image/vguq10pr5/

This is what I get currently...
https://postimg.org/image/3ky9pvqg7/
...using the .NET wrapper:
image.Colorize(new MagickColor("#ffff00"), (Percentage)50);

Instead of washing out the black/white hues, I'd like to only saturate the various shades of grey with shades of whatever hex color I pass in.

If you load up Photoshop, go to Image > Hue/Saturation and configure the HSL for 60/70%/50%, you'll get the desired result.

How would I go about doing this, given these values?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need assistance on colorizing a grayscale image without affecting black/white hues

Post by fmw42 »

Try this (unix syntax). Please always provide your IM version and platform when asking questions on this forum, since syntax may vary.

Code: Select all

convert background1_original.jpg \
\( -size 1x1 xc:black xc:"hsl(60,70%,50%)" xc:white +append -resize 512x1! \) \
-interpolate bilinear -clut result.jpg
If on unix systems, see my script tintilize at the link below.
BenFacilis
Posts: 2
Joined: 2016-07-18T13:34:55-07:00
Authentication code: 1151

Re: Need assistance on colorizing a grayscale image without affecting black/white hues

Post by BenFacilis »

Thanks a million! Going to try this out
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Need assistance on colorizing a grayscale image without affecting black/white hues

Post by GeeMack »

BenFacilis wrote:How would I go about doing this, given these values?
Like the idea fmw42 provided above, I'd probably create a color lookup table to apply to the original image. Using IM7 on a Windows 7 64 system I can get a near match to your "background1_edited.jpg" example with a command like this...

Code: Select all

magick background1_original.jpg ^
   ( -size 1x256 gradient:#000000-#dddd33 gradient:#dddd33-#ffffff -append ) -clut output.jpg
That makes a lookup table which is a gradient running from black to yellow with the hex value "#dddd33" to white. The "-clut" operation applies that table to your "background1_original.jpg" and outputs "output.jpg".

Also as fmw42 mentioned, the exact syntax would depend on your version of IM and your operating system.
Post Reply