Create a 2D LEGO mosaic from an image array

image_to_mosaic(img, img_size = 48, color_table = NULL,
  method = "cie94", color_palette = c("universal", "generic",
  "special"), dithering = FALSE, contrast = 1, use_bricks = NULL,
  brightness = 1, warhol = 1:3)



Image to convert into mosaic. Usually from jpeg::readJPEG() or png::readPNG().


Size of output image in pixel, where one pixel = one 'brick'. Use a single value (e.g. 48) for a square image with 48 pixels on each side. Use an array of two values for a rectangular image c(width, height).


Defaults to lego_colors. Data frame of brick colors to map onto image. Must contain Name and R, G, B channels. See attached data lego_colors as examples.


The method to use for comparison. Either 'brickr_classic', 'euclidean', 'cie1976', 'cie94', 'cie2000', or 'cmc'. 'brickr_classic' is an explicit euclidean distance formula, but yield different results than 'euclidean' in farver. See farver::compare_colour.


Brick color rarity to use. Defaults to all colors: 'universal' (most common), 'generic', and 'special' (least common). This is useful when trying to build the mosaic out of real bricks. Use "bw" for only grayscale bricks. Ignored if a color_table is supplied.


Improves color of large, photo-realistic mosaics.


For theme = "bw". A value >1 will increase the contrast of the image while a positive value <1 will decrease the contrast.


Array of brick sizes to use in mosaic. Defaults to c('4x2', '2x2', '3x1', '2x1', '1x1')`.


A value >1 will increase the brightness of the image while a positive value <1 will decrease the brightness.


Array of values c(1, 2, 3) associated with R, G, B color channels. Swap values in array to swap color channels for a fun visual effect.


A list with element Img_lego containing a data frame of the x- & y-coordinates, R, G, B channels, and mapped color of each brick (pixel).

See also

Other Mosaics: build_mosaic