Skip to contents

Extracts connected objects from an image, computes their features, crops each object, converts the crop to a raster with alpha, and draws each thumbnail centered at its corresponding (x, y) feature location in a ggplot. Optionally overlays object IDs. Caching can be used to avoid recomputing object features on repeated calls.

Usage

object_scatter(
  img,
  x,
  y,
  scale = 0.1,
  xy_ratio = 1,
  xlab = x,
  ylab = y,
  erosion = 2,
  dilatation = FALSE,
  show_id = FALSE,
  color_id = "black",
  size_id = 3,
  cache = TRUE,
  verbose = TRUE,
  ...
)

Arguments

img

An image of class EBImage::Image (or compatible) from which objects will be segmented and measured.

x

Character scalar. Name of the feature column (returned by get_measures(res)) to use on the x-axis.

y

Character scalar. Name of the feature column to use on the y-axis.

scale

Numeric in (0, 1]. Relative thumbnail size as a fraction of the data range along each axis (larger values draw larger thumbnails).

xy_ratio

Numeric scalar. Factor applied to the vertical scaling (y-axis) of thumbnails. Use values other than 1 to stretch or compress thumbnails vertically.

xlab, ylab

Character scalars used as x- and y-axis labels. Defaults to x and y, respectively.

erosion, dilatation

Integer (non-negative). Size of the structuring element for morphological erosion/dilatation of the segmented objects.

show_id

Logical. If TRUE, overlays object IDs at their x, y locations.

color_id

Character. Color used for the ID labels when show_id = TRUE.

size_id

Numeric. Text size for the ID labels when show_id = TRUE.

cache

Logical. If TRUE (default), caches results of object extraction using a simple key based on image dimensions and parameters.

verbose

If TRUE (default), shows the progress of analysis.

...

Additional arguments forwarded to analyze_objects().

Value

A list with two elements:

  • features — a data frame (or tibble) with object-level features returned by get_measures(res). Must contain columns named x and y.

  • plot — a ggplot object. The thumbnail scatter plot.

Scaling behavior

Thumbnails are sized relative to the observed ranges in x and y. If the two axes differ substantially in range, perceived thumbnail aspect on the plotting device may vary. Use xy_ratio to adjust vertical scaling.

Examples

if(interactive()){
img <- image_pliman("potato_leaves.jpg")
plot(img)
res <- object_scatter(
 img = img,
 index = "B",
 x = "area",
 y = "solidity",
 watershed = FALSE,
 scale = 0.5
)
res$plot

# remove cached data
clear_pliman_cache()
}