Function Repository Resource:

Jigsaw

Source Notebook

Turn an image into a jigsaw puzzle

Contributed by: Jason Yap

ResourceFunction["Jigsaw"][img]

adds interlocking jigsaw puzzle pieces based on recognizable features to the image img.

ResourceFunction["Jigsaw"][image,num]

creates num interlocking jigsaw puzzle pieces traced out in each of the horizontal and vertical directions.

Details

ResourceFunction["Jigsaw"] uses ImageKeypoints for detecting recognizable features using the AGAST algorithm.
Randomness is used to introduce slight perturbations to the positions of the grid points to ensure that the jigsaw pieces are not uniform.
The noisy grid points form a basis for generating a Voronoi mesh composed of slightly irregular polygons.
Any image of any dimension is acceptable, the computation time depends on size.

Examples

Basic Examples (2) 

Returns original image with each tile having a recognizable feature:

In[1]:=
ResourceFunction["Jigsaw"][
 Entity["FictionalCharacter", "SpongeBob"][
  EntityProperty["FictionalCharacter", "Image"]]]
Out[1]=

Returns original image with 2 x 2 jigsaw puzzle piece tiles:

In[2]:=
ResourceFunction["Jigsaw"][
 Entity["FictionalCharacter", "SpongeBob"][
  EntityProperty["FictionalCharacter", "Image"]], 2]
Out[2]=

An arbitrary Image can be used:

In[3]:=
ResourceFunction["Jigsaw"][Image[Graphics[{White, Rectangle[]}]], 3]
Out[3]=

Properties and Relations

Each disk is a recognizable feature and each puzzle piece has at least part of the disk, so that each piece has a recognizable feature.

In[4]:=
i = Image[
  Graphics[{Red, Disk[{0, 0}, 1], Disk[{3, 0}, 1], Disk[{0, 3}, 1], Disk[{3, 3}, 1]}]]
Out[4]=
In[5]:=
ResourceFunction["Jigsaw"][i]
Out[5]=

Possible Issues (1) 

An Image must be used, not a Graphic:

In[6]:=
ResourceFunction["Jigsaw"][Graphics[{White, Rectangle[]}]]
Out[6]=

Publisher

Jason Yap

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.0 – 07 August 2024

Source Metadata

Related Resources

License Information