
    h                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  / S	Qr " S
 S\
5      r " S S\5      r " S S\5      rg)a  Transforms for spectrogram augmentation.

This module provides transforms specifically designed for augmenting spectrograms
in audio processing tasks. Includes time reversal, time masking, and frequency
masking transforms commonly used in audio machine learning applications.
    )annotations)warn)Field)	XYMasking)HorizontalFlip)BaseTransformInitSchema)ALL_TARGETS)FrequencyMaskingTimeMaskingTimeReversec                  R   ^  \ rS rSrSr\r " S S\5      r S SU 4S jjjr	Sr
U =r$ )	r      ax  Reverse the time axis of a spectrogram image, also known as time inversion.

Time inversion of a spectrogram is analogous to the random flip of an image,
an augmentation technique widely used in the visual domain. This can be relevant
in the context of audio classification tasks when working with spectrograms.
The technique was successfully applied in the AudioCLIP paper, which extended
CLIP to handle image, text, and audio inputs.

This transform is implemented as a subclass of HorizontalFlip since reversing
time in a spectrogram is equivalent to flipping the image horizontally.

Args:
    p (float): probability of applying the transform. Default: 0.5.

Targets:
    image, mask, bboxes, keypoints, volume, mask3d

Image types:
    uint8, float32

Number of channels:
    Any

Note:
    This transform is functionally identical to HorizontalFlip but provides
    a more semantically meaningful name when working with spectrograms and
    other time-series visualizations.

References:
    - AudioCLIP paper: https://arxiv.org/abs/2106.13043
    - Audiomentations: https://iver56.github.io/audiomentations/waveform_transforms/reverse/

c                      \ rS rSrSrg)TimeReverse.InitSchema?    N)__name__
__module____qualname____firstlineno____static_attributes__r       l/var/www/fran/franai/venv/lib/python3.13/site-packages/albumentations/augmentations/spectrogram/transform.py
InitSchemar   ?   s    r   r   c                >   > [        S[        SS9  [        TU ]  US9  g )NzTimeReverse is an alias for HorizontalFlip transform. Consider using HorizontalFlip directly from albumentations.HorizontalFlip.    
stacklevel)p)r   UserWarningsuper__init__)selfr   	__class__s     r   r"   TimeReverse.__init__B   s+     	Z		
 	1r   r   )      ?)r   float)r   r   r   r   __doc__r	   _targetsr   r   r"   r   __classcell__r$   s   @r   r   r      s4     D H, 
 

 
r   r   c                  T   ^  \ rS rSrSr " S S\5      r  S   SU 4S jjjrSrU =r	$ )	r   O   a  Apply masking to a spectrogram in the time domain.

This transform masks random segments along the time axis of a spectrogram,
implementing the time masking technique proposed in the SpecAugment paper.
Time masking helps in training models to be robust against temporal variations
and missing information in audio signals.

This is a specialized version of XYMasking configured for time masking only.
For more advanced use cases (e.g., multiple masks, frequency masking, or custom
fill values), consider using XYMasking directly.

Args:
    time_mask_param (int): Maximum possible length of the mask in the time domain.
        Must be a positive integer. Length of the mask is uniformly sampled from (0, time_mask_param).
    p (float): probability of applying the transform. Default: 0.5.

Targets:
    image, mask, bboxes, keypoints, volume, mask3d

Image types:
    uint8, float32

Number of channels:
    Any

Note:
    This transform is implemented as a subset of XYMasking with fixed parameters:
    - Single horizontal mask (num_masks_x=1)
    - No vertical masks (num_masks_y=0)
    - Zero fill value
    - Random mask length up to time_mask_param

    For more flexibility, including:
    - Multiple masks
    - Custom fill values
    - Frequency masking
    - Combined time-frequency masking
    Consider using albumentations.XYMasking directly.

References:
    - SpecAugment paper: https://arxiv.org/abs/1904.08779
    - Original implementation: https://pytorch.org/audio/stable/transforms.html#timemask

c                  ,    \ rS rSr% \" SS9rS\S'   Srg)TimeMasking.InitSchema}   r   gtinttime_mask_paramr   N)r   r   r   r   r   r4   __annotations__r   r   r   r   r   r/   }       ${*r   r   c           	     X   > [        S[        SS9  [        TU ]  SSSU4SSUS9  Xl        g )NzTimeMasking is a specialized version of XYMasking. For more flexibility (multiple masks, custom fill values, frequency masking), consider using XYMasking directly from albumentations.XYMasking.r   r      r   )num_masks_xnum_masks_ymask_x_lengthfill	fill_maskr   )r   r    r!   r"   r4   )r#   r4   r   r$   s      r   r"   TimeMasking.__init__   sN    
 	O 	
 	o. 	 	
  /r   )r4   )(   r&   )r4   r3   r   r'   
r   r   r   r   r(   r   r   r"   r   r*   r+   s   @r   r   r   O   :    +Z+, +
  "// / /r   r   c                  T   ^  \ rS rSrSr " S S\5      r  S   SU 4S jjjrSrU =r	$ )	r
      a  Apply masking to a spectrogram in the frequency domain.

This transform masks random segments along the frequency axis of a spectrogram,
implementing the frequency masking technique proposed in the SpecAugment paper.
Frequency masking helps in training models to be robust against frequency variations
and missing spectral information in audio signals.

This is a specialized version of XYMasking configured for frequency masking only.
For more advanced use cases (e.g., multiple masks, time masking, or custom
fill values), consider using XYMasking directly.

Args:
    freq_mask_param (int): Maximum possible length of the mask in the frequency domain.
        Must be a positive integer. Length of the mask is uniformly sampled from (0, freq_mask_param).
    p (float): probability of applying the transform. Default: 0.5.

Targets:
    image, mask, bboxes, keypoints, volume, mask3d

Image types:
    uint8, float32

Number of channels:
    Any

Note:
    This transform is implemented as a subset of XYMasking with fixed parameters:
    - Single vertical mask (num_masks_y=1)
    - No horizontal masks (num_masks_x=0)
    - Zero fill value
    - Random mask length up to freq_mask_param

    For more flexibility, including:
    - Multiple masks
    - Custom fill values
    - Time masking
    - Combined time-frequency masking
    Consider using albumentations.XYMasking directly.

References:
    - SpecAugment paper: https://arxiv.org/abs/1904.08779
    - Original implementation: https://pytorch.org/audio/stable/transforms.html#freqmask

c                  ,    \ rS rSr% \" SS9rS\S'   Srg)FrequencyMasking.InitSchema   r   r1   r3   freq_mask_paramr   N)r   r   r   r   r   rG   r5   r   r   r   r   r   rE      r6   r   r   c           	     X   > [        S[        SS9  [        TU ]  USSSU4SSS9  Xl        g )NzFrequencyMasking is a specialized version of XYMasking. For more flexibility (multiple masks, custom fill values, time masking), consider using XYMasking directly from albumentations.XYMasking.r   r   r   r8   )r   r<   r=   mask_y_lengthr9   r:   )r   r    r!   r"   rG   )r#   rG   r   r$   s      r   r"   FrequencyMasking.__init__   sN    
 	O 	
 	o. 	 	
  /r   )rG   )   r&   )rG   r3   r   r'   r@   r+   s   @r   r
   r
      rA   r   r
   N)r(   
__future__r   warningsr   pydanticr   /albumentations.augmentations.dropout.xy_maskingr   +albumentations.augmentations.geometric.flipr   (albumentations.core.transforms_interfacer   $albumentations.core.type_definitionsr	   __all__r   r   r
   r   r   r   <module>rT      sR    #   E F L <2. 2jE/) E/PE/y E/r   