Skip to contents

Compares two outputs from image_detect_dl() or image_segment_dl() by matching instances via bounding-box Intersection-over-Union (IoU) and classifying each detection/segment into "common" (intersection: matched in both x and y), "only_x" (present only in x), or "only_y" (present only in y).

Usage

image_compare_dl(
  x,
  y,
  mode = c("all", "intersection", "difference", "union", "only_x", "only_y"),
  iou_threshold = 0.5,
  match_class = TRUE,
  names = NULL,
  img = NULL,
  col = c(common = "#00CC66", only_x = "#FF3B30", only_y = "#007AFF"),
  alpha = 0.45,
  border = "black",
  lwd = 2,
  cex = 0.9,
  bbox = NULL,
  mask = NULL,
  badge = TRUE,
  badge_pad = 4,
  show_text = TRUE,
  show_conf = TRUE,
  show_class = TRUE,
  show_id = FALSE,
  show_status = TRUE,
  show_legend = TRUE,
  legend_pos = "topright",
  plot = TRUE,
  verbose = TRUE,
  ...
)

Arguments

x, y

Objects returned by image_detect_dl() or image_segment_dl().

mode

Character string specifying which subset of instances to retain and plot:

  • "all" or "union" (default): all instances ("common", "only_x", and "only_y").

  • "intersection": only consensus instances matched in both x and y ("common").

  • "difference": symmetric difference — instances exclusive to either x or y ("only_x" and "only_y").

  • "only_x": instances present in x but absent in y (\(x \setminus y\)).

  • "only_y": instances present in y but absent in x (\(y \setminus x\)).

iou_threshold

Numeric IoU threshold in \((0, 1]\) required to pair an instance from x with an instance from y. Defaults to 0.5.

match_class

Logical. If TRUE (default), only instances with matching class labels can be paired.

names

Optional character vector of length 2 giving human-readable labels for x and y in summaries, badges, and the plot legend. Defaults to the deparsed argument expressions.

img

Optional Image object to use as background when plotting. Defaults to the image attached to x or y.

col

Named or length-3 character vector of colors for "common", "only_x", and "only_y". Defaults to c(common = "#00CC66", only_x = "#FF3B30", only_y = "#007AFF").

alpha, border, lwd, cex, bbox, mask, badge, badge_pad, show_text, show_conf, show_class, show_id

Visual overlay parameters forwarded to the plot renderer.

show_status

Logical. If TRUE (default), prefixes the class label of exclusive detections with [-name_x] or [+name_y] in the plotted badge.

show_legend

Logical. If TRUE (default), draws a status legend on the plot indicating counts for common and exclusive detections.

legend_pos

Position of the legend (e.g. "topright", "topleft", "bottomright", "bottomleft"). Defaults to "topright".

plot

Logical. If TRUE (default), renders the comparison overlay.

verbose

Logical. If TRUE (default), prints a comparison summary to the console.

...

Additional graphical parameters passed to graphics::plot().

Value

Invisibly returns an object of class c("image_compare_dl", "list") with elements:

  • results: data.frame of instances matching mode, including columns status ("common", "only_x", "only_y"), source, id_x, id_y, score_x, score_y, and iou.

  • all_results: data.frame containing all instances across all three statuses regardless of mode.

  • counts: data.frame summarizing instance counts per status.

  • metrics: list with n_x, n_y, n_common, n_only_x, n_only_y, jaccard_instances, mean_box_iou, and (when pixel masks are present) mask_iou and mask_dice.

  • contours: list of polygon contours aligned with results.

  • summary: formatted summary string.