
Compare Two Deep-Learning Detection or Segmentation Results
Source:R/utils_neural.R
image_compare_dl.RdCompares 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()orimage_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 bothxandy("common")."difference": symmetric difference — instances exclusive to eitherxory("only_x"and"only_y")."only_x": instances present inxbut absent iny(\(x \setminus y\))."only_y": instances present inybut absent inx(\(y \setminus x\)).
- iou_threshold
Numeric IoU threshold in \((0, 1]\) required to pair an instance from
xwith an instance fromy. Defaults to0.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
xandyin summaries, badges, and the plot legend. Defaults to the deparsed argument expressions.- img
Optional
Imageobject to use as background when plotting. Defaults to the image attached toxory.- col
Named or length-3 character vector of colors for
"common","only_x", and"only_y". Defaults toc(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.frameof instances matchingmode, including columnsstatus("common","only_x","only_y"),source,id_x,id_y,score_x,score_y, andiou.all_results:data.framecontaining all instances across all three statuses regardless ofmode.counts:data.framesummarizing instance counts per status.metrics: list withn_x,n_y,n_common,n_only_x,n_only_y,jaccard_instances,mean_box_iou, and (when pixel masks are present)mask_iouandmask_dice.contours: list of polygon contours aligned withresults.summary: formatted summary string.