You are here

Script or Plugin to Count Blocks

Hi everyone. I am I guess still a newbie with GIMP, Ive been using it for over a year now. Anyway, I am a designer of crochet patterns. I have a program that I create my pattern in, then I upload it to GIMP and tweak it. I also provide row-by-row instructions for each pattern. What that means is that I have to count each and every square and type it into a table.

My question is: Is there a script or plug in or even some other program that I could use to count the squares for me? Specifically, if I highlight a group of squares, it would tell me how many there are.

I have attached a sample pattern so you have an idea of what Im talking about.

Thanks!

Viktoria-Lyn

Edit: Ive uploaded a sample table. I have it as a template in Open Office.

AttachmentSize
Castle Pattern172.94 KB
Table for Castle Pattern103.19 KB
Simple Test Pattern75.28 KB
Simple Test Table81 KB
Script won't read315.79 KB
Wilbur Pat101.15 KB
Wilbur Fin66.41 KB

Would it not be better to have the script generate the table in its entirety? This is actually easier to accomplish than counting the squares in a selected region.

If so, could you provide an example of the table you need generated?

When working a pattern you read from right to left and then the next row is left to right.

Once I get something on my mind I can't rest until I have solved it-lol.

I noticed that when I click into a block and hold down the shift key and drag the mouse over a set of blocks, at the bottom of GIMP it gives me the total pixels. It counts each block as 6 pixels. After some mind bending (for me at least) calculations, I came up with this formula:

If the total is 48 pixels/6+1 gives me the blocks I need. The +1 is because it counts the first block I click in as zero. So far it has worked out perfectly, I just need to make sure I click squarely into the block or the count is off by 1 or 2.

If there was a way to generate a table and save me about 3 hours of work that would be awesome!

When working a pattern you read from right to left and then the next row is left to right.
But what are the "instructions" provided to the crocheter?
For example, your swan image has 50 white squares (L-R) on the first row, and on the second row (R-L): 6 white followed by 2 black followed by 24 white followed by 7 black followed by 11 white. How should this information be presented?

In the table that I uploaded, there are columns marked O and S. The white blocks are "O"pen mesh blocks and the black blocks are the "S"olid mesh blocks. I plug the numbers into the table with the row and the direction to read the chart if they so choose. So a crocheter would read Row 1 from the "R"ight and it would be 50. Then Row 2 from the "L"eft would be 11 Open/7 Solid/24 Open/2 Solid/6 Open.

The pattern is always read with the first row R-L and so on.

I have completed a first cut at the script. It is available for download from the top-most link on this page ([cfdc83f96a] at the time of this post). The command added can be found under "File->Create->Crochet Pattern by Viktoria".

After opening your pattern image, make a selection around just the grid itself and then run the script. It should spend some time scanning your image and then starts producing images containing your data tables. A separate image is created for every 23 rows of instructions. For your example swan image, the following two tables are produced:

http://www.kerosenecow.net/data/images/misc/swan-table.png

The script still needs some work, but I thought you might be able to take a look and see if I'm on the right track. (Note: the resulting images are not currently "undo-able". I don't know why this is but hope to resolve the problem soon.)

It looks just like what I need! But Im unclear how to download it? I went to the link and could not find a download? Sorry.

lol sorry, I found it. Im adding it to GIMP right now and will test it.

I have attached a screen shot. It generated 2 blank tables and then some errors. Not sure what I did wrong.

I also attached the pattern that I tried to use it on. I outlined the pattern and did a crop to selection so just the pattern showed.

I also uploaded the first 5 rows of the toe shoes pattern so you can compare.

I'm not sure why you are experiencing problems. When I run the script on your ballerina shoes image, the following is the first table:

http://www.kerosenecow.net/data/images/misc/shoes-table.png

This was produced with the latest version. In order to match the results of your sample table, I am assuming that the rows should proceed from the bottom of the image to its top.

I have reduced the number of rows per page to 20 so that there will be room for instructions at the top of the page. I've also added a thumbnail of the image to the upper right corner of each page.

It worked! Perfectly, Oh my gosh, I don't know how to thank you. This is going to save me a TON of time. I downloaded the latest version. I think my error was in not selecting the pattern before running the script. This is so awesome! I wish I was there to give you a hug!

If you wish changes to be made to the script, please create a ticket (AKA bug report) at the link below. I do not always notice new posts here on the GIMP Plugin Registry.

http://chiselapp.com/user/saulgoode/repository/script-fu/reportlist

Hi, I left a ticket at the link you gave but thought I would put something here also. Ive been using the script all day and spot checking the tables. I thought it was working great but after doing about 13 files and uploading them to my Etsy Shop I realized that one of them was wrong. So I scanned 3 more files and they all came out backwards. The table says Row 1 Right but the numbers read from the Left. I went back and looked at the ones I had already done and the very first file appears to be correct but all the rest appear to be wrong. Not sure what I did.

Please run the script on the toe-shoes.jpg image and verify that it produces the same table as shown here:

http://www.kerosenecow.net/data/images/misc/shoes-table.png

Also, could you post one of the patterns you are scanning and the resulting table (just the first page)? Also, is the script now always producing an incorrect result, or does it work on some patterns and not on others?

It still worked on the toe shoes. Ive uploaded the pattern that I first noticed it on. The first row should be 3-80-4 and its reading it backwards. It works on some but not all. I went back and checked a few of the patterns that I ran yesterday and some were correct and some were not.

I tried it on a very simple test pattern and it still read it backwards and only read 10 rows instead of the 50 that are on the pattern.

I have -- he said hopefully -- fixed the problem with the rows sometimes being backwards. Here is the resulting first page of the table for the castle pattern (let me know if this is not correct):

http://www.kerosenecow.net/data/images/misc/castle-table1.png

The new version of the script is located at:

http://chiselapp.com/user/saulgoode/repository/script-fu/artifact/854697...

As for the test pattern not being completely read, I was unable to repeat the error. Remember to make a selection around the pattern itself, such that there are no dark pixels within the selection that are not part of the pattern. Any text labels or other markings that are not part of the pattern grid should lie outside the selection. Your test.jpg image, for example, has some short diagonals in the lower-right corner. If these diagonals are included in the selection (or if you don't make a selection) then the script will become confused when it tries to scan the grid.

I reran the patterns I did yesterday. Out of 17 patterns only 4 were backwards, so that is terrific!!

I uploaded a another pattern. It would not read it yesterday and still won't read it today. I ran it like 8 times. It's not a big deal, I just wont offer row-by-row with this pattern. Im just curious why it won't read it so I can make sure I don't do anymore patterns like it.

The GIMP Error says:

Execution error for 'Crochet Pattern by Viktoria': Error: (:1) eval: unbound variable: thumbail-layer

I really, really appreciate all the work you have done on this for me. If there is any way I can help you (not sure how lol) please ask. Maybe test scripts or something? Thank you again :)

Here is the updated script (fixing a typographical error):

http://chiselapp.com/user/saulgoode/repository/script-fu/artifact/1a663e...

If your pattern editing software allows it, you might try saving your pattern files as PNG instead of JPG. JPEG works well for photographs but it is not well-suited for solid colored, hard lined images such as your patterns. Also, if your program allows it, try specifying a color other than gray for the grid lines (e.g., red or blue), leaving the pattern itself as black and white -- this might help the scanner better separate the pattern from the grid.

I don't know how hard it is, but if you were able to design a pattern based upon GIMP's mascot, Wilber, I'd enjoy seeing it.

Thank you for the updated script. I do have the ability to change the grid color. I tried red and it read the pattern wrong. On one sample row it read it as 148-1 and that is no where near what is actually on the pattern. The pattern software that I use only has jpg but I can open it in GIMP and resave it as a png so thats not a problem.

I was wondering how hard would it be to remove the thumbnail picture? On the larger patterns I end up with 18 pages. If you removed the thumbnail would it make less pages? In my pattern packet I include the chart anyway.

Uploaded files of Wilburs pattern and what it would look like finished. Pretty cute :) I might have to make this one.

"The pattern software that I use only has jpg but I can open it in GIMP and resave it as a png so thats not a problem."
Don't bother doing this; once the file is saved as JPEG, the damage is done. Converting it to PNG only saves the damaged image (and my script already tries to handle the damaged image). If there is an option for JPEG quality, use the highest value available.

Here is the updated script:

http://chiselapp.com/user/saulgoode/repository/script-fu/artifact/d3d332...

I have removed the thumbnail and increased the number of lines per page to 25.

Thanks for the Wilber.

Thank you so much. Im glad you like Wilbur. :)

Thanks for removing the thumbnail and adding the page numbers, that is awesome! It also seems to run faster now too.

Subscribe to Comments for "Script or Plugin to Count Blocks"