View source: R/apply_fun_to_imgs.R
apply_fun_to_imgs | R Documentation |
Most of the functions in pliman can be applied to a list of images, but this can be not
ideal to deal with lots of images, mainly if they have a high resolution. For
curiosity, a 6000 x 4000 image use nearly 570 Megabytes of RAM. So, it would be
impossible to deal with lots of images within R. apply_fun_to_img()
applies a
function to images stored in a given directory as follows:
Create a vector of image names that contain a given pattern of name.
Import each image of such a list.
Apply a function to the imported image.
Export the mutated image to the computer.
If parallel is set to FALSE
(default), the images are processed sequentially, which
means that one image needs to be imported, processed, and exported so that the other
image can be processed. If parallel is set to TRUE
, the images are processed
asynchronously (in parallel) in separate R sessions (3) running in the background on
the same machine. It may speed up the processing time when lots of images need to be
processed.
apply_fun_to_imgs(
pattern,
fun,
...,
dir_original = NULL,
dir_processed = NULL,
prefix = "",
suffix = "",
parallel = FALSE,
workers = 3,
verbose = TRUE
)
pattern |
A pattern to match the images' names. |
fun |
A function to apply to the images. |
... |
Arguments passed on to |
dir_original, dir_processed |
The directory containing the original and processed
images. Defaults to |
prefix, suffix |
A prefix and/or suffix to be included in the name of processed
images. Defaults to |
parallel |
If |
workers |
A positive numeric scalar or a function specifying the number of parallel processes that can be active at the same time. Defaults to 3. |
verbose |
Shows the progress in console? Defaults to |
Nothing. The processed images are saved to the current working directory.
# apply_fun_to_imgs("pattern", image_resize, rel_size = 50)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.