The "Meet the GiMP!" ForumGIMP, Image Processing (DIP) and PhotographyImage Processing SoftwareScripts, Plugins, Python, Perl and SchemeNew Python script: Cross-stitchify
Pages: [1]   Go Down
Print
Author Topic: New Python script: Cross-stitchify  (Read 2635 times)
w_nightshade
Regular
**
Posts: 70



View Profile WWW
« on: March 19, 2009, 01:02:13 pm »

Someone on an email list I belong to asked about ways of making a counted cross-stitch pattern from a photo.  There are commercial packages that do this, but it seemed like something GIMP could do, and I wanted some Python practice.

Attached is a zip file containing the following files:

  • cross-stitch.py - Python script for converting a photo to a cross-stitch pattern
  • floss.html - an HTML document listing available cross-stitch floss colours by numbered index, common name, RGB and hex values (culled from http://www.stitchstuff.com/dmcrgb.htm)

I used the Photoshop tutorial found here as my starting point.  The script performs the following operations:
  • Pixellates, adjusts brightness & posterises according to user settings
  • Scales down the pixellated image to increase performance
  • Checks each colour of each mosaic tile, and performs "best matching" colour exchange against the palette of available floss colours
  • Scales up pixellated image for next operations and for readability
  • Adds grid in new layer
  • Adds text labels for each colour with floss' index number
  • Creates a text file listing all floss needed, and in what quantities

It appears in the menus under Filters > Decor > Cross-stitchify... It takes quite some time to run as I need to iterate through each tile of the image twice, and any interruption during the label phase can crash the script, but the output is quite good.  The entire image can be printed for use as the pattern, or just the grid if printing in B&W.

I would love some feedback if there are better ways to do what I have done, or any bugs I may have missed.  Cheers!

UPDATE: version 2.0 - added creation of text file with list of what colour floss, and how many stitches of each, are used. Also allowed for greater range of mosaic sizes to accommodate wider range of images.  New version attached below.


* max_cross_stitch.gif (275.78 KB, 1640x1120 - viewed 306 times.)

* max.jpg (67.8 KB, 827x567 - viewed 208 times.)
* cross-stitchify_v2_0.zip (15 KB - downloaded 124 times.)
* max.txt (5.15 KB - downloaded 157 times.)
« Last Edit: March 24, 2009, 05:58:33 pm by w_nightshade » Logged

Rolf
Administrator
Sr. Member
***
Posts: 1332


View Profile
« Reply #1 on: March 19, 2009, 07:28:22 pm »

Absolutely useless for me - but sooooo cooool!

I wouldn't have guessed that this is possible.
Logged

monoceros84
Administrator
Sr. Member
***
Posts: 1460



View Profile WWW
« Reply #2 on: March 19, 2009, 08:09:27 pm »

Absolutely useless for me - but sooooo cooool!

You don't stitch, Rolf?  Grin
Logged

Cheers,
Mathias

Visit this site about my photography, my experiences in Norway and my blog:
http://www.gedankenquirl.de (German language)

w_nightshade
Regular
**
Posts: 70



View Profile WWW
« Reply #3 on: March 19, 2009, 10:40:16 pm »

Awwww, Rolf... thanks. Smiley
Logged

w_nightshade
Regular
**
Posts: 70



View Profile WWW
« Reply #4 on: March 24, 2009, 05:47:17 pm »

I decided I liked this enough to add it to the GIMP registry. 

http://registry.gimp.org/node/14919

I also added code that generates a text file with a list of every colour used by index number and name, with a list of how many stitches in that colour.  I also commented the code more thoroughly.  That project has been super fun, and I hope someone gets some use from it... either by using the script itself, or by getting some insight ro inspiration to write their own scripts.
Logged

Rolf
Administrator
Sr. Member
***
Posts: 1332


View Profile
« Reply #5 on: March 24, 2009, 06:50:07 pm »

I wanted to talk about this in today's show, but forgot. Next week. :-)
Logged

w_nightshade
Regular
**
Posts: 70



View Profile WWW
« Reply #6 on: March 25, 2009, 02:05:00 pm »

I am honoured!

Also, v2.1 is up - apparently the method I was using to launch the text file only works in Windows (what I am running), so I added an OS test which pops up a message with the text file path in not running Windows.
Logged

Pages: [1]   Go Up
Print
Jump to: