Photos

Mosaic ↓

Choosing photos replaces the set. Change uses per photo under Matching.

Target picture

Sunflower: example photos, 1,200 cells, up to 3 uses per photo, 45% tint.

Mosaic

The mosaic appears here.

Matching

How this works

The mosaic matches each grid cell to a photo in six steps:

  • Grid. With n photos and a target of shape a (height ÷ width), the grid has ⌊√(n/a)·a⌋ rows and ⌊√(n/a)⌋ columns, so it never has more cells than photos. Extra photos are left out.
  • Cells. The target is scaled to one pixel per cell, each pixel the average of the area it covers.
  • Photos. Each photo is scaled to 200 pixels wide and summarised by its average colour.
  • Cost. Both are turned into hue, saturation, lightness and opacity, and a cell's cost for a photo is the sum of the squared differences. Hue is in degrees and lightness is scaled down by 255, so the match is mostly by hue, then saturation. The CIELAB option compares perceived lightness and colour instead.
  • Assignment. Each cell gets its own photo, so that the total cost over all cells is as small as possible: the linear assignment problem, solved exactly by the Hungarian algorithm. Photos are first shuffled with the seed, which matters only between equal costs.
  • Drawing. Each photo is drawn at the tile width with its own shape, rows as tall as their tallest photo. Cropping to squares and tinting towards the target are options here, off by default.

The same photos, settings and seed reproduce the same assignment. JPEG colours can vary slightly between browser decoders. Photos larger than 400 pixels wide, and targets larger than 1600 pixels, are first halved in the browser.

The mosaic is also available to scripts and agents: see the API description. The example is Hokusai's Red Fuji and CC0 photographs from Wikimedia Commons (sources).