Estimates a metric-aligned relative 3D depth map from any 2D RGB image using the state-of-the-art Depth Anything V2 foundation model running purely via ONNX Runtime.
Usage
image_depth_dl(
img,
model = "depth-anything-v2",
col_palette = "magma",
invert = FALSE,
threads = 0,
engine = c("gpu", "cpu"),
device_id = -1,
verbose = TRUE,
plot = TRUE,
dir = pliman_model_dir(),
...
)Arguments
- img
An
Imageobject, a 2D/3D numeric array, a path to an image file, or a list of images.- model
Model name or path to a custom ONNX file. Defaults to
"depth-anything-v2".- col_palette
Color palette used to visualize the depth map when
plot = TRUE. Options include"viridis","magma","inferno","plasma","spectral", or a custom vector of colors.- invert
Logical. If
TRUE, inverts the depth map so near objects are darker. Defaults toFALSE.- threads
Number of CPU threads (default 0 for auto-tuning).
- engine
Execution engine:
"cpu"or"gpu"(DirectML).- device_id
GPU device ID (default -1 for auto).
- verbose
Logical. Whether to show progress messages.
- plot
Logical. Whether to plot the resulting depth heatmap.
- dir
Model directory (default
pliman_model_dir()).- ...
Additional arguments passed to
graphics::plot().
Value
An Image object representing the colorized depth map, with the raw normalized
depth matrix stored in the "depth" attribute (attr(res, "depth")).
Examples
if (FALSE) { # interactive()
library(pliman)
img <- image_import("leaf.png")
depth <- image_depth_dl(img)
}
