Filters

Filters provides comprehensive filtering capabilities for detections including confidence thresholding, class-based filtering, geometric constraints, zone-based filtering, and tracking-related filters. Designed for zero-overhead method injection into Detections class for seamless chaining operations.

Example

Python
import cv2import pixelflow as pffrom ultralytics import YOLO# Load model and run inferencemodel = YOLO("yolov8n.pt")image = cv2.imread("traffic_scene.jpg")outputs = model.predict(image)detections = pf.detections.from_ultralytics(outputs)# Basic filtering: keep high-confidence detectionshigh_conf = detections.filter_by_confidence(0.8)print(f"High confidence: {len(high_conf)}/{len(detections)} detections")# Conservative filtering for critical applicationscritical = detections.filter_by_confidence(0.95)print(f"Very high confidence: {len(critical)} detections")# Method chaining with other filtersfiltered = detections.filter_by_confidence(0.7).filter_by_class_id([0, 2])print(f"High-conf people and cars: {len(filtered)} detections")# Moderate filtering for analysismoderate = detections.filter_by_confidence(0.5)print(f"Moderate confidence: {len(moderate)} detections")

Functions

  • filter_by_confidence() - Filter detections by minimum confidence score threshold.
  • filter_by_class_id() - Filter detections by class identifier(s).
  • remap_class_ids() - Remap class IDs to consolidate or standardize classification labels.
  • filter_by_size() - Filter detections by bounding box area constraints.
  • filter_by_dimensions() - Filter detections by individual width and height constraints.
  • filter_by_aspect_ratio() - Filter detections by bounding box aspect ratio (width/height).
  • filter_by_zones() - Filter detections based on zone intersection status.
  • filter_by_position() - Filter detections by their position within the frame.
  • filter_by_relative_size() - Filter detections by size relative to total frame area.
  • filter_by_tracking_duration() - Filter detections by their tracking duration.
  • filter_by_first_seen_time() - Filter detections by when they were first observed.
  • remove_duplicates() - Remove duplicate or highly overlapping detections using Non-Maximum Suppression.
  • filter_overlapping() - Filter detections that significantly overlap with other detections.

filter_by_confidence()

Filter detections by minimum confidence score threshold.

Applies confidence-based filtering to remove low-confidence detections that may represent false positives or uncertain predictions. Essential preprocessing step for improving detection quality and reducing noise in downstream analysis.