
    hx                        S r SSKJr  SSKrSSKJr  SSKJrJr  SSK	r
SSKJr  SSKJr  SSKJr  S	/r " S
 S	\5      rg)a  Lambda transform module for creating custom user-defined transformations.

This module provides a flexible transform class that allows users to define their own
custom transformation functions for different targets (image, mask, keypoints, bboxes).
It's particularly useful for implementing custom logic that isn't available in the
standard transforms.

The Lambda transform accepts different callable functions for each target type and
applies them when the transform is executed. This allows for maximum flexibility
while maintaining compatibility with the Albumentations pipeline structure.

Key features:
- Apply different custom functions to different target types
- Compatible with all Albumentations pipeline features
- Support for all image types and formats
- Ability to handle any number of channels
- Warning system for lambda expressions and multiprocessing compatibility

Note that using actual lambda expressions (rather than named functions) can cause
issues with multiprocessing, as lambdas cannot be properly pickled.
    )annotationsN)
LambdaType)AnyCallable)
functional)NoOp)format_argsLambdac                     ^  \ rS rSrSr      S           SU 4S jjjrSS jrSS jrSS jrSS jr	\
SS j5       rSS	 jrSS
 jrSrU =r$ )r
   &   a  A flexible transformation class for using user-defined transformation functions per targets.
Function signature must include **kwargs to accept optional arguments like interpolation method, image size, etc:

Args:
    image (Callable[..., Any] | None): Image transformation function.
    mask (Callable[..., Any] | None): Mask transformation function.
    keypoints (Callable[..., Any] | None): Keypoints transformation function.
    bboxes (Callable[..., Any] | None): BBoxes transformation function.
    p (float): probability of applying the transform. Default: 1.0.

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

Image types:
    uint8, float32

Number of channels:
    Any

c                T  > [         T	U ]  US9  XPl        [        R	                  S[
        R                  5      U l        UUUUS.R                  5        HR  u  pxUc  M
  [        U[        5      (       a%  UR                  S:X  a  [        R                  " SSS9  XR                  U'   MT     g )N)p)imagemask	keypointsbboxesz<lambda>zaUsing lambda is incompatible with multiprocessing. Consider using regular functions or partial().   )
stacklevel)super__init__namedictfromkeysfpixelnoopcustom_apply_fnsitems
isinstancer   __name__warningswarn)
selfr   r   r   r   r   r   target_namecustom_apply_fn	__class__s
            m/var/www/fran/franai/venv/lib/python3.13/site-packages/albumentations/augmentations/other/lambda_transform.pyr   Lambda.__init__<   s     	1	 $.VX^XcXc d"	-

 %'-(K *oz::?W?W[e?eMMI#$ 6E%%k2-    c                2    U R                   S   nU" U40 UD6$ )a  Apply the Lambda transform to the input image.

Args:
    img (np.ndarray): The input image to apply the Lambda transform to.
    **params (Any): Additional parameters (not used in this transform).

Returns:
    np.ndarray: The image with the applied Lambda transform.

r   r   )r"   imgparamsfns       r&   applyLambda.applyY   s$     ""7+#   r(   c                2    U R                   S   nU" U40 UD6$ )a  Apply the Lambda transform to the input mask.

Args:
    mask (np.ndarray): The input mask to apply the Lambda transform to.
    **params (Any): Additional parameters (not used in this transform).

Returns:
    np.ndarray: The mask with the applied Lambda transform.

r   r*   )r"   r   r,   r-   s       r&   apply_to_maskLambda.apply_to_maskg   s$     ""6*$!&!!r(   c                2    U R                   S   nU" U40 UD6$ )a,  Apply the Lambda transform to the input bounding boxes.

Args:
    bboxes (np.ndarray): The input bounding boxes to apply the Lambda transform to.
    **params (Any): Additional parameters (not used in this transform).

Returns:
    np.ndarray: The bounding boxes with the applied Lambda transform.

r   r*   )r"   r   r,   r-   s       r&   apply_to_bboxesLambda.apply_to_bboxesu   s$     ""8,&#F##r(   c                2    U R                   S   nU" U40 UD6$ )a   Apply the Lambda transform to the input keypoints.

Args:
    keypoints (np.ndarray): The input keypoints to apply the Lambda transform to.
    **params (Any): Additional parameters (not used in this transform).

Returns:
    np.ndarray: The keypoints with the applied Lambda transform.

r   r*   )r"   r   r,   r-   s       r&   apply_to_keypointsLambda.apply_to_keypoints   s$     "";/)&v&&r(   c                    g)z|Check if the Lambda transform is serializable.

Returns:
    bool: True if the transform is serializable, False otherwise.

F )clss    r&   is_serializableLambda.is_serializable   s     r(   c                p    U R                   c  Sn[        U5      eU R                  5       U R                   S.$ )z}Convert the Lambda transform to a dictionary.

Returns:
    dict[str, Any]: The dictionary representation of the transform.

zTo make a Lambda transform serializable you should provide the `name` argument, e.g. `Lambda(name='my_transform', image=<some func>, ...)`.)__class_fullname__r   )r   
ValueErrorget_class_fullname)r"   msgs     r&   to_dict_privateLambda.to_dict_private   s=     99N  S/!&*&=&=&?TYYWWr(   c                    SU R                   0nUR                  U R                  R                  5       5        UR                  U R	                  5       5        U R
                  R                   S[        U5       S3$ )zReturn the string representation of the Lambda transform.

Returns:
    str: The string representation of the Lambda transform.

r   ())r   updater   r   get_base_init_argsr%   r   r	   )r"   states     r&   __repr__Lambda.__repr__   sf     #T**0023T,,./..))*!K,>+?qAAr(   )r   r   )NNNNNg      ?)r   Callable[..., Any] | Noner   rM   r   rM   r   rM   r   z
str | Noner   float)r+   
np.ndarrayr,   r   returnrO   )r   rO   r,   r   rP   rO   )r   rO   r,   r   rP   rO   )r   rO   r,   r   rP   rO   )rP   bool)rP   zdict[str, Any])rP   str)r   
__module____qualname____firstlineno____doc__r   r.   r1   r4   r7   classmethodr<   rC   rK   __static_attributes____classcell__)r%   s   @r&   r
   r
   &   s    . ,0*./3,0E(E (E -	E
 *E E E E:!"$'  X
B 
Br(   )rV   
__future__r   r    typesr   typingr   r   numpynp"albumentations.augmentations.pixelr   r   (albumentations.core.transforms_interfacer   albumentations.core.utilsr	   __all__r
   r:   r(   r&   <module>rc      s;   , #      C 9 1*NBT NBr(   