Page 1 of 1

Jigsaw puzzle solver

Posted: 2011-07-09T06:48:43-07:00
by jumpjack
I have a huge (6000 piecese) jigsaw puzzle I'm not able to finish, so I was thinking about getting some help from my PC. 8)
I was thinking about splitting the sample image:
Image


into a grid, based on pieces size:
Image

and then to compare each remaining piece to each square, of course rotating the piece in 4 positions. But I'm not quite sure if any existing free "duplicate images finder" would be able to determine that these two images are actually the "same":
Image

Image

So I think I'd need to use a different kind of grid which gets rid of "cavities" and "projections":
Image

How can I obtain such a grid from an image using ImageMagick?

And, once I have it, is it possibile to create several different files from it (one per piece)?

And, finally, does it exist an ImageMagick function to "fuzz compare" two images?



But actually, being able to create such a program would be really cool!
http://www.youtube.com/watch?v=BnGu3t5oNdA

In this video, OpenCV is used rather than ImageMagick; it's also free and opensource... but I can't find any source of the jigsaw solver!
Could imagemagick be used to create such a program?

Re: Jigsaw puzzle soler

Posted: 2011-07-09T08:35:51-07:00
by glennrp

Code: Select all

convert -crop 200x200 jigsaw.jpg tile%04d.ppm
mogrify -frame 20x20 tile*.ppm
Then do whatever you want with the tiles. Someone else
will have to suggest how to compare the pieces with the
tiles.

Re: Jigsaw puzzle soler

Posted: 2011-07-09T10:19:17-07:00
by fmw42
For cropping into multiple pieces, see above from glennrp and http://www.imagemagick.org/Usage/crop/#crop_tile

Add +repage if you do not need to keep the virtual canvas position, which may cause other problems with further processing.


IM has a compare function for two images the same size or for two different size images. But note that it is rotation sensitive. So any rotation may cause the compare to mismatch. Any way see

http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/script/comma ... age-search
http://www.imagemagick.org/Usage/compare/
http://www.imagemagick.org/Usage/compare/#statistics

For two same-sized images:
compare -metric rmse image1 image2 null:

other metrics are available (such as fuzz if transparency is involved) as well

For comparing two different size images, see

viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076

but add -subimage-search, since the above was created, the compare function for different size images has changed and requires this option to tell it to look for the best match of the smaller image in the larger one.

Re: Jigsaw puzzle solver

Posted: 2011-07-09T22:53:02-07:00
by anthony
There are many methods of comparing images. But for a jigsaw, I do not think just simply rotating the piece in 4 (90 degree) units will be enough. Can you be sure you actually get the 'piece' with exactly the right rotation?

As such you will need to look at a rotation invarient method of determining a pieces location.

This is not very simple, and involves transforming the images into a special form to do the search.
Including Polar transforms, Log transforms, and fourier transforms.

I have planned to look at this, but never see to get around to it.


Also in jigsaw puzzles you often get areas of blank or similarity (repeated parts). This type of search even if you have a copy of the final image, will only give you multiple possible locations, not a definitive location, which can only be determined by how the pieces join together, perhaps with some orientation help from small texture effects in the piece.

Re: Jigsaw puzzle solver

Posted: 2011-07-10T01:23:39-07:00
by jumpjack
anthony wrote:There are many methods of comparing images. But for a jigsaw, I do not think just simply rotating the piece in 4 (90 degree) units will be enough. Can you be sure you actually get the 'piece' with exactly the right rotation?
why not?
anthony wrote:As such you will need to look at a rotation invarient method of determining a pieces location.
The method used in above video would be indeed cool!
Also in jigsaw puzzles you often get areas of blank or similarity (repeated parts).
Of course images comparison is totally useless for single-color pieces, but I have a puzzle with hundreds of pieces (out of 6000) with plenty of lines and colors, but I can't position after months of "work".

Re: Jigsaw puzzle solver

Posted: 2011-07-10T07:02:25-07:00
by jumpjack
Does ImageMagick have any SIFT/SURF feature/implementation?

I found this cool SW... but I can't get it working in windows (can't get the .key files)

http://www.cs.ubc.ca/~lowe/keypoints/

Resources:
http://en.wikipedia.org/wiki/Speeded_Up_Robust_Features

Re: Jigsaw puzzle solver

Posted: 2011-07-10T09:49:09-07:00
by el_supremo
It works in Win7 Pro for me. In a DOS window just use the command:

Code: Select all

siftwin32 <book.pgm >book.key
Pete

Re: Jigsaw puzzle solver

Posted: 2011-07-10T10:00:20-07:00
by jumpjack
el_supremo wrote:It works in Win7 Pro for me. In a DOS window just use the command:

Code: Select all

siftwin32 <book.pgm >book.key
Pete
This is very weird: of course I tried this example, but I always got a PGM file inside the .key file, and the program output itself said "PGM file created" or something like that.
Now I just tried... and it works properly. :shock:

I can't understand. :shock:

Re: Jigsaw puzzle solver

Posted: 2011-07-10T10:06:34-07:00
by jumpjack
Damn, I added (erroneously) the -display switch!!! :shock: RTFWM!!! (W=Whole :lol: )

Re: Jigsaw puzzle solver

Posted: 2011-07-10T11:15:50-07:00
by fmw42
You could try using the plugin for Surf in ImageJ

Re: Jigsaw puzzle solver

Posted: 2011-07-10T11:44:18-07:00
by jumpjack
Since I installed Nokia OVI Suite I can't run any java program, as .JAR is nowassociated to "installation on phone"! :(

Re: Jigsaw puzzle solver

Posted: 2011-07-11T03:52:11-07:00
by whugemann
Your problems with Java aside -- I also think that ImageJ is the right program for ready-made solutions on special problems like this. I used its SIFT tools to settle a very shaky video and found them doing amazingly well.