putROI: Put an Image (ROI) into Another Image

View source: R/putROI.R

putROIR Documentation

Put an Image (ROI) into Another Image

Description

Place a scaled image into another image as an optionally framed inset

Usage

putROI(
  img,
  roi,
  position,
  show,
  frac = NULL,
  mag = NULL,
  frac.default = 1/3,
  lwd = 2,
  col = "white"
)

Arguments

img

the larger Image object to receive the roi; this can be an Image object or a path (as a character vector) to such the image

roi

the smaller Image object to be placed in the Image object "img"

position

a character string or integer in 1 to 9 indicating the position of the inset; If missing, locator will be called to interact with the user to place the inset; see Details

show

logical value indicated whether to show the image with inset

frac

a numeric value between 0 and 1 for the fractional width occupied by the inset; the default values of NULL uses the value in frac.default

mag

optional magnification factor for inset; if NULL (default), it will be determined by frac

frac.default

default fractional width for the inset (1/3)

lwd

width of the inset border in pixels; note that this is not the standard definition of lwd

col

color of the inset border

Details

The image to be placed as an inset (roi) will be scaled and placed in img at the location specified by position. This argument can be one of "topleft", "top", "topright", "left", "center", "right", "bottomleft", "bottom", and "bottomright". The code will also accept the integers 1 to 9 corresponding to these respective positions. If position is missing, locator will be called to determine where (among the nine choices) to place the inset.

The image will be scaled according to either frac or mag where frac indicates the fractional width of the image to be occupied by the scaled inset. Alternatively, the magnification can be specified with mag, typically a number greater than 1. Values that create an inset greater than the dimensions of the img argument will cause an error.

If show = TRUE or if show is missing and locator was used to place the inset, the image with inset will be plotted. In all cases, the modified image will be invisibly returned.

Value

An Image of the same dimensions as the second argument (img) with roi inserted after appropriate scaling and optional framing.

See Also

getROI to get a region of interest from an image and drawROI to draw a frame within an image.

Examples

# Sample color image
  lighthouse <- readImage(system.file("extdata", "lighthouse.jpg", package="EBImageExtra"))

# Get region of interest of fixed width and height, specified by center
  ins <- getROI(lighthouse, 515, 280, w = 180, h = 280)
  putROI(lighthouse, ins, "topright", show = TRUE)

# Display the 9 possible positions
  img <- resize(lighthouse, w = 256)
  ins2 <- resize(ins, w = 45)
  z <- lapply(1:9, function(i) putROI(img, ins2, i, lwd  = 4))
  z <- abind(z, along = 4) # 5-times faster than calling 'combine'
  plotStack(z, labels = TRUE, cex = 1.5)


ornelles/EBImageExtra documentation built on Aug. 10, 2022, 11:44 p.m.