sd_img2img: Generate images with img2img

View source: R/pipeline.R

sd_img2imgR Documentation

Generate images with img2img

Description

Generate images with img2img

Usage

sd_img2img(
  ctx,
  prompt,
  init_image,
  negative_prompt = "",
  mask = NULL,
  width = NULL,
  height = NULL,
  sample_method = SAMPLE_METHOD$EULER,
  sample_steps = 20L,
  cfg_scale = 7,
  seed = 42L,
  batch_count = 1L,
  scheduler = SCHEDULER$DISCRETE,
  clip_skip = -1L,
  strength = 0.75,
  eta = 0,
  flow_shift = NULL,
  vae_mode = "auto",
  vae_auto_threshold = 1048576L,
  vae_tile_size = 64L,
  vae_tile_overlap = 0.25,
  vae_tile_rel_x = NULL,
  vae_tile_rel_y = NULL,
  vae_tiling = NULL,
  cache_mode = c("off", "easy", "ucache"),
  cache_config = NULL
)

Arguments

ctx

SD context created by sd_ctx

prompt

Text prompt describing desired image

init_image

Init image in sd_image format. Use sd_load_image to load from file.

negative_prompt

Negative prompt (default "")

mask

Optional inpainting mask. A PNG file path, a numeric matrix [H, W] (values in 0..1 or 0..255), or a 1-channel SD image list. White (255) = regenerate that region, black (0) = keep the original. Must match the init image dimensions. When NULL (default) the whole image is denoised (plain img2img).

width

Image width in pixels (default 512)

height

Image height in pixels (default 512)

sample_method

Sampling method (see SAMPLE_METHOD)

sample_steps

Number of sampling steps (default 20)

cfg_scale

Classifier-free guidance scale (default 7.0)

seed

Random seed (-1 for random)

batch_count

Number of images to generate (default 1)

scheduler

Scheduler type (see SCHEDULER)

clip_skip

Number of CLIP layers to skip (-1 = auto)

strength

Denoising strength (0.0 = no change, 1.0 = full denoise, default 0.75)

eta

Eta parameter for DDIM-like samplers

flow_shift

Flow shift for flow-matching models (Flux, SD3). NULL (default) lets the model pick an architecture-specific value; set a numeric value to override. Ignored by non-flow models.

vae_mode

VAE processing mode: "normal" (no tiling), "tiled" (always tile), or "auto" (VRAM-aware: queries free GPU memory via Vulkan and compares against estimated peak VAE usage; tiles only when VRAM is insufficient). Default "auto".

vae_auto_threshold

Pixel area fallback threshold for vae_mode = "auto" when VRAM query is unavailable (no Vulkan, CPU backend, etc.). Tiling activates when width * height exceeds this value. Default 1048576L (1024x1024 pixels).

vae_tile_size

Tile size in latent pixels for tiled VAE (default 64). Ignored when vae_tile_rel_x/vae_tile_rel_y are set.

vae_tile_overlap

Overlap ratio between tiles, 0.0-0.5 (default 0.25)

vae_tile_rel_x

Relative tile width as fraction of latent width (0-1) or number of tiles (>1). NULL = use vae_tile_size. Takes priority over vae_tile_size.

vae_tile_rel_y

Relative tile height as fraction of latent height (0-1) or number of tiles (>1). NULL = use vae_tile_size. Takes priority over vae_tile_size.

vae_tiling

Deprecated. Use vae_mode instead. If TRUE, equivalent to vae_mode = "tiled".

cache_mode

Step caching mode: "off" (default), "easy" (EasyCache — skips redundant denoising steps), or "ucache" (UCache). Can speed up sampling 20-40% with minor quality impact.

cache_config

Optional fine-tuned cache config from sd_cache_params. Overrides cache_mode when provided.

Value

List of SD images


sd2R documentation built on June 19, 2026, 9:08 a.m.