drawROI: Draw a Rectangular Frame within an Image

View source: R/drawROI.R

drawROIR Documentation

Draw a Rectangular Frame within an Image

Description

Draw a rectangular frame surrounding the region of interest in an image or the entire image.

Usage

drawROI(
  img,
  x,
  y,
  x2,
  y2,
  w,
  h,
  show,
  lwd = 2,
  col = "white",
  asCorner = FALSE,
  which.corner = c("bottomleft", "topleft", "topright", "bottomright"),
  sides = 1:4,
  pch = 3,
  col.pch = col
)

Arguments

img

An Image object

x, y

x,y coordinates of one or both corners of rectangular selection or the location of the center of the rectangular selection or a list specifying the corners of the selection or an Roi object with a slot named "loc" (See Details)

x2, y2

optional second pair of x and y coordinates when needed to specify the other corner of the rectangular selection

w, h

optional width and height of the rectangular selection; required if x2,y2 are missing

show

replot the image after adding the border if TRUE

lwd

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

col

border color of the rectangle

asCorner

logical value to use the point x,y as the corner of the selection instead of the center of the selection

which.corner

identifies the corner of the rectangle specified by x,y; applies only if asCorner = TRUE

sides

which side(s) are to include the border (1=bottom, 2=left, 3=top, 4=right)

pch

plotting character used by locator when interacting with the image

col.pch

color for plotting character used by locator

Details

A rectangular border of lwd pixels will drawn around the region of interest along the sides specified by sides. The added border will be drawn toward the interior of the region of interest to preserve the dimensions of the modified image. This function differs from rect by using lwd in an atypical manner–here lwd refers to the width of the border in pixels. This also differs from the base functions by directly changing pixels in the image, in contrast to changing the image on the plot device.

This region of interest can be specified with arguments or interactively. Options allow specifying the rectangle either by the center or corner(s) as describe below. Options 1 through 5 below require no interaction with the user and will display the revised image only if show = TRUE. Option 6 below requires interaction with the user. In all cases, the selected coordinates are adjusted to conform to the dimensions of the image, which can override values in w or h.

  1. Two Points. If values are provided for each of x,y and x2,y2, these are treated as opposite corners of the rectangular selection.

  2. Object with loc slot. If x is an object of class Roi, the coordinates in the loc slot will be extracted and applied to the img argument.

  3. List. If x is a list of length 2, it must hold opposite corners of the rectangular selection. This could be the loc slot from a Roi object or the result of a call to locator(2).

  4. No Points (use entire image). If all of x,y, x2,y2, w,h are missing, a border will be generated for the entire image.

  5. One Point (with width and height). A single value can be provided for each of x,y with named values for for w,h as the width and height of the rectangular selection. The point x,y is interpreted as either the center (asCorner = FALSE) or the corner of the selection (asCorner = TRUE). If asCorner = TRUE, the position of the corner is determined by the argument which.corner which can be one of "bottomleft", "topleft", "topright", or "bottomright".

  6. Only width and height. If only (w,h) are provided as named arguments, locator will be used to interact with the user to identify the point needed to define the rectangular selection. The selected point is interpreted as either the center (asCorner = FALSE) or the corner of the selection (asCorner = TRUE) as described above.

Value

Modified image with region of interest outlined.

See Also

getROI to get a region of interest from an image and putROI to place an ROI with scaling.

Examples


# Example of adding arbitrary 90 pixel x 90 pixel "roi" highlights to one image
  img <- readImage(system.file("extdata", "lighthouse.jpg", package="EBImageExtra"))
  xc <- sample(100:(dim(img)[1] - 100), 8)
  yc <- sample(100:(dim(img)[2] - 100), 8)
  for (i in 1:8) img <- drawROI(img, xc[i], yc[i], w = 90, h = 90)
  plot(img)

# Example of adding a frame to the image itself
  drawROI(img, as.Roi(img), col = "red", lwd = 12, show = TRUE) 


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