Cross Stitch software

Bonnie likes to do cross stitch. For some idiotic reason I felt that this was an interesting project to implement. So I did. Then, Paul Mateman's wife asked for some enhancements: she wanted thicker lines for every 10th (easier counting). So Paul took the liberty of reorganising the code a bit, now it runs a bit faster, and it generates the cross-stitch pattern the right way up. As usual, the major changes occur right after a release and I get busy. Richard Henwood has just sent me a patch:

xs-0.9.4-rh.patch

In the end I made some additions to your code to accept a [-p gimp_palette_file.gpl] option. This finds the closest color from the gimp_palette_file to the 'true' color of each pixel of the picture.

Now Cameron Morland has rewritten to generate the postscript directly. This results in a zillion times speed up and removes the dependancy on pyx - It is no longer slow! I haven't had time to remerge 0.9.4-rh with the 0.9.5 rewrite: This would be a good project for someone to get their hands dirty!

Installation

Grab the latest version.

Install PIL. On Debian this means "apt-get install python-imaging". The program has no interface or options. Just run it like this:

cd cs-0.9.4/
python xs.py file.png

xFig is recommended for laying out the printer ready form.

FAQ

Have you done any cross stitches?

I did one in high school.

Tutorial

Lets say I want to make a cross stitch of a sugar glider. First I need a picture of a sugar glider. Here's one I prepared earlier:

Then we need to make it a realistic size to stitch. I've chosen to make it 100x75 squares. Obviously it depends on your ability and your patience.

Ok, the hard part is converting the image down to a reasonable number of thread colours. This takes a bit of fiddling. The Easy way is to change the image to index and choose "generate optimal palette" with say 16 colours. Tweek the number of colours until you are happy with the result. If you go this path, push the contrast up a fair bit - I'll explain in a moment.

The second option is to hand pick the colours you want from the image using the new palette option and the eye-dropper to select colours you want. This is a little more tedious, but the results are better (I'm too lazy to include an example). The reason is that an optimal palette tends to have colours that are closer to the middle. E.g your picture might have a nice bright red in it, but the computer will decide that trading off a bit of the redness to reduce the error in the orange patches is worthwhile. The GIMPs algorithm is very good, but considering how long you will be spending doing the stitching, and looking at the results, it is probably worth the extra effort. Increasing the contrast is a cheap hack to achieve this. Notice that the eyes are much duller in the indexed version.

The third option is to use a premade palette with all the standard thread colours. Richard Henwood has kindly provided a complete palette of the DMC and Anchor range of colours. There are 455 colours total, and the gimp won't deal with indexed colours with more than 256 colours so at this point the best strategy is to pick the colours you would like to use, copy them into a separate file (remember to keep the same 4 header lines) and put that in your ~/.gimp-2.0/palettes/ directory. Here is a shortened example for bracteantha picture.

Please feel free to send in any other palettes.

Ok, now save this picture.

Now, here's the exciting bit. Run the cross-stitch program as per the instructions:

python cs-0.9.4/xs.py sugarglider-index.png

There will now be 2 extra files sugarglider-indexed.eps and sugarglider-indexed-colour.eps . These are the actual grid, and the key between the colour and the symbol. The Colour key is shown below (rotated 90° for clarity, click for the chart):

There are only 19 symbols currently. If you have any ideas for more then either tell me, or send me a patch.

Now open up xFig and drag out a picture rectangle. set the picture to be the chart. Repeat for the original picture and the colour key. Now you can print out your cross stitch and start stitching!

njh