Converting a grayscale image to a colored 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
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Converting a grayscale image to a colored image

Post by troyd1 »

I have a grayscale image. I would like to convert it to another color, say blue. I would now want the black to be blue and the others to be shades of blue. How would I do that?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting a grayscale image to a colored image

Post by fmw42 »

troyd1 wrote:I have a grayscale image. I would like to convert it to another color, say blue. I would now want the black to be blue and the others to be shades of blue. How would I do that?

Please read viewtopic.php?f=1&t=9620 as you do not identify your version of IM nor platform. If your IM is not too old, then try

convert image +level-colors black,blue resultimage

see
http://www.imagemagick.org/Usage/color_ ... vel-colors
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Re: Converting a grayscale image to a colored image

Post by troyd1 »

Sorry, 6.6.9-7. q16 dynamic - window 2003 server

I tried some itteration using +level-color with promising results.

Here is my command:
convert -size 1650x1275 -density 300 xc:#ffff99 "c:\PCSHARE\PCGRAPHICS\ITWEB\REXFILES\BG_SC1_Design_03.png" +level-colors blue,white -composite -resize 20% c:\temp\graphics\finalgraphic.png

The graphic is actually a fancy border in grayscale.
The image is here: http://67.62.79.120/graphicstemp/BG_SC1_Design_03.png
After the composite, it does not have the ffff99 background, just white.
I also tried :
convert -size 1650x1275 -density 300 xc:#ffff99 "c:\PCSHARE\PCGRAPHICS\ITWEB\REXFILES\BG_SC1_Design_03.png" +level-colors blue,white -fill transparent -opaque white -composite -resize 20% c:\temp\graphics\finalgraphic.png
this gives me a black background.

Getting close, just not sure what to try next.
Thanks in advance for your help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting a grayscale image to a colored image

Post by fmw42 »

sorry I misread about the black and thought you wanted to preserve it. You need parens to avoid recoloring your #ffff99 background and quotes around it also. Try


convert ( -size 1650x1275 xc:"#ffff99" ) ( BG_SC1_Design_03.png +level-colors blue,white ) -composite -resize 20% result.png

but put your full paths back in as I had your image in my home directory.

or better (simpler)

convert BG_SC1_Design_03.png +level-colors blue,white -background "#ffff99" -flatten -resize 20% result.png
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Re: Converting a grayscale image to a colored image

Post by troyd1 »

Thanks for the reply. The first option will work. I am confused though.
I thought that the way image magic worked was like a stack so that
convert -size 1650x1275 xc:"#ffff99" was the first "layer" and BG_SC1_Design_03.png would be the second layer so that +level-colors blue,white would on work on the BG_SC1_Design_03.png and then the -composite would lay BG_SC1_Design_03.png +level-colors blue,white on top of the canvas without even using the parens. Please explain where my logic went wrong. Did the +level-colors blue,white apply to both? Thanks again for your help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting a grayscale image to a colored image

Post by fmw42 »

Did the +level-colors blue,white apply to both?
yes, IM will process any number of input images by the same command (except for commands that combine images) unless you use parens.

see
http://www.imagemagick.org/Usage/basics/#cmdline
http://www.imagemagick.org/Usage/basics/#image_seq
Post Reply