o
    i+                     @  s   d dl mZ d dlmZmZmZ d dlmZ d dlZ	d dl
Z
d dlmZmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZmZ d d
lmZmZmZmZmZ g dZG dd deeZ G dd deeZ!G dd deeZ"e" Z#Z$e! Z%Z&e  Z'Z(dS )    )annotations)HashableMappingSequence)AnyN)KeysCollectionSequenceStr)NdarrayOrTensor)get_track_meta)RandSmoothDeformRandSmoothFieldAdjustContrastRandSmoothFieldAdjustIntensity)MapTransformRandomizableTransform)GridSampleModeGridSamplePadModeInterpolateModeconvert_to_tensorensure_tuple_rep)	RandSmoothFieldAdjustContrastdRandSmoothFieldAdjustIntensitydRandSmoothDeformdRandSmoothFieldAdjustContrastDRandSmoothFieldAdjustIntensityDRandSmoothDeformD!RandSmoothFieldAdjustContrastDict"RandSmoothFieldAdjustIntensityDictRandSmoothDeformDictc                      `   e Zd ZdZejZdejddddfd(ddZ	d)d* fddZ	d+d, fd#d$Z
d-d&d'Z  ZS ).r   a  
    Dictionary version of RandSmoothFieldAdjustContrast.

    The field is randomized once per invocation by default so the same field is applied to every selected key. The
    `mode` parameter specifying interpolation mode for the field can be a single value or a sequence of values with
    one for each key in `keys`.

    Args:
        keys: key names to apply the augment to
        spatial_size: size of input arrays, all arrays stated in `keys` must have same dimensions
        rand_size: size of the randomized field to start from
        pad: number of pixels/voxels along the edges of the field to pad with 0
        mode: interpolation mode to use when upsampling
        align_corners: if True align the corners when upsampling field
        prob: probability transform is applied
        gamma: (min, max) range for exponential field
        device: Pytorch device to define field on
    r   N皙?)g      ?g      @keysr   spatial_sizeSequence[int]	rand_sizepadintmoder   align_cornersbool | NoneprobfloatgammaSequence[float] | floatdevicetorch.device | Nonec
           
   
   C  N   t | | t| | t|t| j| _t|||| jd |d||	d| _d S Nr         ?)r!   r#   r$   r&   r'   r)   r+   r-   )	r   __init__r   r   lenr    r&   r   trans
selfr    r!   r#   r$   r&   r'   r)   r+   r-    r7   j/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/transforms/smooth_field/dictionary.pyr2   B      z'RandSmoothFieldAdjustContrastd.__init__seed
int | Nonestatenp.random.RandomState | Nonereturnc                       t  || | j|| | S Nsuperset_random_stater4   r6   r:   r<   	__class__r7   r8   rC   ^      z/RandSmoothFieldAdjustContrastd.set_random_statedata
Any | NoneNonec                   s$   t  d  | jr| j  d S d S r@   )rB   	randomize_do_transformr4   r6   rH   rE   r7   r8   rK   e   s   z(RandSmoothFieldAdjustContrastd.randomize"Mapping[Hashable, NdarrayOrTensor]c                 C     |    t|}| js | |D ]}t|| t d||< q|S t| |D ]\}}| j| j	|t
| j	   | || d||< q'|S N)
track_metaFrK   dictrL   key_iteratorr   r
   	enumerater4   set_moder&   r3   r6   rH   dkeyidxr7   r7   r8   __call__k   s   z'RandSmoothFieldAdjustContrastd.__call__r    r   r!   r"   r#   r"   r$   r%   r&   r   r'   r(   r)   r*   r+   r,   r-   r.   NN)r:   r;   r<   r=   r>   r   r@   rH   rI   r>   rJ   rH   rN   r>   rN   )__name__
__module____qualname____doc__r   backendr   AREAr2   rC   rK   r[   __classcell__r7   r7   rE   r8   r   ,   s    r   c                      r   ).r   a  
    Dictionary version of RandSmoothFieldAdjustIntensity.

    The field is randomized once per invocation by default so the same field is applied to every selected key. The
    `mode` parameter specifying interpolation mode for the field can be a single value or a sequence of values with
    one for each key in `keys`.

    Args:
        keys: key names to apply the augment to
        spatial_size: size of input arrays, all arrays stated in `keys` must have same dimensions
        rand_size: size of the randomized field to start from
        pad: number of pixels/voxels along the edges of the field to pad with 0
        mode: interpolation mode to use when upsampling
        align_corners: if True align the corners when upsampling field
        prob: probability transform is applied
        gamma: (min, max) range of intensity multipliers
        device: Pytorch device to define field on
    r   Nr   )r   r1   r    r   r!   r"   r#   r$   r%   r&   r   r'   r(   r)   r*   r+   r,   r-   r.   c
           
   
   C  r/   r0   )	r   r2   r   r   r3   r    r&   r   r4   r5   r7   r7   r8   r2      r9   z(RandSmoothFieldAdjustIntensityd.__init__r:   r;   r<   r=   r>   c                   r?   r@   rA   rD   rE   r7   r8   rC      rG   z0RandSmoothFieldAdjustIntensityd.set_random_staterH   rI   rJ   c                      t  d  | j  d S r@   rB   rK   r4   rM   rE   r7   r8   rK         z)RandSmoothFieldAdjustIntensityd.randomizerN   c                 C  rO   rP   rR   rW   r7   r7   r8   r[      s   z(RandSmoothFieldAdjustIntensityd.__call__r\   r]   )r:   r;   r<   r=   r>   r   r@   r^   r_   )r`   ra   rb   rc   r   rd   r   re   r2   rC   rK   r[   rf   r7   r7   rE   r8   r   z   s    r   c                
      sn   e Zd ZdZejZdejdddej	e
jejddf
d-ddZ	d.d/ fd#d$Zd0d1 fd(d)Zd2d+d,Z  ZS )3r   a5  
    Dictionary version of RandSmoothDeform.

    The field is randomized once per invocation by default so the same field is applied to every selected key. The
    `field_mode` parameter specifying interpolation mode for the field can be a single value or a sequence of values
    with one for each key in `keys`. Similarly the `grid_mode` parameter can be one value or one per key.

    Args:
        keys: key names to apply the augment to
        spatial_size: input array size to which deformation grid is interpolated
        rand_size: size of the randomized field to start from
        pad: number of pixels/voxels along the edges of the field to pad with 0
        field_mode: interpolation mode to use when upsampling the deformation field
        align_corners: if True align the corners when upsampling field
        prob: probability transform is applied
        def_range: value of the deformation range in image size fractions
        grid_dtype: type for the deformation grid calculated from the field
        grid_mode: interpolation mode used for sampling input using deformation grid
        grid_padding_mode: padding mode used for sampling input using deformation grid
        grid_align_corners: if True align the corners when sampling the deformation grid
        device: Pytorch device to define field on
    r   Nr   r1   Fr    r   r!   r"   r#   r$   r%   
field_moder   r'   r(   r)   r*   	def_ranger,   	grid_modegrid_padding_modestrgrid_align_cornersr-   r.   c                 C  sn   t | | t| | t|t| j| _t|
t| j| _t|||| jd |d||	| jd |||d| _	d S )Nr   r1   )r#   r!   r$   rj   r'   r)   rk   
grid_dtyperl   rm   ro   r-   )
r   r2   r   r   r3   r    rj   rl   r   r4   )r6   r    r!   r#   r$   rj   r'   r)   rk   rp   rl   rm   ro   r-   r7   r7   r8   r2      s$   zRandSmoothDeformd.__init__r:   r;   r<   r=   r>   c                   r?   r@   rA   rD   rE   r7   r8   rC     rG   z"RandSmoothDeformd.set_random_staterH   rI   rJ   c                   rg   r@   rh   rM   rE   r7   r8   rK     ri   zRandSmoothDeformd.randomizerN   c                 C  s   |    t|}| js | |D ]}t|| t d||< q|S t| |D ]-\}}| j| j	|t
| j	   | j| j|t
| j   | || d| jj||< q'|S rP   )rK   rS   rL   rT   r   r
   rU   r4   set_field_moderj   r3   set_grid_moderl   r-   rW   r7   r7   r8   r[     s   zRandSmoothDeformd.__call__)r    r   r!   r"   r#   r"   r$   r%   rj   r   r'   r(   r)   r*   rk   r,   rl   r   rm   rn   ro   r(   r-   r.   r]   )r:   r;   r<   r=   r>   r   r@   r^   r_   )r`   ra   rb   rc   r   rd   r   re   torchfloat32r   NEARESTr   BORDERr2   rC   rK   r[   rf   r7   r7   rE   r8   r      s$    &r   ))
__future__r   collections.abcr   r   r   typingr   numpynprs   monai.configr   r   monai.config.type_definitionsr	   monai.data.meta_objr
   Z#monai.transforms.smooth_field.arrayr   r   r   monai.transforms.transformr   r   monai.utilsr   r   r   r   r   __all__r   r   r   r   r   r   r   r   r   r7   r7   r7   r8   <module>   s$   NM\