Title: | Make packed image mosaics |
---|---|
Description: | impac takes a list of images or a function that generates images and packs them onto a canvas using a greedy algorithm, while respecting transparency. |
Authors: | Russell Dinnage [aut, cre, cph] |
Maintainer: | Russell Dinnage <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2024-10-25 05:03:00 UTC |
Source: | https://github.com/rdinnager/impac |
A simple greedy algorithm tries to pack as many images into a larger image as possible, taking into account transparency, if available (recommended).
impac( im, width = 1024, height = 800, mask = NULL, weights = NULL, preferred = NULL, max_num_tries = 100, scales = c(rep(0.5, 2), rep(0.25, 4), rep(0.15, 8)), scale_fun = function(s, i, c) { if (c < (i * 0.5)) { mscale <- min(s) c(s, rep(mscale/2, floor(1/mscale))) } else { scales } }, max_images = 1000, min_scale = 0.05, bg = "transparent", show_every = 25, progress = TRUE, start_image = NULL, ... )
impac( im, width = 1024, height = 800, mask = NULL, weights = NULL, preferred = NULL, max_num_tries = 100, scales = c(rep(0.5, 2), rep(0.25, 4), rep(0.15, 8)), scale_fun = function(s, i, c) { if (c < (i * 0.5)) { mscale <- min(s) c(s, rep(mscale/2, floor(1/mscale))) } else { scales } }, max_images = 1000, min_scale = 0.05, bg = "transparent", show_every = 25, progress = TRUE, start_image = NULL, ... )
im |
Can be either a character vector of image
file names (format must be compatible with |
width |
Width in pixels of produced image |
height |
Height in pixels of produced image |
mask |
An optional masking image. |
weights |
Vector of Weights to apply to each image. Higher weighted images will be packed first and so will tend to be larger. This vector will be recycled. |
preferred |
An alternate way to specify images to pack first, as
a character vector of names or file names (only works if |
max_num_tries |
Maximum number of times to try packing an image onto the canvas before giving up. |
scales |
A vector of starting scaling factors to randomly choose from for each image. |
scale_fun |
An function that takes three arguments,
which correspond to the current vector of scaling factors, the current
iteration of the algorithm, and the count of the number of packed images
so far, respectively (e.g. |
max_images |
The maximum number of images to pack before stopping. |
min_scale |
The minimum scale factor to use. If the algorithm
generates a scale factor this small (via |
bg |
The background colour for the campus, default: "transparent" |
show_every |
Show the intermediate packed image after every
|
progress |
Should progress be printed as the algorithm runs? |
start_image |
An optional image to start the packing with. If not
|
... |
Further arguments passed on the |
A packed image mosaic, as a imager::cimg
object.
plot( impac( function(i) imager::draw_circle( imager::imfill(500, 500, val = c(0, 0, 0, 0)), 250, 250, radius = runif(1, 150, 250), color = matrix(grDevices::col2rgb(sample(grDevices::rainbow(100), 1), alpha = TRUE), nrow = 1) ), width = 400, height = 400, max_images = 10, bg = "white" )$image )
plot( impac( function(i) imager::draw_circle( imager::imfill(500, 500, val = c(0, 0, 0, 0)), 250, 250, radius = runif(1, 150, 250), color = matrix(grDevices::col2rgb(sample(grDevices::rainbow(100), 1), alpha = TRUE), nrow = 1) ), width = 400, height = 400, max_images = 10, bg = "white" )$image )
impac
objectsClear any cached impac
objects
impac_clear_cache()
impac_clear_cache()
No return value
impac_clear_cache()
impac_clear_cache()
Function to try and rescue
impac_recover()
impac_recover()
Function to resume an image packing where it left off
impac_resume(x = NULL, ...)
impac_resume(x = NULL, ...)
x |
An |
... |
Other arguments to be passed to |
An impac
object
Save packed image mosaic
impac_write(x, file, quality = 0.7)
impac_write(x, file, quality = 0.7)
quality |