Phomo
Photo mosaic generation library.
Usage
To build a photo mosaic, you'll need a master image as well a bunch of so called tile images. The tile images will be arranged to best reconstruct the master image.
The master image is initialized with the [Master] struct.
The tile images can be loaded using some helper functions:
- [
read_images_from_dir] - [
read_images_from_dir_cropped] - [
read_images_from_dir_resized]
The photo mosaic can be constructed using the [Mosaic] struct.
Examples
I'll be using this 256x256 image as master image:
And for the tile images, we'll be using a susbset of the UTKfaces dataset.
Basic mosaic
Build a 12x12 photo mosaic.
use ;
let master_file = "tests/data/master/master.png";
let grid_size = ;
let max_tile_occurrences = 1;
let master = from_file.unwrap;
let tile_dir = "tests/data/mosaic/faces/";
let tiles = read_images_from_dir_cropped.unwrap;
let mosaic = new.unwrap;
let distance_matrix = mosaic.distance_matrix;
let mosaic_img = mosaic.build;
With repeated tiles
use ;
let master_file = "tests/data/master/master.png";
let grid_size = ;
let max_tile_occurrences = 2;
let master = from_file.unwrap;
let tile_dir = "tests/data/mosaic/faces/";
let tiles = read_images_from_dir_cropped.unwrap;
let mosaic = new.unwrap;
let distance_matrix = mosaic.distance_matrix;
let mosaic_img = mosaic.build;
Palette transfer - Tiles to master
Build a 8x8 photo mosaic, with palette transfer of the master image to the tile images. The color of the tiles will be adjusted to match the color distribution of the master image.
use ;
let master_file = "tests/data/master/master.png";
let grid_size = ;
let max_tile_occurrences = 1;
let master = from_file.unwrap;
let tile_dir = "tests/data/mosaic/faces/";
let mut tiles = read_images_from_dir_cropped.unwrap;
tiles = tiles.match_palette;
let mosaic = new.unwrap;
let distance_matrix = mosaic.distance_matrix;
let mosaic_img = mosaic.build;
Palette transfer - Master to tiles
Build a 12x12 photo mosaic, with palette transfer of the tile images onto the master image. The color of the master image will be adjusted to match the color distribution of the tile images.
use image;
use ;
let master_file = "tests/data/master/master.png";
let grid_size = ;
let max_tile_occurrences = 1;
let master_img = open.unwrap.to_rgb8;
let cell_size = ;
let tile_dir = "tests/data/mosaic/faces/";
let tiles = read_images_from_dir_cropped.unwrap;
let master = from_image.unwrap;
let mosaic = new.unwrap;
let distance_matrix = mosaic.distance_matrix;
let mosaic_img = mosaic.build;
Color Normalization
Build a 12x12 photo mosaic, with color distribution normalization. The colors of both the master image and tiles images will be adjusted to cover the full color space.
use image;
use ;
let master_file = "tests/data/master/master.png";
let grid_size = ;
let max_tile_occurrences = 1;
let master_img = open.unwrap.to_rgb8;
let master = from_image.unwrap;
let tile_dir = "tests/data/mosaic/faces/";
let mut tiles = read_images_from_dir_cropped.unwrap;
tiles = tiles.equalize;
let master = from_image.unwrap;
let mosaic = new.unwrap;
let distance_matrix = mosaic.distance_matrix;
let mosaic_img = mosaic.build;