Skip to contents

yolo_dataset_anonymize() (and its alias yolo_anonymize()) scans a YOLO dataset or image folder, detects sensitive entities such as human faces, workers, and vehicle license plates, and automatically blurs or pixelates those regions directly on the images. Crucially, target object annotations (labels/*.txt containing bounding boxes or segmentation masks for crops, fruits, seeds, animals, or weeds) are completely preserved without any displacement or coordinate modification.

This utility ensures compliance with privacy regulations (e.g., GDPR, LGPD, institutional ethics committees) prior to publishing open-access agronomic datasets on repositories such as Zenodo, Figshare, Dryad, or Roboflow.

Usage

yolo_dataset_anonymize(
  dataset,
  model = "yolo26n",
  target_classes = c("person", "face", "license plate", "car", "truck", "bus",
    "motorcycle"),
  person_region = c("head", "full"),
  method = c("pixelate", "blur"),
  kernel_size = 25L,
  conf_threshold = 0.2,
  iou_threshold = 0.45,
  output_dir = NULL,
  backup = TRUE,
  recursive = TRUE,
  engine = "gpu",
  verbose = TRUE,
  ...
)

yolo_anonymize(
  dataset,
  model = "yolo26n",
  target_classes = c("person", "face", "license plate", "car", "truck", "bus",
    "motorcycle"),
  person_region = c("head", "full"),
  method = c("pixelate", "blur"),
  kernel_size = 25L,
  conf_threshold = 0.2,
  iou_threshold = 0.45,
  output_dir = NULL,
  backup = TRUE,
  recursive = TRUE,
  engine = "gpu",
  verbose = TRUE,
  ...
)

Arguments

dataset

Character string or vector. Path to the YOLO dataset root directory (containing images/ or subdirectories train/, val/, test/), or a character vector of image file paths.

model

A YOLO model identifier or path. Defaults to "yolo26n". Can be an ONNX model file or a pretrained model name (e.g., "yolo11n", "yolo26n").

target_classes

Character vector of class names or regex patterns to anonymize. Defaults to c("person", "face", "license plate", "car", "truck", "bus", "motorcycle").

person_region

Character string specifying which region of a detected "person" to anonymize:

  • "head" (default): Estimates and blurs only the head/face region (top 22% of the bounding box).

  • "full": Blurs the entire bounding box of the person.

method

Character string specifying the anonymization method:

  • "pixelate" (default): Applies mosaic pixelation (irrecoverable pixel blocks).

  • "blur": Applies repeated spatial box/mean blurring.

kernel_size

Integer. Size in pixels of mosaic blocks (for "pixelate") or blur kernel (for "blur"). Defaults to 25L.

conf_threshold

Numeric. Confidence threshold for detecting sensitive entities. Defaults to 0.20 to ensure high recall for distant or edge-of-frame faces.

iou_threshold

Numeric. Non-Maximum Suppression (NMS) IoU threshold. Defaults to 0.45.

output_dir

Character string or NULL. Destination directory for anonymized images. If NULL (default), images are modified in-place.

backup

Logical. When modifying images in-place (output_dir = NULL), whether to create backup copies with extension .orig or .backup. Defaults to TRUE.

recursive

Logical. Whether to search subdirectories recursively. Defaults to TRUE.

engine

Character string. Compute engine: "gpu" (default) or "cpu".

verbose

Logical. Whether to display progress bars and summary reports. Defaults to TRUE.

...

Additional arguments passed to image_detect_dl().

Value

An S3 object of class c("yolo_anonymized", "data.frame") containing:

  • image: Path to the image file.

  • anonymized_count: Number of sensitive entities detected and anonymized.

  • classes: Comma-separated list of sensitive classes found.

  • status: Processing status ("anonymized", "no_sensitive_objects", or "error").

  • output_path: Path where the anonymized image was written.