drawROI | R Documentation |
Draw a rectangular frame surrounding the region of interest in an image or the entire image.
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 )
img |
An |
x, y |
|
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 |
show |
replot the image after adding the border if |
lwd |
line width of the border in pixels; note that this is
not the standard definition of |
col |
border color of the rectangle |
asCorner |
|
which.corner |
identifies the corner of the rectangle specified
by |
sides |
which side(s) are to include the border (1=bottom, 2=left, 3=top, 4=right) |
pch |
plotting character used by |
col.pch |
color for plotting character used by |
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
.
Two Points. If values are provided for each of x,y
and x2,y2
, these are treated as opposite corners of
the rectangular selection.
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.
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)
.
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.
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"
.
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.
Modified image with region of interest outlined.
getROI
to get a region of interest from an image and
putROI
to place an ROI with scaling.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.