Turning a black and white sketch into a red and white sketch

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
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Turning a black and white sketch into a red and white sketch

Post by whugemann »

I often have to overlay different black and white line drawings in order to compare them. I have done this with Photoshop so far:

1) Turn the vector drawing into a grayscale pixel format.
2) Negate the drawing, such that I have white lines on black canvas.
3) Turn it into a RGB image.
4) Switch off, say, the red channel, such that I have cyan lines on black canvas.
5) Negate the result again, such that I have red lines on white canvas.

Analogously, I turn the other vector drawing into, say, green lines on white canvas and then superpose the two by multiplying them.

I tried to do this with ImageMagick by using -colorspace RGB, -channel ... and -combine, but didn't succeed. All I could make up were cyan, magenta or yellow lines on white canvas, that is a combination of two colour channels. Could someone help me out with the correct Convert command?
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Turning a black and white sketch into a red and white sk

Post by fmw42 »

Wolfgang,

If you have grayscale or white lines on a black background and you want to colorize the lines, you can do

convert grayscaleimage +levelcolors black,somecolor newimage

note the +level-colors not -level-colors

see
http://www.imagemagick.org/Usage/color_ ... vel-colors

Hope I understand your question? If not let me know further or provide a link to an example input and output image


If the line is pure white on a pure black background, then it is more direct to do:

convert bwimage -fuzz XX% -fill somecolor -opaque white newimage

the fuzz XX% permits the line to be anti-aliased and not get a halo. Generally a few percent should do, but vary it until you get the results desired. If the line is not anti-aliased, then you can leave off the -fuzz XX%.

see
http://www.imagemagick.org/Usage/color_basics/#replace

Fred
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Turning a black and white sketch into a red and white sk

Post by el_supremo »

If you're starting with black lines on white and want to change the black to red you can use these two options:
-fill red -opaque black
Similarly black to green is:
-fill green -opaque black

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Turning a black and white sketch into a red and white sk

Post by fmw42 »

As el_supremo said, you can start with black lines on white and convert to color lines on black in one command, if you like.

convert image -fill somecolor -opaque black -fill black +opaque white resultimage
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Turning a black and white sketch into a red and white sk

Post by whugemann »

Based on your instructions, I now used the +level-colors operator (which I didn't known so far) and succeeded. I turned black lines on white canvas into red ones on white canvas by:

convert grayscale.jpg -negate +level-colors ,cyan -negate red.png

I will have to look up what I am actually doing there sometimes, but I don't have the time at the moment. I went for the +level-colors option instead of using color substitutions, because in this case I have to deal with JPEG scans and I do not want to experiment with the -fuzz option. Thanks for your advice!
Wolfgang Hugemann
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Turning a black and white sketch into a red and white sk

Post by whugemann »

I've just seen Anthony's solution for the cow picture at http://www.imagemagick.org/Usage/color_ ... vel-colors. Thus the easiest solution is

convert %1 +level-colors red, %~n1.png

which spares the double-negation.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Turning a black and white sketch into a red and white sk

Post by fmw42 »

whugemann wrote:I've just seen Anthony's solution for the cow picture at http://www.imagemagick.org/Usage/color_ ... vel-colors. Thus the easiest solution is

convert %1 +level-colors red, %~n1.png

which spares the double-negation.

Sorry, when I went looking for references for you I tried to find that one, but could not find it for some reason (probably scanned the pages too quickly). It was one I was trying to get for you. Glad you found it.

Fred
Post Reply