Data Augmentation Module

Data Augmentation Module

This module implements classical computer vision augmentation techniques specifically tailored for facial datasets stored in compressed NumPy format (.npz).

Technices included:

  • Gaussian Noise: Adds random variation to simulate sensor noise.

  • Salt and Pepper: Simulates digital transmission errors and dead pixels.

  • Blur: Applies a box filter to simulate out-of-focus or motion blur.

Data Integrity:

The module is designed to integrate with the outputs of ‘face2.py’. It automatically detects and ignores files with the suffix ‘_audio.npz’ to ensure that audio spectrograms are not corrupted by visual filters. All augmented outputs are saved with the original ‘data’ key to maintain compatibility with standard DataLoaders.

data_augmentation.add_gaussian_noise(image, snr_db=15.0)[source]

Adiciona ruído Gaussiano baseado em um SNR fixo (em dB).

Parameters:
  • image – Imagem original em uint8 (0-255).

  • snr_db – Relação Sinal-Ruído desejada em decibéis. Valores típicos: 10 (muito ruído) a 30 (pouco ruído).

data_augmentation.add_salt_and_pepper_noise(images, prob=0.04)[source]

Applies impulsive noise (Salt and Pepper) to a batch of images.

Parameters:
  • images – NumPy array of shape (N, H, W, C).

  • prob – Total probability of noise affecting a pixel.

Returns:

Augmented uint8 NumPy array.

data_augmentation.apply_blur(images, kernel_size=5)[source]

Applies an average blur filter to a batch of images.

Parameters:
  • images – NumPy array of shape (N, H, W, C).

  • kernel_size – Dimension of the square blur kernel.

Returns:

Augmented uint8 NumPy array.

data_augmentation.process_augmentation(input_folder, output_folder, selected_augs)[source]

Processes all face .npz files in a directory using the specified filters.

The function iterates through the input folder, loads the ‘data’ key from valid files, applies the requested transformations, and saves each as a new compressed .npz file with a suffix indicating the effect.

Parameters:
  • input_folder – Path containing the original .npz face files.

  • output_folder – Path to save the augmented files.

  • selected_augs – List of augmentation keys to apply (e.g., [‘blur’]).