This function uses the magick package to edit the color and perform other image manipulations on a background image. It can be useful if you want to highlight certain features of these images.

img_edit(
  spe,
  sampleid,
  image_id = "lowres",
  channel = NA,
  brightness = 100,
  saturation = 100,
  hue = 100,
  enhance = FALSE,
  contrast_sharpen = NA,
  quantize_max = NA,
  quantize_dither = TRUE,
  equalize = FALSE,
  normalize = FALSE,
  transparent_color = NA,
  transparent_fuzz = 0,
  background_color = NA,
  median_radius = NA,
  negate = FALSE
)

Arguments

spe

A SpatialExperiment-class object. See fetch_data() for how to download some example objects or read10xVisiumWrapper() to read in spaceranger --count output files and build your own spe object.

sampleid

A character(1) specifying which sample to plot from colData(spe)$sample_id (formerly colData(spe)$sample_name).

image_id

A character(1) with the name of the image ID you want to use in the background.

channel

A character(1) passed to magick::image_channel. If NA this step is skipped.

brightness

A numeric(1) passed to magick::image_modulate.

saturation

A numeric(1) passed to magick::image_modulate.

hue

A numeric(1) passed to magick::image_modulate.

enhance

A logical(1) controlling whether to use magick::enhance.

contrast_sharpen

A numeric(1) passed to magick::image_contrast. If NA this step is skipped.

quantize_max

A numeric(1) passed to magick::image_quantize. If NA this step is skipped.

quantize_dither

A logical(1) passed to magick::image_quantize.

equalize

A logical(1) controlling whether to use magick::equalize.

normalize

A logical(1) controlling whether to use magick::normalize.

transparent_color

A character(1) passed to magick::image_transparent. If NA this step is skipped.

transparent_fuzz

A numeric(1) passed to magick::image_transparent.

background_color

A character(1) passed to magick::image_background. If NA this step is skipped.

median_radius

A numeric(1) passed to magick::image_median. If NA this step is skipped.

negate

A logical(1) controlling whether to use magick::negate.

Value

A magick image object such as the one returned by magick::image_read.

Details

The magick functions are used in the sequence represented by the arguments to this function. You can alternatively use this function sequentially. Or directly use the magick package.

See also

Other Image editing functions: img_update(), img_update_all()

Examples

if (enough_ram()) {
    ## Obtain the necessary data
    if (!exists("spe")) spe <- fetch_data("spe")

    ## Reduce brightness to 25%
    x <- img_edit(spe, sampleid = "151507", brightness = 25)
    plot(x)
}
#> 2024-12-16 21:51:18.131969 loading file /github/home/.cache/R/BiocFileCache/10535bcd9c3d_Human_DLPFC_Visium_processedData_sce_scran_spatialLIBD.Rdata%3Fdl%3D1