This repository is home to optimization and image processing code that approximates a given image (could be color or grayscale) with a mosaic in complete sets of double-nine dominoes.
For example, consider the image on the left of a young Hank Marvin from his days with The Shadows. Code in this repository was used to generate two mosaics (see picture in the middle and on the right -- zoom in to see the tiles), each in 12 complete sets of 55 double-nine dominoes, as a pointillistic representation of the black-and-white photo of Hank.
To learn more about domino mosaics, both the art form and its interpretation as the solution to an integer program, watch mathematician-artist Robert Bosch of Oberlin College give this talk at Google.
-
First, create a library of images for each domino in a set of 55 double-nine dominoes.
-
CODE:
Code/Octave/createDominoSet.m
-
TO RUN CODE:
- Open Terminal and change current directory to
Code/Octave/
. - Open Octave by entering
octave
at the terminal. - To generate images of black domino tiles with white dots, run the octave code by entering
createDominoSet('white')
. To generate images of white dominoes with black dots, change input argument to'black'
.
- Open Terminal and change current directory to
-
OUTPUT: A MATLAB (and Octave) compatible
.mat
file inData/Domino_Set_Images
. -
Run code once for each tile color. The images (more precisely, a cell array of matrices representing the domino images) are saved to
Data/Domino_Set_Images/dominoes_with_white_dots_V7.mat
andData/Domino_Set_Images/dominoes_with_white_dots_V7.mat
.
-
-
Next, choose a target image. Crop the image to accomodate multiple complete sets of dominoes -- the exact number needs to be calculated manually and will depend on the cropped image dimensions. Then run this next code to perform some image processing and obtain a compressed, grayscale version of the image.
-
CODE:
Code/Octave/preprocessImage.m
-
TO RUN CODE:
- Open Terminal and change current directory to
Octave_scripts
. - Open Octave by entering
octave
. - Run code by entering
preprocessImage ('HM')
.
- Open Terminal and change current directory to
-
INPUT:
- Input parameter
'HM'
directs the code to look for the target imageHM.jpg
(cropped photo of Hank) inData/Target_Images/
. - The code will ask the user to manually enter (i) dimensions
m
andn
of the domino portrait. These dimensions are such thatmn = 110s
, wheres
is the number of complete sets used in the image, and (ii)k
, the size of each square cell, such thatmk
equals the height (in pixels) andnk
equals the width (also in pixels) of the cropped image. For example, for Hank's potrait, setm
to 40,n
to 33, andk
to 10. This means, in the next step, the optimization code will be usings
= 12 complete sets of double-nine dominoes to generate the final mosaic.
- Input parameter
-
OUTPUT: A scaled and compressed image file
Data/Compressed_Images/HM.txt
in the form of a matrix of integers ranging from 0 and 9.
-
-
Finally, approximate a greyscale image with
s
sets of double-nine dominoes by solving a binary integer program.-
CODE:
Code/Julia/ModuleDominoes.jl
-
TO RUN CODE:
- Open Terminal and change current directory to
Code/Julia/
. - Open Julia by entering
julia
at the command line. - Enter the following commands.
julia> include("ModuleDominoes.jl") julia> using .Dominoes julia> dominoes("HM", "white", "constrained")
- Open Terminal and change current directory to
-
INPUT: The input parameter
"constrained"
indicates that all dominoes in thes
complete sets,55s
to be precise, will be used to generate the final mosaic. Setting this last parameter to"unconstrained"
indicates to the code that the mosaic is to be built from an unlimited supply of dominoes, which naturally does not make for an interesting optimization problem. The second input parameter (in this example,'white'
) indicates the color of the dots on the dominoes. -
OUTPUT: The code will generate the image
Data/Mosaic_Images/HM_white_constrained.png
, a mosaic in black domino tiles with white dots.
-
The image of Hank Marvin is cropped from a group photo of The Shadows that appears in the public domain.
- This book review in the Scientific American of Robert Bosch's book Opt Art is a great start if you're diving into Bob's world of pointillism-via-optimization.
- Details on how to model the integer program can be found in the article "Constructing Domino Portraits" in "Tribute to a Mathemagician".
- Check out all of Bob Bosch's Mathematical Art and the art of his inspiration, Ken Knowlton.