Skip to contents

Applies a chain of preprocessing steps to an sg_image object, including optional stain normalisation, denoising, and contrast enhancement.

Usage

sg_preprocess(
  image,
  stain_normalize = c("none", "macenko", "reinhard", "vahadane"),
  denoise = FALSE,
  contrast = c("none", "clahe", "stretch"),
  target_resolution = NULL
)

Arguments

image

An sg_image object.

stain_normalize

Character string specifying the stain normalisation method. One of "none" (default), "macenko", "reinhard", or "vahadane".

denoise

Logical; if TRUE, a simple mean filter is applied for denoising. Default is FALSE.

contrast

Character string specifying contrast enhancement. One of "none" (default), "clahe", or "stretch".

target_resolution

Finite positive numeric scalar or NULL. If supplied, resample to this many microns per current array pixel using bilinear interpolation. Requested resampling of anisotropic pixels is unsupported and raises an error; leave NULL to retain them unchanged. Both pixel sizes must be finite and positive to resample. Partial or invalid calibration raises an error; if both sizes are unknown, the existing message-and-skip behaviour is retained.

Value

A new sg_image object with its history field updated to record the preprocessing steps applied.

Examples

pixels <- matrix(runif(400), nrow = 20, ncol = 20)
img <- new_sg_image(pixels)
img2 <- sg_preprocess(img)
img3 <- sg_preprocess(img, contrast = "stretch", denoise = TRUE)