image_mosaic() creates a 4-image mosaic composite (2x2 grid) by cropping
a quadrant from 4 input images and stitching them together onto a single
canvas with an adjustable overlap (defaults to 20%). It seamlessly handles
coordinate alignment, feathering or overlay blending in the overlap zones,
and translation/clipping of YOLO bounding box or polygon annotations.
Usage
image_mosaic(
...,
images = NULL,
pattern = NULL,
path = NULL,
labels = NULL,
width = NULL,
height = NULL,
overlap = 0.2,
min_area_ratio = 0.1,
crop_region = c("quadrant", "random", "center"),
blend = c("none", "feather", "overlay"),
sample = FALSE,
return_list = FALSE,
plot = TRUE,
verbose = TRUE
)Arguments
- ...
Image objects, character paths to image files, or a list of images.
- images
An optional list of
Imageobjects or character vector of file paths.- pattern
An optional regular expression pattern to select image files from
path.- path
An optional directory path where image files are located.
- labels
Optional YOLO annotations corresponding to the 4 input images. Can be a character vector of 4
.txtlabel file paths, or a list of 4 character vectors where each element contains lines of YOLO formatted annotations (class x_center y_center width heightorclass x1 y1 x2 y2 ...).- width, height
Target dimensions (width and height in pixels) of the output mosaic canvas. Defaults to the dimensions of the first input image.
- overlap
Fraction of overlap between adjacent tiles (default
0.20, i.e., 20%). Can be a single numeric value or a vector of two valuesc(overlap_x, overlap_y).- min_area_ratio
Minimum visible area fraction (between 0 and 1) required to retain an object cut by mosaic quadrant seams. Default is
0.10(10 percent).- crop_region
Region to crop from each input image:
"quadrant"(default): Image 1 crops top-left, Image 2 crops top-right, Image 3 crops bottom-left, Image 4 crops bottom-right."random": Random crop of size(1 + overlap) / 2from each image."center": Center crop of size(1 + overlap) / 2from each image.
- blend
Blending mode for the overlapping regions:
"feather"(default): Linear alpha cross-fading across the overlap seam."overlay": Sequential overlay where subsequent tiles cover previous ones."none": Hard cut at the canvas midpoint.
- sample
Logical. If more than 4 images are provided, whether to randomly sample 4 images (
TRUE) or use the first 4 (FALSE, default).- return_list
Logical. If
TRUE, returns a named list withimageandlabels. IfFALSE(default), returns the compositeImageobject with the transformed annotations attached as an attributeattr(out, "labels").- plot
Logical. Whether to display the resulting mosaic. Defaults to
TRUE.- verbose
Logical. Whether to display informative progress/messages. Defaults to
TRUE.
Value
An Image object of class c("pliman_mosaic", "Image") (with attr(out, "labels")
containing transformed annotations if labels were provided), or a list containing
$image and $labels if return_list = TRUE.
Author
Tiago Olivoto tiagoolivoto@gmail.com
Examples
if (FALSE) { # \dontrun{
library(pliman)
# Mosaic from 4 sample images with 20% overlap
im1 <- image_pliman("sev_leaf.jpg")
im2 <- image_pliman("sev_leaf_nb.jpg")
im3 <- image_pliman("sev_healthy.jpg")
im4 <- image_pliman("sev_sympt.jpg")
mos <- image_mosaic(im1, im2, im3, im4, overlap = 0.20)
} # }
