# Photographic Quilt and Auto-generation Program

4,414

52

19

My wife has had it in her head to make a flower quilt for several months.  At first, she didn't want my help, but I finally convinced her that I could be of some use generating the pattern.  So, I showed her how to use CorelDraw to reduce the resolution and posterize, then I wrote her a little Python program for generating the pattern and color swatches.

This instructable will take you from a photograph to a sophisticated, collated quilt pattern. In this instructable, we'll just go as far as creating the pattern. We'll photograph the progress of the quilt and post another instructable when it's complete.  Errica [sic] has already done a few squares and you can really see how well it's going to come together!

Software needed:
• CoelPhotoPaint or another bitmap manipulation program.  (I didn't have much luck with Paint.net, but you can give it a try!)
• The Python script included in this instructable.
BTW, we used the Corel programs available at the TechShop!

## Step 1: Select an Image

The first step in making a photographic style quilt is to find an image.  This can be tricky!  You will have to zoom in very close and find an image without a lot of detail if you want to have any hope of conveying your idea on a quilt.  You should iterate on a *lot* of images before settling on your final one.   We took several trips around the neighborhood taking photos of all the flowers we could find.  Then we finally had the brilliant idea to visit the local nursery for flowers :-)

Take lots of photos.  Make the close up, and make sure your background looks good.  Here is a quick sample of the photos we took!

## Step 2: Reduce the Resolution

Reduce the number of pixels. Be careful! A small change in resolution makes for a LOT more work: 10x10 = 100 squares, 20x20=400 squares, 40x40=1600 squares! A LOT of work to be sure.

Errica [sic] went bonkers and went for this image you see here, which is 39 x 47 = 1833 separate quilt pieces!

From this point on, be sure to save your images in .BMP format so that you don't loose any color information in encoding or decoding.

To reduce the number of pixels in the image, you choose Image->Resample. Be sure to change measurements to pixels, and specify around 40 pixel resolution. See photo for an example.

## Step 3: Reduce the Number of Colors, Check Out Your Palette

Using CorelPhotoPaint or similar program, you can reduce the number of colors in the image.  Use the 'Image->Convert to Paletted' command.  I tried this in Paint.net with Posterize, but it resulted in WAY too many colors.  The CorelPhotoPaint works well, and I'm sure this can be done in photoshop.

I choose the settings shown in the image.  Basically, play with it until you get something you like.  I ended up with 30 colors.

Here's the output of the color count:

\$ ./count_colors.py 01-flower4-reduced_pixel_count.bmp 02-flower4-reduced_colors.bmp
There are 1827 colors in this image, and 1833 pixels:
There are 30 colors in this image, and 1833 pixels:

So, we reduced the image from 1827 colors to 30 colors!  This is a good thing ;-)

Check out your palette for any colors that are too close to one-another.  If any are very close, you can keep reducing the color count.

## Step 4: Run This Program That Creates the Quilt!

Now, create the quilt pattern!

The attached program called create_quilt.py requires python with the Python Image Library.

You simply run the create_quilt.py program from your command line.  If you are actually going to create one of these quilts and you don't have any clue how to run python or programs, just shoot me a message and run the program for you to create your palette and quilt pattern.  If many people want to do it, I'll just stick it on a web page somewhere.

# create_quilt.py my_reduced_pixel_filename.bmp

and the follwoing files will be created:
color_list.txt
palette.png
quilt.png

The next couple of steps will describe each of those output files.

[UPDATE May 31, 2013:  Added the create_quilt.zip file that contains the python script, as well as a stand alone windows executable for running the program.]

## Step 5: Palette

Here is the palette.png output of create_quilt.py.  This image will have one square for each color in your image.  This is going to be your guide for selecting fabrics.

Each square is labeled in a "A, B" format.  A is the index of the color, B is the number of square of that color required.  In this example, the top left is a light pink, and it says, "0, 36".  That means that the color index is '0', and there are 36 of these squares needed.  As you go across the image, you see that the color index simply increments by one each square. (Sorry I started the quilt indices at 0, not one, which often confuses non programmers... oh well.  Just remember that '0' is a number ;-)  )

## Step 6: Quilt.png

The quilt.png file shows an image of the entire quilt. This is your pattern that you will use to actually piece together your quilt.

The outsides of the pattern simply have the rows and columns numbered, and the number inside each quilt block represents the color index from your palette.  Building your quilt is 'simply' quilting by number :-)

## Step 7: Color_list.txt

Here's an example of the first few lines of color_list.txt:

# count RGB
0 36 [246, 215, 226]
1 62 [243, 143, 176]
2 65 [240, 111, 146]
3 55 [218, 157, 159]

The format is simply 'index count RGB color'.  You can use this if you like, but really the previous photos are all that's required.

## Step 8: Pick Your Fabrics

Print out your swatches and a large copy of your main image.  Be careful that your swatch colors and main image colors match!  We initially tried printing swatches at the photo place on 4x6 prints because they were \$0.19 each with each swatch on a different print. The auto-color-correction wrecked that idea -- several of the colors that should be different came out looking identical!  Be careful to double check the colors of everything before you start buying fabrics.

This is the end of the beginning.  We'll keep you updated as the quilt progresses!

Stay tuned for instructable #2, where my wife actually builds the quilt.  I only did the programming & helped with image selection, so my work here is done.

## Step 9: Sneak Preview

Here's a sneak preview of the quilt.  It's already starting to look cool!

Again, I'd be happy to run the little program for anybody that needs me to.

Enjoy!

## Recommendations

• ### Embroidery Class

9,861 Enrolled

## 19 Discussions

Absolutely amazing! I hope you'll update when the quilt is finished, I know it will be gorgeous - that is the perfect flower to make a quilt out of.

I'm saving this to my favorites - I've always wanted to make a photo quilt. :D

Hey, the create_quilt.py file is essentially empty (only 20 bytes long). What happened to the full program?

3 replies

Oh boy, good question. It should be a whole program, I'm not sure what happened to it. I'll check when I get home to see if I have it still.

No, nevermind. I saw the newer zip file available in a later step, and was able to download that no problem. Thanks a lot for replying though!

Oh, great. I'll just remove this file to avoid confusion.

I have a quick question if you're still checking this out from time to time. I am having a problem with the palette.jpg because I have it down to 30 colors but the palette is only showing 25 of them. I attached the image here so that you could see, just in case I'm missing something obvious.

Also, thanks so much for doing this, it's a huge help!

2 replies

Oops! You are absolutely correct! The palette.jpg.xxx.jpg files for each separate palette color are generated correctly, but the palette.jpg does not contain all of the squares.

The fix is a 2 line change in the create_quilt.py file:

Change the line
from math import sqrt, pow
to
from math import sqrt, pow, ceil

and
rows = int(sqrt(num_colors))
to
rows = int(ceil(sqrt(num_colors)))

Thanks so much! Now to just get started collecting the fabrics for this FF VII quilt.

can someone send me a step by step method on what to do and what to download , and where. duh . would really like to do a wedding quilt but can not figure this photographic quilt program

3 replies

Okay, on step 4 or so, now there is a 'create_quilt.zip' file that contains a stand alone executable file that will run the program. No need to install python or PIL. It's windows only for now. If you need to run on a mac, let me know, and I can do the same thing for the mac.

-Caleb

Hi there,
The program is not a 'point-and-click' simple program. You do have to go through the steps detailed in the instructable up to step 3 yourself, which includes choosing the image, reducing the resolution, and reducing the colors down to something manageable, like 30 colors.

I assume that you have done that. The next step is running the program. Oopsie! Looks like the 'create_quilt.py' file is broken. I need to re-upload it. Unfortunately, it's at home, so I'll have to do it tonight.

If you already have an image ready for 'quiltifying', you can send me a message and I'll run the program for you.

-Caleb

Hey Caleb and Errica,

It's pretty amazing that you've figured out how to program & do the process. Errica your quilt is going to be show-worthy. It's really starting to take shape. More! Show us another ujpdate.

Caleb. I want my own program!! Can you get it to me via your dad?

2 replies

Hi FufuMa,
Thank you!! I just went to the fabric store with the photo swatches that mostly match my big print out of the whole flower. You can see what I'm working off of to the left of the quilt blocks. I made sure that they fit what the computer was aiming for by looking at both the "map" and the real photo. I also picked what I liked together and changed the background that was mostly black to dark greens and blues. I also went with all batiks because they flow nicely together and each one has more than one color. The big block of mustardy yellow is going to be ripped out and replaced with a batik.

Hi fufu,
Programming is kinda my thang. :-) Anyway, here's another sneak preview. Also, I'll see if I can package the program in an easy way that you could use.

Wowie Kazowie!! Errica, it's gorgeous!! Were you able to select exactly 30 colors, or did you have to select several of a color to allow for fudge factor ... or does Caleb;s program give a result that's true to color? Fabric stores don't print RGB values on fabrics,so how do you gauge a fabric color to the RGB values?? Color wheel? Use colors as the printer sees them? Would love to know the answer to that.

Errica what is the finished size? And Caleb, does your program allow the user to plug in finished size &the work backwards from there to choose size of individual blocks? How do you control block size if you want a specific sized quilt? So many questions ...

The result is veryvery implressive!

Ya, looks to be shaping up really well so far. I think she's something like 1/20th done already :-)