Crops an image (or matrix) either by specifying axis-aligned limits
(width_limits
/height_limits
) or by specifying a centered box size via center
.
render_crop(
image = NULL,
width_limits = NULL,
height_limits = NULL,
center = NULL,
filename = NULL,
preview = FALSE
)
Default NULL
. 3-layer RGB/4-layer RGBA array, rayimg
class, or filename of an image.
Default NULL
. Length-2 numeric (xmin, xmax)
along the width (x/columns).
Values in [0,1]
are treated as fractions of image width; otherwise they are pixel indices.
Mutually exclusive with center
. If provided alone, height_limits
defaults to full height.
Default NULL
. Length-2 numeric (ymin, ymax)
along the height (y/rows).
Values in [0,1]
are treated as fractions of image height; otherwise they are pixel indices.
Mutually exclusive with center
. If provided alone, width_limits
defaults to full width.
Default NULL
. Length-2 numeric (height, width)
for a center-crop.
Values in (0,1]
are treated as fractions of (image height, image width)
; otherwise pixels.
Mutually exclusive with width_limits
/height_limits
.
Default NULL
. The filename of the image to be saved. If this is not given, the image will be plotted instead.
Default FALSE
. Whether to plot the cropped image, or just to return the values.
A rayimg
array with the cropped region.
# Left half of the image
if(run_documentation()){
render_crop(dragon,
width_limits = c(0, 0.50),
height_limits = c(0, 1)) |>
plot_image()
}
# Right half of the image
if(run_documentation()){
render_crop(dragon,
width_limits = c(0.50, 1),
height_limits = c(0, 1)) |>
plot_image()
}
# Top middle of the image (25%–50% height, 25%–75% width)
if(run_documentation()){
render_crop(dragon,
height_limits = c(0.25, 0.50),
width_limits = c(0.25, 0.75)) |>
plot_image()
}
# Top middle, explicit pixel coords (for a 200x200 image)
if(run_documentation()){
render_crop(dragon,
height_limits = c(50, 100),
width_limits = c(50, 150)) |>
plot_image()
}
# Center-crop: 50% height and width of the image
if(run_documentation()){
render_crop(dragon, center = c(0.5, 0.5)) |>
plot_image()
}
# Center-crop: fixed 50x100 pixels
if(run_documentation()){
render_crop(dragon, center = c(50, 100)) |>
plot_image()
}