Talk

Fast Jigsaw Puzzle Solving with Python: From CV Algorithms to Applications

LanguageEnglish
Audience levelIntermediate
Elevator pitch

Curious about how to solve 2D jigsaw puzzles, but in a Pythonic way?

Join me in a discussion about designing complex computer-vision based solutions such as time series analysis using NumPy and OpenCV, and explore its real-world applications in fragment stitching and artifact restoration!

Abstract

Do you find doing jigsaw puzzles fun and relaxing? Many do—until the number of pieces grows from dozens to thousands, or even millions. Suddenly, what starts as a leisurely activity quickly becomes an overwhelming and near-impossible challenge!

Such are the problems commonly faced in fields like archaeology and palaeography, where reconstructing fragmented artifacts or partial manuscripts is a crucial and essential task. Fortunately, Python and its robust image processing libraries have provided many out-of-the-box tools specifically designed for extracting and comparing features presented in a typical image setting, which, if utilized properly, can revolutionize how matching candidates for a given puzzle piece are located in a random dataset. Libraries like OpenCV and Numpy in particular, which are built on C/C++ infrastructure, also guarantees efficient computations for basic mathematical operations and matrix calculations. These can prove quite indispensable when working with massive image datasets including millions of items and billions of potential piecewise permutations, where speed becomes a critical bottleneck.

In this talk, I will present my latest research on puzzle solving and fragment reassembly through curve-matching techniques, showcasing how CV algorithms might be organized and implemented into real-world applications. The computational model I propose for solving the jigsaw problem leverages a multi-step algorithmic approach:

1). Contour extraction with morphological operations and Canny edge detection. 2). Gaussian filtering combined with Douglas-Peucker polygon approximation. 3). Rapid polygon-segment matching using cosine similarity. 4). Segment-wise alignment with a weighted adaptation of the LCSS distance metric. 5). Collision detection and angle correction for fine-tuning result and scoring.

To maximize performance, the model adopts a coarse-to-fine process, utilizing multi-layered filtering and C-language like tools in Python. For operations where NumPy are unsuitable to solve, pybind11 is also introduced for importing custom functions written in C++ into main Python script, ensuring a finer level of control with zero computational overhead. This combinatorial approach ensures the piecewise comparison for any two images can be conducted in matters of milliseconds, even for object contours that have thousands of points.

TagsComputer Vision, Algorithms and Data Structures, Scientific Python
Participant

Peichao Qin

I am currently a PhD student at the Faculty of Asian and Middle Eastern Studies at the University of Cambridge. My dissertation focuses on the digitalization of Shang oracle bones stored at Cambridge University Library. In my leisure, I am also a computer science enthusiast and a full-stack web developer.