dataeval.core.calculate

dataeval.core.calculate(images, boxes, stats=ImageStats.ALL, *, per_image=True, per_box=True, per_channel=False, progress_callback=None)

Compute specified statistics on a set of images.

Parameters:
images : Iterable[ArrayLike]

An iterable of images to compute statistics on.

boxes : Iterable[Iterable[BoxLike] | None] | None

Optional bounding boxes for each image. If None, processes entire images.

stats : ImageStats, default ImageStats.ALL

Flags indicating which statistics to compute. Can combine multiple flags using bitwise OR (|). Dependencies are resolved automatically.

per_image : bool, default True

If True, compute statistics for entire images. When boxes are provided and per_image=True, statistics are computed for both the full image and each box (if per_box=True).

per_box : bool, default True

If True and boxes are provided, compute statistics for each bounding box. Has no effect when boxes is None. At least one of per_image or per_box must be True.

per_channel : bool, default False

If True, compute per-channel statistics. If False, statistics are aggregated across all channels.

progress_callback : Callable[[int, int | None], None] | None

Optional callback for progress updates.

Returns:

Dictionary containing computed statistics and metadata including: - Individual statistics as computed by processors - ‘source_index’: List of SourceIndex objects with image/box/channel info - ‘object_count’: List of object counts per image - ‘invalid_box_count’: List of invalid box counts per image - ‘image_count’: Total number of images processed

Output is sorted by (image_index, box_index, channel_index) ascending, with None values appearing before 0.

Return type:

dict[str, Any]

Examples

Compute all statistics:

>>> from dataeval.core.flags import ImageStats
>>> stats = calculate(images, boxes)

Compute specific statistics:

>>> stats = calculate(images, boxes, stats=ImageStats.PIXEL_MEAN | ImageStats.VISUAL_BRIGHTNESS)

Use convenience groups:

>>> stats = calculate(images, boxes, stats=ImageStats.PIXEL | ImageStats.VISUAL)
>>> stats = calculate(images, boxes, stats=ImageStats.PIXEL_BASIC, per_channel=True)

Compute statistics only for bounding boxes (not full images):

>>> stats = calculate(images, boxes, per_image=False, per_box=True)

Compute statistics for full images only (ignore boxes):

>>> stats = calculate(images, boxes, per_image=True, per_box=False)

Compute statistics for both full images and boxes with per-channel breakdown:

>>> stats = calculate(images, boxes, per_image=True, per_box=True, per_channel=True)