Color TSP art
<<< Advanced stipping || Color TSP art
Contents
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
- Using an image editor which understands the CMYK color spaces such as Adobe Photoshop, change your image's color model to CMYK.
- Save each color layer in a separate file using a bitmap format understood by Gimp (e.g., PSD).
- In Gimp, produce stippled images for each color layer as per Producing a stippled image with Gimp.
- Generate TSP art for each stippled color layer using some special command line options for tspart.py.
- 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, use the cmyk.jsx script found in the latest TSP art tool kit download,
Run the script using the "Scripts..." item from the "File" menu. Under "Scripts..." you can select "Browse..." and then browse to the directory with the cmyk.jsx file. This will produce files named x-black.psd, x-cyan.psd, x-magenta.psd, and x-yellow.psd where "x" is the name of the original file.
If you want to manually do the separations, here are the steps for Photoshop. After opening the 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.
- 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 this to the magenta, yellow, and black channels, your image should only have the cyan channel remaining. Now, convert the image to grayscale: under the "Image" menu, select "Mode..." and from the "Mode..." menu, select "Grayscale" [3]. Click "OK" to having the color information discarded. Now, save the image as a new file named "cyan.psd". Select "Photoshop" as the output format.
- 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. After converting the image to grayscale, save the result as a .psd file named magenta.psd.
- 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. Convert to grayscale, and then save the result as a .psd file named yellow.psd.
- 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. After converting to grayscale, save the result as a .psd file named black.psd.
- 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 .psd files, cyan.psd, magenta.psd, yellow.psd, and black.psd. You can omit in GImp converting the images to grayscale: when Gimp opens the images, they will already be grayscale images. 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 --stroke 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 --stroke=yellow --pre --runs=1 --layer="1 - yellow" yellow.pbm % python tspart.py --stroke=cyan --mid --runs=1 --layer="2 - cyan" cyan.pbm % python tspart.py --stroke=magenta --mid --runs=1 --layer="3 - magenta" magenta.pbm % python tspart.py --post --runs=1 --layer="4 - black" 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). We also used the --layer option to specify a layer name for each layer. By having layer names of this form, we can plot each layer separately with the Eggbot control extension in Inkscape.
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 --stroke=magenta --mid --runs=1 magenta.pbm % python tspart.py --stroke=cyan --mid --runs=1 cyan.pbm % python tspart.py --stroke=yellow --post --runs=1 yellow.pbm % cat black.svg magenta.svg cyan.svg yellow.svg > picture.svg
Notes
[*] Color TSP art rendition of The Solitary Cedar by Tivadar Csontváry. (Sometimes translated as "The Lonely Cedar".)
[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] It is important to do the conversion to grayscale within Photoshop: Photoshop will know the correct gamma expansions for the CMYK color model in use. If you were to save the files as TIFF files and let Gimp do the grayscale conversions, then Gimp will do the wrong gamma expansions and the color balances will be noticeably off in your results. Moreover, if you leave the images as CMYK images and save them to .psd files, then Gimp cannot read them as Gimp cannot handly CMYK images.
<<< Advanced stipping || Color TSP art