Difference between revisions of "Color TSP art"

From Evil Mad Scientist Wiki
Jump to: navigation, search
m (Reverted edits by 86.186.243.193 (talk) to last revision by Dnewman)
 
(6 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
----
 
----
  
http://mtbaldy.us/~dnewman/tspart/cedar.jpg
+
http://wiki.evilmadscience.com/s3/eggbot/tspart/cedar.jpg
  
 
== Introduction ==
 
== Introduction ==
Line 20: Line 20:
 
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].
 
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.  
+
After opening your image file in Photoshop, use the cmyk.jsx script found in the latest TSP art tool kit download,
 +
 
 +
:[http://code.google.com/p/eggbotcode/downloads/list http://code.google.com/p/eggbotcode/downloads/list]
 +
 
 +
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.
 
To separate each color out, we will use a fairly manual technique.  A better technique may well exist.
Line 32: Line 39:
 
== Stipple each color layer ==
 
== 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.
+
Follow the directions from [[Producing a stippled image with Gimp]] to generate stippled images of your four .psd files, x-cyan.psd, x-magenta.psd, x-yellow.psd, and x-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 ==
 
== Generate TSP art ==
  
When generating the TSP art, we will use the <tt>--line-color</tt> 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 <tt>--pre</tt>, <tt>--mid</tt>, and <tt>--post</tt> 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.
+
When generating the TSP art, we will use the <tt>--stroke</tt> 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 <tt>--pre</tt>, <tt>--mid</tt>, and <tt>--post</tt> 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.
 
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.
Line 43: Line 50:
  
 
<pre>
 
<pre>
% python tspart.py --line-color=yellow --pre --runs=1 yellow.pbm
+
% python tspart.py --stroke=yellow --pre --runs=1 --layer="1 - yellow" yellow.pbm
% python tspart.py --line-color=cyan --mid --runs=1 cyan.pbm
+
% python tspart.py --stroke=cyan --mid --runs=1 --layer="2 - cyan" cyan.pbm
% python tspart.py --line-color=magenta --mid --runs=1 magenta.pbm
+
% python tspart.py --stroke=magenta --mid --runs=1 --layer="3 - magenta" magenta.pbm
% python tspart.py --post --runs=1 black.pbm
+
% python tspart.py --post --runs=1 --layer="4 - black" black.pbm
 
</pre>
 
</pre>
  
Note that in the above, we omitted specifying the line color for black.pbm as black is the default line color.  We also specified <tt>--runs=1</tt> so as to speed up the solution process (at the expense of solution quality).
+
Note that in the above, we omitted specifying the line color for black.pbm as black is the default line color.  We also specified <tt>--runs=1</tt> so as to speed up the solution process (at the expense of solution quality).  We also used the <tt>--layer</tt> 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 ==
 
== Combine into a single SVG file ==
Line 67: Line 74:
 
<pre>
 
<pre>
 
% python tspart.py --pre --runs=1 black.pbm
 
% python tspart.py --pre --runs=1 black.pbm
% python tspart.py --line-color=magenta --mid --runs=1 magenta.pbm
+
% python tspart.py --stroke=magenta --mid --runs=1 magenta.pbm
% python tspart.py --line-color=cyan --mid --runs=1 cyan.pbm
+
% python tspart.py --stroke=cyan --mid --runs=1 cyan.pbm
% python tspart.py --line-color=yellow --post --runs=1 yellow.pbm
+
% python tspart.py --stroke=yellow --post --runs=1 yellow.pbm
 
% cat black.svg magenta.svg cyan.svg yellow.svg > picture.svg
 
% cat black.svg magenta.svg cyan.svg yellow.svg > picture.svg
 
</pre>
 
</pre>

Latest revision as of 01:36, 18 June 2012

<<< Advanced stipping || Color TSP art


cedar.jpg

Introduction[edit]

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., PSD).
  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[edit]

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,

http://code.google.com/p/eggbotcode/downloads/list

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.

  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 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.
  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. After converting the image to grayscale, save the result as a .psd file named magenta.psd.
  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. Convert to grayscale, and then save the result as a .psd file named yellow.psd.
  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. After converting to grayscale, save the result as a .psd file named black.psd.
  5. Quit out of Photoshop.

Stipple each color layer[edit]

Follow the directions from Producing a stippled image with Gimp to generate stippled images of your four .psd files, x-cyan.psd, x-magenta.psd, x-yellow.psd, and x-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[edit]

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[edit]

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[edit]

[*] 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