Skip to contents

Re-draws the detections returned by image_detect_sahi() over the image. Any visual parameter not given here keeps the value used in the original call, so plot(res) reproduces the original plot and plot(res, rainbow = FALSE, show_text = FALSE) changes only those settings. The result of image_detect_sahi() is also a image_detect_dl object, so this method shares the drawing code of plot.image_detect_dl().

Usage

# S3 method for class 'image_detect_sahi'
plot(
  x,
  img = NULL,
  col = NULL,
  rainbow = NULL,
  lwd = NULL,
  cex = NULL,
  show_text = NULL,
  show_conf = NULL,
  show_class = NULL,
  show_id = NULL,
  show_box = NULL,
  show_point = NULL,
  point_size = NULL,
  point_pch = NULL,
  point_col = NULL,
  badge = NULL,
  badge_pad = NULL,
  ...
)

Arguments

x

An object of class image_detect_sahi returned by image_detect_sahi().

img

Optional Image object to use as background. Defaults to the image used in image_detect_sahi().

col

Box colors: a single color, a vector of colors, or a vector named by class (e.g. c(car = "red", truck = "blue")).

rainbow

Logical. If TRUE, each object gets its own color; if FALSE, one color per class.

lwd

Box line width.

cex

Size factor for the labels.

show_text, show_conf, show_class, show_id

Logical. Whether to draw the labels and, in them, the confidence, class name and object id.

show_box, show_point

Logical. Whether to draw the boxes and the box centers.

point_size, point_pch, point_col

Size, symbol and color of the box centers.

badge

Logical. Whether to draw a colored background behind the labels.

badge_pad

Padding of the label background.

...

Further arguments passed to plot.image_detect_dl(), such as bbox, alpha or border, and graphical arguments passed to graphics::plot().

Value

x, invisibly, with the plotting arguments given here stored, so that later re-plots (e.g. by image_combine()) look the same.

Details

The plot can also be placed in a grid with image_combine(), e.g. image_combine(img, plot(res, lwd = 0.5)).

Examples

if (FALSE) { # interactive()
library(pliman)
farm <- image_pliman("farm.jpg")
res <- image_detect_sahi(farm, model = "yolo26n", slice_width = 480, slice_height = 480)

# One color per class, without labels
plot(res, rainbow = FALSE, show_text = FALSE)

# Custom colors by class and thicker lines
plot(res, rainbow = FALSE, col = c(person = "red", cow = "yellow"), lwd = 4)

# Side by side with the original image
image_combine(farm, plot(res, show_conf = FALSE), ncol = 1, mar = 0)
}