Color TSP art

From Evil Mad Scientist Wiki
Revision as of 20:13, 3 October 2010 by Dnewman (talk | contribs)
Jump to: navigation, search

<<< Advanced stipping || Color TSP art


Introduction

While yet to be proven a viable Eggbot art form, our adventures with TSP art need not end with monochrome imagery. By separating a color image into its cyan, magenta, yellow, and key (black) components, and then treating each component as a separate image to generate TSP art for, we can produce a color likeness of the original image by recombining the four pieces of TSP art.

The basic plan of attack is then

  1. Using an image editor which understands the CMYK color spaces such as Adobe Photoshop, change your image's color model to CMYK.
  2. Save each color layer in a separate file using a bitmap format understood by Gimp (e.g., TIFF).
  3. In Gimp, produce stippled images for each color layer as per Producing a stippled image with Gimp.
  4. Generate TSP art for each stippled color layer using some special command line options for tspart.py.
  5. Combine the TSP art files for the four layers into a single SVG file.

Color separation

First, ensure that you are using an image editor which supports CMYK color models. In the discussion which follows, directions are provided for Adobe Photoshop [1, 2].

After opening your image file in Photoshop, change the color model to CMYK via the "Mode..." item of the "Image" menu. Under the "Mode..." item, select "CMYK Color". If asked which specific CMYK color model to convert to, just go ahead and use the default which Photoshop suggests. At this point, save your image file as a new file and use the "Photoshop" format, .psd.

To separate each color out, we will use a fairly manual technique. A better technique may well exist.

  1. Cyan: Under the "Image" menu, select the "Adjustments..." item. In the pop-up menu under "Adjustments...", select "Levels...". This will bring up a new window with the title "Levels". In this window, use the "Channel" drop down list to select "Magenta". Then, set the output level for magenta to be "255" in the box on the left hand side. (The box on the right hand side should already read "255".) Once you have do this, you should see the magenta component disappear from the image. Now, repeat this step with the yellow and black channels as well. After doing thss to the magenta, yellow, and black channels, your image should only have the cyan channel remaining. Save the image as a new file named "cyan.tif". Select TIFF as the output format [3]. When presented with some TIFF file options, use the defaults presented.
  2. Magenta: Now re-open the image file you created as a Photoshop (.psd) file. This gives you the image again in a CMYK color space and with all channels present. Now, repeat the process of blanking out three of the color channels, but this time preserving magenta and setting the output levels to 255 for cyan, yellow, and black. Save the result as a TIFF file named magenta.tif.
  3. Yellow: Again, re-open the image file you created as a Photoshop (.psd) file. Set the output levels of the cyan, magenta, and black channels to 255. Leave the yellow channel untouched. Save the result as a TIFF file named yellow.tif.
  4. Black: Finally, re-open the .psd image file. Set the output levels of the cyan, magenta, and yellow channels to 255. Leave the black channel unchanged. Save the result as a TIFF file named black.tiff.
  5. Quit out of Photoshop.

Stipple each color layer

Follow the directions from Producing a stippled image with Gimp to generate stippled images of your four TIFF files, cyan.tif, magenta.tiff, yellow.tiff, and black.tiff. When adjusting the output levels in each image to "wash it out", try to use the same output level for each file. Save the results as cyan.pbm, magenta.pbm, yellow.pbm, and black.pbm.

Generate TSP art

When generating the TSP art, we will use the --line-color option to tspart.py to control the color of each drawn TSP solution. Also, so as to make output SVG files which can be combined into a single SVG file, we will also use the --pre, --mid, and --post options. Those options allow us to say that one output file is to include the preamble of a SVG file, another output fille is to have the postamble, and that the other files should have neither. Each individual file will not be a complete SVG file. However, when all the files are appended one after the other, they will create a valid SVG file.

Before proceeding, we should consider the order in which we want to draw the colors. On our Eggbot, we probably want to draw yellow first, followed by cyan, then magenta, and then black. This way we don't soil our yellow pen tip by drawing over darker ink colors. Similar considerations hold for cyan and magenta. However, when drawing on our screen, we want the reverse ordering so that yellow doesn't get completely lost under the other colors. On our screen, the colors won't blend: instead yellow pixels will simply be replaced by pixels of other colors which happen to draw over them.

Here are the commands to generate the TSP solutions for our four color channels,

% python tspart.py --line-color=yellow --pre --runs=1 yellow.pbm
% python tspart.py --line-color=cyan --mid --runs=1 cyan.pbm
% python tspart.py --line-color=magenta --mid --runs=1 magenta.pbm
% python tspart.py --post --runs=1 black.pbm

Note that in the above, we omitted specifying the line color for black.pbm as black is the default line color. We also specified --runs=1 so as to speed up the solution process (at the expense of solution quality).

Combine into a single SVG file

This step is a little anti-climatic. You merely need to issue the command,

% cat yellow.svg cyan.svg magenta.svg black.svg > picture.svg

after which the file picture.svg will be the resulting work of color TSP art. Windows users should note that they have the "cat" command by virtue of having installed Cygwin as part of setting up the Concorde TSP solver.

Keep in mind that when combining the files, the first file listed should be the one produced with the --pre option, and the last file listed (before the ">") should be the file produced with the --post option. The intervening two files should be the two produced with the --mid option.

If you wish to generate color TSP art for purposes other than Eggbot plotting, you may instead want to use the order black, magenta, cyan, yellow like so,

% python tspart.py --pre --runs=1 black.pbm
% python tspart.py --line-color=magenta --mid --runs=1 magenta.pbm
% python tspart.py --line-color=cyan --mid --runs=1 cyan.pbm
% python tspart.py --line-color=yellow --post --runs=1 yellow.pbm
% cat black.svg magenta.svg cyan.svg yellow.svg > picture.svg

Notes

[1] As of this writing, a free 30-day trial version of Photoshop is available for download from Adobe. This trial version supports the CMYK operations described here.
[2] Unfortunately, Gimp is not capable of working with CMYK color models.
[3] While Gimp can read .psd files, it cannot process .psd files with CMYK color models.


<<< Advanced stipping || Color TSP art