Generating duotones

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?".
helcim

Generating duotones

Post by helcim »

Hello, I am looking for a way to generate duotones using imagemagick. First of all, how one should combine two greyscale images so that each ends up in a separate channel of a resulting image. Obviously it would be ideal if they were DeviceN channels but I don't know if imagemagick supports that.

Many thanks in advance


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

Re: Generating duotones

Post by fmw42 »

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Generating duotones

Post by anthony »

Also see the Windows example which creates color-cubes by merging rotated gradients to crate the faces of the cube, in different color spaces.
http://www.imagemagick.org/Usage/windows/#cube
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
helcim

Re: Generating duotones

Post by helcim »

Many thanks for replies. That's slightly arcane to me. I hoped for a simpler solution. Anyway, I'll try to understand that.
helcim

Re: Generating duotones

Post by helcim »

Here is my initial solution. Comments welcome!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generating duotones

Post by fmw42 »

You can put that all in one command line:

convert shadows.tif -negate black.tif
convert midtones.tif -negate cyan.tif
convert cyan.tif black.tif -set colorspace CMYK -channel cyan,black -combine duotone.tif

becomes

convert \( shadows.tif -negate \) \( midtones.tif -negate \) -set colorspace CMYK -channel cyan,black -combine duotone.tif

and I believe this also works as -negate is applied to all input images

convert shadows.tif midtones.tif -negate -set colorspace CMYK -channel cyan,black -combine duotone.tif
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Generating duotones

Post by anthony »

What the order. The cyan and black image creations need to be swapped in the combine command.

You are right in that negate will do BOTH.

convert midtones.tif shadows.tif -negate -set colorspace CMYK -channel cyan,black -combine duotone.tif


One small warning. While -combine does this properly the alternative method of using -compose CopyBlack fails for a grayscale channel image, basically as a RGB grayscale image does not contain a black channel! (CopyOpacity does do the right thing when no 'alpha/matte' channel is present.

I reported this bug a long time ago, but it was never actioned. I could I suppose fix it myself.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
helcim

Re: Generating duotones

Post by helcim »

Indeed the order should be changed, first midtones which should go to cyan then shadows to black. But the syntax without parenthesis does not seem to work for me. One more thing, when I display it with display 6.5.3-10 it shows a negative image on red background. All is fine with when I view it in feh, krita or gimp, which apparently treat yellow and magenta channels as invisible.
helcim

Re: Generating duotones

Post by helcim »

Yes, one -negate is enough but with parenthesis, like this:

Code: Select all

convert \( shadows.tif  midtones.tif -negate \) -set colorspace CMYK -channel cyan,black -combine duotone.tif
So to make this code work even better the question now is how to include generation of shadows.tif and midtones.tif in the command line? I guess it would make sense to have for instance all the duotones in a book created in a uniform way.
helcim

Re: Generating duotones

Post by helcim »

First take at a more generalized solution

Code: Select all

convert \( \( rose: -modulate 250 \)  \( rose: -modulate 90 \) -negate \) -set colorspace CMYK -channel cyan,black -combine rose-duotone.tif  
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generating duotones

Post by fmw42 »

perhaps if you could explain why you are doing this -- what is the objective of duotones, one could be of more help. I am not that familiar with what you do with them. I think this is a photography term, but I know nothing more about it. All I know is what it say on wikipedia, where they use blue rather than cyan. Your cyan result hardly looks any different from a grayscale result.

http://en.wikipedia.org/wiki/Duotone

I don't know if this helps, but you could convert your image to grayscale and tint it or tricolorize it. See my scripts, tintilize and tricolorize
Last edited by fmw42 on 2009-06-25T17:17:21-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Generating duotones

Post by anthony »

helcim wrote:One more thing, when I display it with display 6.5.3-10 it shows a negative image on red background. All is fine with when I view it in feh, krita or gimp, which apparently treat yellow and magenta channels as invisible.
Applogies I should have mentioned. As you are not filling in ALL the channels, the missing channels are set to the RGB channel value of the background color. so add -background black before the -combine.


The first sets of parenthesis should never be needed as their is only one current image list. Remember the way parenthesis works is \( creates a new separate image list, and \) appends that list to the end of the pervious older list. Either list could be empty! As such starting convert with \( just creates a second empty list, which is not really needed. Mind you, it does not hurt either.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Generating duotones

Post by anthony »

fmw42 wrote:All I know is what it say on wikipedia, where they use blue rather than cyan.
http://en.wikipedia.org/wiki/Duotone
From what I can see a duotone is very similar to what Fred creates with his Tricolorize.

As wikipedia says...
This is most often used to bring out middle tones and highlights of an image. The most common colors used are blue, yellow, browns and reds.
However if you are preserving white and black colors, just using -tint with the grayscale image should generate a 'duotone'. Tint basically tines all mid-range color values using a parabolic weighing pattern, and the fill color as a color vector. See
http://www.imagemagick.org/Usage/color/#tint

If you can confirm this is what you are after!

Hmmm for the Sepia-Tone examples in Wikipedia
http://en.wikipedia.org/wiki/Sepia_tone#Sepia_toning
I had a good result of matching there effect by tinting with 'Wheat'
convert MalibuBW.jpg -fill Wheat -tint 100 show:

I have updated the sepia-tone color examples
http://www.imagemagick.org/Usage/color/#sepia-tone

I will also see about adding examples of the duotone to the section on 'tint'
http://www.imagemagick.org/Usage/color/#tint

Updates should appear in a couple of hours.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
helcim

Re: Generating duotones

Post by helcim »

Many thanks for your replies! Yes, I should have started with explanation of my objectives. I need real duotones rather than tinted image for a two-color printing job so that I could print the illustrations for a book with just two plates, black and cyan for instance. Actually, very often cyan is replaced in the printing process by an arbitrary spot color, just because it's easier to generate CMYK. But I would obviously like to do it right, if it's possible, that means generate a duotone image with black and another Pantone color in its own channel with a CMYK preview embedded. I think it's possible in PDF and PS but not in tiff.

I guess it's impossible to give a universal recipe for a duotone conversion just like with grayscale. Two most popular use cases seem to be:
1. A "better" black-and-white reproduction.
2. A more "artistic" effect.

One can strive also for a quite faithful color reproduction with just two inks as this article demonstrates. Although I cannot think of any practical application of this. Unless you print a book with a single illustration, of course :)

Right now I'm most interested in case 1.

Piotr
helcim

Re: Generating duotones

Post by helcim »

One more interesting article on duotones by Robert Chung.
Post Reply