Skip to contents

Upscales images using state-of-the-art deep convolutional and modulation neural networks (including Real-ESRGAN, Real-ESRGAN Full, and PureScale SAFMN Spatially-Adaptive Feature Modulation) with intelligent tiled overlapping to prevent GPU/CPU memory exhaustion.

Usage

image_superres_dl(
  img,
  model = "realesrgan_x2_full",
  scale = NULL,
  tile_size = 256,
  tile_pad = 16,
  threads = 0,
  engine = c("gpu", "cpu"),
  device_id = -1,
  verbose = TRUE,
  plot = TRUE,
  dir = pliman_model_dir(),
  ...
)

Arguments

img

An Image object, a 2D/3D numeric array, a path to an image file, or a list of images.

model

Super-resolution model name or path to a custom ONNX file. Built-in options:

  • "realesrgan_x2_full" (default): Full Real-ESRGAN perceptual network for 2x super-resolution (RRDBNet, photorealistic quality).

  • "SAFMN2x": PureScale 2x Spatially-Adaptive Feature Modulation Network for lightweight, artifact-free 2x upscaling.

  • "SAFMN2x_sharper": PureScale 2x SAFMN with enhanced high-frequency modulation for crisp boundary and fine texture reconstruction.

  • "SAFMN4x": PureScale 4x SAFMN for high-magnification 4x super-resolution with feature modulation.

  • "realesrgan_x4_full": Full Real-ESRGAN perceptual network for 4x super-resolution (RRDBNet, high-fidelity texture synthesis).

  • "realesrgan" (or "realesrgan-compact"): Ultra-fast, lightweight 4x generative super-resolution (SRVGG, ~4.9 MB).

scale

Desired upscaling factor. Defaults to NULL, which automatically infers the model's native scale (2x for 2x models, 4x for 4x models). If a different scale is provided (e.g., scale = 3 or scale = 8), the neural output is resized to the target scale using high-quality Lanczos interpolation.

tile_size

Processing tile size in pixels (default 256).

tile_pad

Overlap margin in pixels for seamless blending between adjacent tiles (default 16).

threads

Number of CPU threads (default 0 for auto-tuning).

engine

Execution engine: "gpu" (DirectML) or "cpu".

device_id

GPU device ID (default -1 for auto).

verbose

Logical. Whether to show progress messages.

plot

Logical. Whether to plot the super-resolved image.

dir

Model directory (default pliman_model_dir()).

...

Additional arguments passed to graphics::plot().

Value

An Image object with dimensions (orig_w * scale) x (orig_h * scale) x 3.

Examples

if (FALSE) { # interactive()
  library(pliman)
  img <- image_import("low_res.png")
  imgsr <- image_superres_dl(img)
  imgsharper <- image_superres_dl(img, model = "SAFMN2x_sharper")
  image_combine(img, imgsr, imgsharper, ncol = 3)
}