views:

68

answers:

2

There are special kind of images called "duotone" which have just two channels. It is mostly used when you want to achive higher quality reproduction - have a printing press with two colors (black , gray).

My question is, I have normal gray-scale image, how to convert it to duotone?

I know I can tweak the curves in Photoshop - this is not what I'm asking, rather than how to do it programmatically? Perhaps there is a library which can do just that? What about "dot gain compensation"? "Total ink coverage"?

Or, what are te algorithms for creating "separations"?

+1  A: 

You can do it programatically. Color operations like these are quite simple, but doing it programmatically still requires tweaking.

Let's say you have the RGB color model for your image, then each channel (Red, Green, Blue, respectively) has a value. In gray-scale images (one channel: Gray) all these values (Red, Green and Blue) are equal, thus basically there is only one channel (the Gray).

Your goal is to create two new channels (duotone), which are the color A and color B. (A, B, resp.) I presume the effect you need is that A and B is either present or not at a certain location. Thus possible values per location are A, AB, B and none.

You have to iterate over the locations of your image (probably pixels), and translate the original colors (from RGB or G, to the duotone).

There are several techniques for translating them, but let's keep it simple: the image has only one channel, G, and we will apply a threshold filter:

threshold = 0.25
IF G < (0.5 + threshold) THEN A
IF G >= (0.5 - threshold) THEN B

For instance, with these values for G:

G         AB
0.0       A
0.1       A
0.2       A
0.3       AB
0.4       AB
0.5       AB
0.6       AB
0.7       AB
0.8        B
0.9        B
1.0        B

Now you only use three of the four possible values in the duo-tone. The following will do better:

thresholdA = 0.25
thresholdB = 0.5
IF G >= thresholdA && G < (1 - thresholdA) THEN A
IF G >= thresholdB                         THEN B

G         AB
0.0       
0.1       
0.2       A
0.3       A
0.4       A
0.5       AB
0.6       AB
0.7       AB
0.8        B
0.9        B
1.0        B

You will have to tweak the thresholds. If you let the tweaking be done in a GUI, then you've created your own (minor) Photoshop :-)

Pindatjuh
Thanks! I have two more questions though: in the first example, you mentioned that I use only 3 of 4 values, true, but if G = 0, A would most probably be also (very close) 0, no? And second, isn't it too simple for real-world printing? You mentioned there are several ways of translating from G (or RGB) to AB, please, don't you have more pointers? Also, how to compensate for gray not being 50% of black and various printing artifacts (dot gain, coated/uncoated stock, ...)?
TarGz
The colors A and B are user-defined, thus by you. If you choose A to be black, then you must adjust the threshold too. You mentioned two colors: black and gray, then adjust the thresholds accordingly (threshold 0.25 in the first example will work for such a situation).This is not the best way to do it, but it provides an overview how you may attack the problem. If your gray is not 50% black, then you'd have to adjust the threshold. You can test this out, by converting a gradient (white->black) to duotone and print it. Then adjust the threshold.
Pindatjuh
A: 

Photoshop's duotone's aren't very sophisticated. Photoshop duotones are merely the grayscale channel duplicated and output with two inks. Each ink color can have it's own curve, which adjusts each ink channel's output. The only tricky part is representing the curve (Photoshop maps a Bézier curve to a few data points defining the curve).

For help with the other terms you threw out in your question, you should investigate color management libraries (ColorSync on Mac OS X, Windows Color System, or LittleCMS).

If you want to have a deeper understanding, start with the Wikipedia entries on image processing and color management.

Further information in response to comments:

A CMS can help with dot gain compensation and converting an image into grayscale from other color spaces such as RGB.

The way Photoshop makes duotones is not to even separate the image into two, but just include instructions in the file to print the one grayscale image twice, adjusting values as necessary. If you want to create an image file that can be used by other programs such as InDesign to create documents suitable for a commercial printer, you'll want to create EPS files. See the documentation at Adobe's Web site on EPS and PostScript.

The pixel by pixel adjustment is accomplished by creating lookup tables for each ink. The tables have entries for each grayscale value. For an 8-bit grayscale image, the lookup table will contain 256 values. The lookup table is populated by solving the curve for each ink. Then run through your original grayscale data, replacing each value with whatever is at that location in the lookup table. For example, say your first curve puts the value of 102 in slot 127, and your second curve puts a value of 153 in slot 127. Then your first color would print at 40% for each pixel in the original image that's 50%, and your second color would print at 60% for each pixel in the original image that's 50%.

Mr. Berna
If I understand this correctly, the problem withm any CMS is, that you need an ICC profile for the desired space (duotone). But most probably such profile is proprietary or plain non-existent, that's why I'm asking about this, to understand how to turn gray-scale image into duotone, possibly suitable for printing.
TarGz
In other words, how to programmatically separate gray scale into two channels? I know that links, but they don't tell how to go about my question...
TarGz
Thank you very much for the response but you still haven't told me where do I get that "102" and "153" from. From curves. Where do I get the curves from? CMS? Most probably there will be no profile available. And even if I could measure the LAB of my solids, I still don't know what intensities I should print other shades on. "adjusting values as necessary" - could you please elaborate on that?
TarGz
The curves come from the duotone designer (the user of the software). A curve is a way to represent the relative intensities of each color in the duotone. Check out the Photoshop help on duotones to understand how duotones work: <http://help.adobe.com/en_US/Photoshop/11.0/WSfd1234e1c4b69f30ea53e41001031ab64-778da.html>
Mr. Berna