Skip to content

Create Your Own Mosaic

Seth Benton edited this page Jul 12, 2013 · 7 revisions

The following steps walk you through creating your own mosaic.

  1. Choose a target image. Though the Fractal Mosaic algorithm, by design, can produce mosaics that capture more detail than traditional photomosaics, like with traditional photomosaics, the best mosaics usually have target images that aren’t too complex (e.g. a face, landscape, etc.). More complex target images can definitely be used, but you’ll need some expertise to tweak the parameters to accomplish this. Currently, the target image must have a height in pixels that is a factor of 1024. For example, the example from the README target image has a height of 3072 pixels (3 x 1024). This is not an inherent limitation of the algorithm. It just made the implementation easier.

  2. Prepare library images. If you’re using the library images that come with the example, you can skip this step. The algorithm uses square 256x256 pixel JPEG images. If creating a color mosaic, they need to be color (obviously). If creating a black and white mosaic, the library images need to be black and white (i.e. greyscale) JPEGs.

  3. Calculate library image statistics. If you're using the library images that come with the example, you can skip this step. Fractal Mosaics computes the following statistics for each library image: General Fourier Descriptor (GFD), standard deviation, histogram, and DC value. These are precomputed for efficiency using the following m-files: General Fourier Descriptors (gfd_calc.m), standard deviation (std_calc.m), histogram (histogram_calc.m), and DC values (DC_calc.m). Note that you'll need to change the 'path' variable in each script to point to your image library. You'll also need to change the name of the .mat variable being saved at the end of each file. For example, instead of saving standard deviation values to 'std_matrix_graffiti_128', you'll want to save to something like 'std_matrix_NEW_IMAGE_SET_128'. Additionally, you'll want to change fractal_mosaic.m to load these new statistics (not the graffiti statistics). These variables are loaded on lines 23,218, 224, and 227.

  4. Change paths to target and library images. Specify the path to the target image with the ‘target_path’ parameter. Specify the path to the library images with the ‘path’ parameter. The script assumes that library images are stored in subfolders under the path specified in ‘path’. This is because most operating systems will limit the number of files stored in a folder/directory, and most projects will use more library images than can be stored in one folder.

  5. Set parameters. The default parameters should work well for most mosaics if the target image isn’t too complex. However, you’ll probably want to tweak at least a couple important parameters to get optimal output. See the Variables page for info on how to do this.

  6. Navigate to the /m-files directory and run the script: fractal_mosaic.m. The mosaic is rendered while the images are being chosen and saved to the variable ‘Render_target’. This is then saved to a JPEG with the filename ‘fractal_mosaic .jpg’ on the last line of the script (remember to change this filename each time you run the script to avoid writing over you last mosaic!). The entire workspace is saved in a .mat file.

  7. (Optional) Post processing. A lot of effort has gone into automating the entire process. However, this required tradeoffs that place limits on what can be done artistically in the final (fully automated) mosaic. Therefore, several features were incorporated to give you more flexibility. One feature allows you to save “alternative” matches (i.e. matches which were below the rms error threshold (and thus good enough to be incorporated into the mosaic), but did not have the lowest rms error for a given pixel). These images, along with the matches making up the fully automated mosaic, can be output to individual PNGs by the ‘X....’ script. These PNGs can then be batch input into Photoshop, or other image processing program of your choice for further manual tweaking.

Clone this wiki locally