Convert an SpatRaster
to a three-band RGB image of class Image
.
Arguments
- mosaic
A mosaic of class
SpatRaster
, generally imported withmosaic_input()
.- r, g, b
The red, green, blue bands.
- coef
An addition coefficient applied to the resulting object. This is useful to adjust the brightness of the final image. Defaults to 0.
- plot
Logical, whether to display the resulting RGB image (default: TRUE).
Details
This function converts SpatRaster
that contains the RGB bands into
a three-band RGB image using pliman (EBImage). It allows you to specify the
band indices for the red, green, and blue channels, as well as apply a
scaling coefficient to the final image. By default, the resulting RGB image
is displayed, but this behavior can be controlled using the plot
parameter.
Examples
if (interactive() && requireNamespace("EBImage")) {
library(pliman)
# Convert a mosaic raster to an RGB image and display it
mosaic <- mosaic_input(system.file("ex/elev.tif", package="terra"))
# Convert a mosaic raster to an RGB image without displaying it
rgb_image <- mosaic_to_rgb(c(mosaic * 2, mosaic - 0.3, mosaic * 0.8))
plot(rgb_image)
}
#> Warning: The current raster is in the lat/lon coordinate system, which may result in processing errors when trying to segment individuals in the `mosaic_analyze()` function. It is highly suggested to reproject the raster using mosaic_project() with EPSG:32632
#> class : SpatRaster
#> dimensions : 90, 95, 1 (nrow, ncol, nlyr)
#> resolution : 0.008333333, 0.008333333 (x, y)
#> extent : 5.741667, 6.533333, 49.44167, 50.19167 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source : elev.tif
#> name : elevation
#> min value : 141
#> max value : 547