U
    PhCL                 f   @  sN  d Z ddlmZ ddlmZmZmZm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mZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 dd	l4m5Z5m6Z6 dd
l7m8Z8 ddl9m:Z:m;Z;m<Z< ddl=m>Z> dddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrgfZ?e>@ ZAG dsd de6e5ZBG dtd de6e5ZCG dud de5ZDG dvd de6e5ZEG dwd de5ZFG dxd de6e5ZGG dyd de5ZHG dzd de6e5ZIG d{d: d:e6e5ZJG d|d de6e5ZKG d}d de5ZLG d~d de5ZMG dd de5ZNG dd de5ZOG dd de5ZPG dd de6e5ZQG dd de5ZRG dd de5ZSG dd de5ZTG dd de5ZUG dd  d e5ZVG dd! d!e6e5ZWG dd" d"e5ZXG dd# d#e6e5ZYG dd( d(e6e5ZZG dd% d%e6e5Z[G dd$ d$e5Z\G dd& d&e5Z]G dd' d'e6e5Z^G dd) d)e6e5Z_G dd* d*e6e5Z`G dd+ d+e5ZaG dd, d,e5ZbG dd- d-e5ZceB ZdZeeC ZfZgeD ZhZieE ZjZkeF ZlZmeG ZnZoeK ZpZqeH ZrZseI ZtZueJ ZvZweL ZxZyeM ZzZ{eN Z|Z}eO Z~ZeP ZZeQ ZZeR ZZeS ZZeT ZZeU ZZeV ZZeW ZZeX ZZeY ZZeZ ZZe[ ZZe\ ZZe] ZZe^ ZZe_ ZZea ZZe` ZZeb ZZec ZZdS )z
A collection of dictionary-based wrappers around the "vanilla" transforms for intensity adjustment
defined in :py:class:`monai.transforms.intensity.array`.

Class names are ended with 'd' to denote dictionary-based transforms.
    )annotations)CallableHashableMappingSequenceN)	DtypeLikeKeysCollection)NdarrayOrTensor)get_track_meta)"AdjustContrastClipIntensityPercentilesComputeHoVerMapsForegroundMaskGaussianSharpenGaussianSmooth
GibbsNoiseHistogramNormalizeKSpaceSpikeNoiseMaskIntensityMedianSmoothNormalizeIntensityRandAdjustContrastRandBiasFieldRandCoarseDropoutRandCoarseShuffleRandGaussianNoiseRandGaussianSharpenRandGaussianSmoothRandGibbsNoiseRandHistogramShiftRandKSpaceSpikeNoiseRandRicianNoiseRandScaleIntensityRandScaleIntensityFixedMeanRandShiftIntensityRandStdShiftIntensitySavitzkyGolaySmoothScaleIntensityScaleIntensityRangeScaleIntensityRangePercentilesShiftIntensityStdShiftIntensityThresholdIntensity)MapTransformRandomizableTransform)is_positive)convert_to_tensorensure_tupleensure_tuple_rep)PostFixRandGaussianNoisedRandRicianNoisedShiftIntensitydRandShiftIntensitydScaleIntensitydRandScaleIntensitydStdShiftIntensitydRandStdShiftIntensitydRandBiasFielddNormalizeIntensitydThresholdIntensitydScaleIntensityRangedClipIntensityPercentilesdAdjustContrastdRandAdjustContrastdScaleIntensityRangePercentilesdMaskIntensitydSavitzkyGolaySmoothdMedianSmoothdGaussianSmoothdRandGaussianSmoothdGaussianSharpendRandGaussianSharpendGibbsNoisedRandGibbsNoisedKSpaceSpikeNoisedRandKSpaceSpikeNoisedRandHistogramShiftdRandCoarseDropoutdRandCoarseShuffledHistogramNormalizedForegroundMaskdComputeHoVerMapsdRandGaussianNoiseDRandGaussianNoiseDictShiftIntensityDShiftIntensityDictRandShiftIntensityDRandShiftIntensityDictScaleIntensityDScaleIntensityDictStdShiftIntensityDStdShiftIntensityDictRandScaleIntensityDRandScaleIntensityDictRandScaleIntensityFixedMeandRandScaleIntensityFixedMeanDictRandScaleIntensityFixedMeanDRandStdShiftIntensityDRandStdShiftIntensityDictRandBiasFieldDRandBiasFieldDictNormalizeIntensityDNormalizeIntensityDictThresholdIntensityDThresholdIntensityDictScaleIntensityRangeDScaleIntensityRangeDictClipIntensityPercentilesDClipIntensityPercentilesDictAdjustContrastDAdjustContrastDictRandAdjustContrastDRandAdjustContrastDictScaleIntensityRangePercentilesD"ScaleIntensityRangePercentilesDictMaskIntensityDMaskIntensityDictSavitzkyGolaySmoothDSavitzkyGolaySmoothDictMedianSmoothDMedianSmoothDictGaussianSmoothDGaussianSmoothDictRandGaussianSmoothDRandGaussianSmoothDictGaussianSharpenDGaussianSharpenDictRandGaussianSharpenDRandGaussianSharpenDictGibbsNoiseDGibbsNoiseDictRandGibbsNoiseDRandGibbsNoiseDictKSpaceSpikeNoiseDKSpaceSpikeNoiseDictRandHistogramShiftDRandHistogramShiftDictRandRicianNoiseDRandRicianNoiseDictRandCoarseDropoutDRandCoarseDropoutDictRandCoarseShuffleDRandCoarseShuffleDictHistogramNormalizeDHistogramNormalizeDictRandKSpaceSpikeNoiseDRandKSpaceSpikeNoiseDictForegroundMaskDForegroundMaskDictComputeHoVerMapsDComputeHoVerMapsDictc                
      sn   e Zd ZdZejZdddejddfdddddd	d	d
dddZdddd d fddZ	dddddZ
  ZS )r4   uF  
    Dictionary-based version :py:class:`monai.transforms.RandGaussianNoise`.
    Add Gaussian noise to image. This transform assumes all the expected fields have same shape, if you want to add
    different noise for every field, please use this transform separately.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        prob: Probability to add Gaussian noise.
        mean: Mean or “centre” of the distribution.
        std: Standard deviation (spread) of distribution.
        dtype: output data type, if None, same as input image. defaults to float32.
        allow_missing_keys: don't raise exception if key is missing.
        sample_std: If True, sample the spread of the Gaussian distribution uniformly from 0 to std.
    皙?        FTr   floatr   boolNone)keysprobmeanstddtypeallow_missing_keys
sample_stdreturnc                 C  s2   t | || t| | t||d||d| _d S )N      ?)r   r   r   r   r   )r-   __init__r.   r   rand_gaussian_noise)selfr   r   r   r   r   r   r    r   Z/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/transforms/intensity/dictionary.pyr      s    
zRandGaussianNoised.__init__N
int | Nonenp.random.RandomState | Noneseedstater   c                   s    t  || | j|| | S N)superset_random_stater   r   r   r   	__class__r   r   r      s    z#RandGaussianNoised.set_random_state"Mapping[Hashable, NdarrayOrTensor]dict[Hashable, NdarrayOrTensor]datar   c                 C  s   t |}| d  | jsB| |D ]}t|| t d||< q"|S | |}|dkr~| |D ]}t|| t d||< q^|S | j||  | |D ]}| j|| dd||< q|S )N
track_metar   Fimg	randomize)dictr   _do_transformkey_iteratorr0   r
   	first_keyr   r   r   dkeyr   r   r   r   __call__   s    

zRandGaussianNoised.__call__)NN)__name__
__module____qualname____doc__r   backendnpfloat32r   r   r   __classcell__r   r   r   r   r4      s      c                      sv   e Zd ZdZejZddddddejdfddd	d	d
d
d
dd
dd
ddZdddd d fddZ	dddddZ
  ZS )r5   a  
    Dictionary-based version :py:class:`monai.transforms.RandRicianNoise`.
    Add Rician noise to image. This transform assumes all the expected fields have same shape, if want to add
    different noise for every field, please use this transform separately.

    Args:
        keys: Keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        prob: Probability to add Rician noise to the dictionary.
        mean: Mean or "centre" of the Gaussian distributions sampled to make up
            the Rician noise.
        std: Standard deviation (spread) of the Gaussian distributions sampled
            to make up the Rician noise.
        channel_wise: If True, treats each channel of the image separately.
        relative: If True, the spread of the sampled Gaussian distributions will
            be std times the standard deviation of the image or channel's intensity
            histogram.
        sample_std: If True, sample the spread of the Gaussian distributions
            uniformly from 0 to std.
        dtype: output data type, if None, same as input image. defaults to float32.
        allow_missing_keys: Don't raise exception if key is missing.
    r   r   r   FTr   r   Sequence[float] | floatr   r   r   )
r   r   r   r   channel_wiserelativer   r   r   r   c
           
   	   C  s6   t | ||	 t| | td||||||d| _d S )Nr   )r   r   r   r   r   r   r   )r-   r   r.   r!   rand_rician_noise)
r   r   r   r   r   r   r   r   r   r   r   r   r   r     s    zRandRicianNoised.__init__Nr   r   r   c                   s    t  || | j|| | S r   )r   r   r   r   r   r   r   r      s    z!RandRicianNoised.set_random_stater   r   r   c                 C  sl   t |}| d  | jsB| |D ]}t|| t d||< q"|S | |D ]}| j|| dd||< qL|S Nr   Tr   )r   r   r   r   r0   r
   r   r   r   r   r   r   r   r   r   %  s    
zRandRicianNoised.__call__)NN)r   r   r   r   r!   r   r   r   r   r   r   r   r   r   r   r   r5      s   "c                
      sT   e Zd ZdZejZdddedfdddddd	dd
d fddZddddZ  Z	S )r6   zR
    Dictionary-based wrapper of :py:class:`monai.transforms.ShiftIntensity`.
    FNr   r   r   
str | NoneKeysCollection | Nonestrr   )r   offsetsafe
factor_key	meta_keysmeta_key_postfixr   r   c                   s   t  || t|t| j| _|dkr8tdt| jnt|| _t| jt| jkr^tdt|t| j| _	t
||| _dS )a  
        Args:
            keys: keys of the corresponding items to be transformed.
                See also: :py:class:`monai.transforms.compose.MapTransform`
            offset: offset value to shift the intensity of image.
            safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`.
                E.g., `[256, -12]` -> `[array(0), array(244)]`. If `True`, then `[256, -12]` -> `[array(255), array(0)]`.
            factor_key: if not None, use it as the key to extract a value from the corresponding
                metadata dictionary of `key` at runtime, and multiply the `offset` to shift intensity.
                Usually, `IntensityStatsd` transform can pre-compute statistics of intensity values
                and store in the metadata.
                it also can be a sequence of strings, map to `keys`.
            meta_keys: explicitly indicate the key of the corresponding metadata dictionary.
                used to extract the factor value is `factor_key` is not None.
                for example, for data with key `image`, the metadata by default is in `image_meta_dict`.
                the metadata is a dictionary object which contains: filename, original_shape, etc.
                it can be a sequence of string, map to the `keys`.
                if None, will try to construct meta_keys by `key_{meta_key_postfix}`.
            meta_key_postfix: if meta_keys is None, use `key_{postfix}` to fetch the metadata according
                to the key data, default is `meta_dict`, the metadata is a dictionary object.
                used to extract the factor value is `factor_key` is not None.
            allow_missing_keys: don't raise exception if key is missing.
        N.meta_keys should have the same length as keys.)r   r   r2   lenr   r   r1   r   
ValueErrorr   r*   shifter)r   r   r   r   r   r   r   r   r   r   r   r   9  s    !"zShiftIntensityd.__init__r   r   c           	      C  s   t |}| || j| j| jD ]f\}}}}|p:| d| }||krR|| |nd }|d krbd n
| jj| }| j|| |d||< q|S )N_)r   )r   r   r   r   r   getr   r   )	r   r   r   r   r   meta_keyr   factorr   r   r   r   r   b  s       zShiftIntensityd.__call__)
r   r   r   r   r*   r   DEFAULT_POST_FIXr   r   r   r   r   r   r   r6   2  s   ")c                      sp   e Zd ZdZejZdddedddfddddd	d
ddddd
ddZdddd d fddZddddZ	  Z
S )r7   zS
    Dictionary-based version :py:class:`monai.transforms.RandShiftIntensity`.
    FNr   r   tuple[float, float] | floatr   r   r   r   r   r   )
r   offsetsr   r   r   r   r   r   r   r   c
           
      C  s   t | ||	 t| | t|t| j| _|dkrDtdt| jnt|| _t| jt| jkrjt	dt|t| j| _
t||d|d| _dS )a  
        Args:
            keys: keys of the corresponding items to be transformed.
                See also: :py:class:`monai.transforms.compose.MapTransform`
            offsets: offset range to randomly shift.
                if single number, offset value is picked from (-offsets, offsets).
            safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`.
                E.g., `[256, -12]` -> `[array(0), array(244)]`. If `True`, then `[256, -12]` -> `[array(255), array(0)]`.
            factor_key: if not None, use it as the key to extract a value from the corresponding
                metadata dictionary of `key` at runtime, and multiply the random `offset` to shift intensity.
                Usually, `IntensityStatsd` transform can pre-compute statistics of intensity values
                and store in the metadata.
                it also can be a sequence of strings, map to `keys`.
            meta_keys: explicitly indicate the key of the corresponding metadata dictionary.
                used to extract the factor value is `factor_key` is not None.
                for example, for data with key `image`, the metadata by default is in `image_meta_dict`.
                the metadata is a dictionary object which contains: filename, original_shape, etc.
                it can be a sequence of string, map to the `keys`.
                if None, will try to construct meta_keys by `key_{meta_key_postfix}`.
            meta_key_postfix: if meta_keys is None, use `key_{postfix}` to fetch the metadata according
                to the key data, default is `meta_dict`, the metadata is a dictionary object.
                used to extract the factor value is `factor_key` is not None.
            prob: probability of shift.
                (Default 0.1, with 10% probability it returns an array shifted intensity.)
            channel_wise: if True, shift intensity on each channel separately. For each channel, a random offset will be chosen.
                Please ensure that the first dimension represents the channel of the image if True.
            allow_missing_keys: don't raise exception if key is missing.
        Nr   r   )r   r   r   r   )r-   r   r.   r2   r   r   r   r1   r   r   r   r$   r   )
r   r   r   r   r   r   r   r   r   r   r   r   r   r   u  s    ("zRandShiftIntensityd.__init__r   r   r   c                   s    t  || | j|| | S r   r   r   r   r   r   r   r   r     s    z$RandShiftIntensityd.set_random_stater   r   c           	      C  s   t |}| d  | jsB| |D ]}t|| t d||< q"|S | |}|dkr~| |D ]}t|| t d||< q^|S | j||  | || j| j	| j
D ]P\}}}}|p| d| }||kr|| |nd }| j|| |dd||< q|S )Nr   r   r   F)r   r   )r   r   r   r   r0   r
   r   r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   r   r   r   r     s,    

   zRandShiftIntensityd.__call__)NN)r   r   r   r   r$   r   r   r   r   r   r   r   r   r   r   r7   n  s   "3   c                	      sT   e Zd ZdZejZddejdfdddddddd fd	d
ZdddddZ	  Z
S )r:   zU
    Dictionary-based wrapper of :py:class:`monai.transforms.StdShiftIntensity`.
    Fr   r   r   r   r   )r   r   nonzeror   r   r   r   c                   s"   t  || t||||| _dS )ap  
        Args:
            keys: keys of the corresponding items to be transformed.
                See also: :py:class:`monai.transforms.compose.MapTransform`
            factor: factor shift by ``v = v + factor * std(v)``.
            nonzero: whether only count non-zero values.
            channel_wise: if True, calculate on each channel separately. Please ensure
                that the first dimension represents the channel of the image if True.
            dtype: output data type, if None, same as input image. defaults to float32.
            allow_missing_keys: don't raise exception if key is missing.
        N)r   r   r+   r   )r   r   r   r   r   r   r   r   r   r   r     s    zStdShiftIntensityd.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   )r   r   r   r   r   r   r   r     s    zStdShiftIntensityd.__call__)r   r   r   r   r+   r   r   r   r   r   r   r   r   r   r   r:     s    c                
      sl   e Zd ZdZejZdddejdfdddddddd	d
ddZdddd d fddZ	dddddZ
  ZS )r;   zV
    Dictionary-based version :py:class:`monai.transforms.RandStdShiftIntensity`.
    r   Fr   r   r   r   r   r   )r   factorsr   r   r   r   r   r   c                 C  s2   t | || t| | t||||dd| _dS )a  
        Args:
            keys: keys of the corresponding items to be transformed.
                See also: :py:class:`monai.transforms.compose.MapTransform`
            factors: if tuple, the randomly picked range is (min(factors), max(factors)).
                If single number, the range is (-factors, factors).
            prob: probability of std shift.
            nonzero: whether only count non-zero values.
            channel_wise: if True, calculate on each channel separately.
            dtype: output data type, if None, same as input image. defaults to float32.
            allow_missing_keys: don't raise exception if key is missing.
        r   )r   r   r   r   r   N)r-   r   r.   r%   r   )r   r   r   r   r   r   r   r   r   r   r   r     s        zRandStdShiftIntensityd.__init__Nr   r   r   c                   s    t  || | j|| | S r   r   r   r   r   r   r     s    z'RandStdShiftIntensityd.set_random_stater   r   r   c                 C  sx   t |}| d  | jsB| |D ]}t|| t d||< q"|S | jd  | |D ]}| j|| dd||< qX|S Nr   Fr   r   r   r   r   r0   r
   r   r   r   r   r   r     s    
zRandStdShiftIntensityd.__call__)NN)r   r   r   r   r%   r   r   r   r   r   r   r   r   r   r   r   r;     s      c                
      sZ   e Zd ZdZejZddddejdfdddddd	dd
d fddZdddddZ	  Z
S )r8   a   
    Dictionary-based wrapper of :py:class:`monai.transforms.ScaleIntensity`.
    Scale the intensity of input image to the given value range (minv, maxv).
    If `minv` and `maxv` not provided, use `factor` to scale image by ``v = v * (1 + factor)``.
    r   r   NFr   float | Noner   r   r   )r   minvmaxvr   r   r   r   r   c                   s$   t  || t|||||| _dS )a  
        Args:
            keys: keys of the corresponding items to be transformed.
                See also: :py:class:`monai.transforms.compose.MapTransform`
            minv: minimum value of output data.
            maxv: maximum value of output data.
            factor: factor scale by ``v = v * (1 + factor)``. In order to use
                this parameter, please set both `minv` and `maxv` into None.
            channel_wise: if True, scale on each channel separately. Please ensure
                that the first dimension represents the channel of the image if True.
            dtype: output data type, if None, same as input image. defaults to float32.
            allow_missing_keys: don't raise exception if key is missing.

        N)r   r   r'   scaler)r   r   r   r   r   r   r   r   r   r   r   r   /  s    zScaleIntensityd.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   r   r   r   r   r   r   r   r   J  s    zScaleIntensityd.__call__)r   r   r   r   r'   r   r   r   r   r   r   r   r   r   r   r8   &  s   "c                	      sh   e Zd ZdZejZddejdfddddddd	d
ddZdddd d fddZ	dddddZ
  ZS )r9   zS
    Dictionary-based version :py:class:`monai.transforms.RandScaleIntensity`.
    r   Fr   r   r   r   r   r   )r   r   r   r   r   r   r   c                 C  s0   t | || t| | t||d|d| _dS )a  
        Args:
            keys: keys of the corresponding items to be transformed.
                See also: :py:class:`monai.transforms.compose.MapTransform`
            factors: factor range to randomly scale by ``v = v * (1 + factor)``.
                if single number, factor value is picked from (-factors, factors).
            prob: probability of scale.
                (Default 0.1, with 10% probability it returns a scaled array.)
            channel_wise: if True, scale on each channel separately. Please ensure
                that the first dimension represents the channel of the image if True.
            dtype: output data type, if None, same as input image. defaults to float32.
            allow_missing_keys: don't raise exception if key is missing.

        r   )r   r   r   r   N)r-   r   r.   r"   r   )r   r   r   r   r   r   r   r   r   r   r   X  s    zRandScaleIntensityd.__init__Nr   r   r   c                   s    t  || | j|| | S r   r   r   r   r   r   r   r   r   s  s    z$RandScaleIntensityd.set_random_stater   r   r   c                 C  s   t |}| d  | jsB| |D ]}t|| t d||< q"|S | |}|dkr~| |D ]}t|| t d||< q^|S | j||  | |D ]}| j|| dd||< q|S )Nr   r   Fr   )r   r   r   r   r0   r
   r   r   r   r   r   r   r   z  s    

zRandScaleIntensityd.__call__)NN)r   r   r   r   r"   r   r   r   r   r   r   r   r   r   r   r   r9   Q  s      c                
      sl   e Zd ZdZejZdddejdfdddddd	dd
dddZdddd d fddZ	dddddZ
  ZS )ra   z
    Dictionary-based version :py:class:`monai.transforms.RandScaleIntensity`.
    Subtract the mean intensity before scaling with `factor`, then add the same value after scaling
    to ensure that the output has the same mean as the input.
    TFr   r   r   r   r   r   r   )r   r   
fixed_meanpreserve_ranger   r   r   r   c                 C  s@   t | || t| | || _|| _t|| j||dd| _dS )a+  
        Args:
            keys: keys of the corresponding items to be transformed.
                See also: :py:class:`monai.transforms.compose.MapTransform`
            factors: factor range to randomly scale by ``v = v * (1 + factor)``.
                if single number, factor value is picked from (-factors, factors).
            preserve_range: clips the output array/tensor to the range of the input array/tensor
            fixed_mean: subtract the mean intensity before scaling with `factor`, then add the same value after scaling
                to ensure that the output has the same mean as the input.
            channel_wise: if True, scale on each channel separately. `preserve_range` and `fixed_mean` are also applied
            on each channel separately if `channel_wise` is True. Please ensure that the first dimension represents the
            channel of the image if True.
            dtype: output data type, if None, same as input image. defaults to float32.
            allow_missing_keys: don't raise exception if key is missing.

        r   )r   r   r   r   r   N)r-   r   r.   r   r   r#   r   )r   r   r   r   r   r   r   r   r   r   r   r     s        z%RandScaleIntensityFixedMeand.__init__Nr   r   r   c                   s    t  || | j|| | S r   r   r   r   r   r   r     s    z-RandScaleIntensityFixedMeand.set_random_stater   r   r   c                 C  sx   t |}| d  | jsB| |D ]}t|| t d||< q"|S | jd  | |D ]}| j|| dd||< qX|S r   )r   r   r   r   r0   r
   r   r   r   r   r   r     s    
z%RandScaleIntensityFixedMeand.__call__)NN)r   r   r   r   r#   r   r   r   r   r   r   r   r   r   r   r   ra     s   #   c                	      sj   e Zd ZdZejZddejddfdddd	d
dddddZdddd d fddZ	dddddZ
  ZS )r<   zN
    Dictionary-based version :py:class:`monai.transforms.RandBiasField`.
       )r   r   r   Fr   inttuple[float, float]r   r   r   r   )r   degreecoeff_ranger   r   r   r   c                 C  s0   t | || t| | t|||dd| _dS )aQ  
        Args:
            keys: keys of the corresponding items to be transformed.
                See also: :py:class:`monai.transforms.compose.MapTransform`
            degree: degree of freedom of the polynomials. The value should be no less than 1.
                Defaults to 3.
            coeff_range: range of the random coefficients. Defaults to (0.0, 0.1).
            dtype: output data type, if None, same as input image. defaults to float32.
            prob: probability to do random bias field.
            allow_missing_keys: don't raise exception if key is missing.

        r   )r   r   r   r   N)r-   r   r.   r   rand_bias_field)r   r   r   r   r   r   r   r   r   r   r     s    zRandBiasFieldd.__init__Nr   r   r   c                   s    t  || | j|| | S r   )r   r   r   r   r   r   r   r     s    zRandBiasFieldd.set_random_stater   r   r   c                 C  s   t |}| d  | jsB| |D ]}t|| t d||< q"|S | |}|dkr~| |D ]}t|| t d||< q^|S | jj|| jdd  d | |D ]}| j|| dd||< q|S )Nr   r      )img_sizeFr   )	r   r   r   r   r0   r
   r   r   shaper   r   r   r   r     s    

zRandBiasFieldd.__call__)NN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r<     s   c                
      sZ   e Zd ZdZejZddddejdfddddddddd	 fd
dZdddddZ	  Z
S )r=   aT  
    Dictionary-based wrapper of :py:class:`monai.transforms.NormalizeIntensity`.
    This transform can normalize only non-zero values or entire image, and can also calculate
    mean and std on each channel separately.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: monai.transforms.MapTransform
        subtrahend: the amount to subtract by (usually the mean)
        divisor: the amount to divide by (usually the standard deviation)
        nonzero: whether only normalize non-zero values.
        channel_wise: if True, calculate on each channel separately, otherwise, calculate on
            the entire image directly. default to False.
        dtype: output data type, if None, same as input image. defaults to float32.
        allow_missing_keys: don't raise exception if key is missing.
    NFr   NdarrayOrTensor | Noner   r   r   )r   
subtrahenddivisorr   r   r   r   r   c                   s$   t  || t|||||| _d S r   )r   r   r   
normalizer)r   r   r  r  r   r   r   r   r   r   r   r   !  s    
zNormalizeIntensityd.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   )r   r   r  r   r   r   r   r   .  s    zNormalizeIntensityd.__call__)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r=     s   "c                      sH   e Zd ZdZejZdddddddd	 fd
dZdddddZ  ZS )r>   a  
    Dictionary-based wrapper of :py:class:`monai.transforms.ThresholdIntensity`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: monai.transforms.MapTransform
        threshold: the threshold to filter intensity values.
        above: filter values above the threshold or below the threshold, default is True.
        cval: value to fill the remaining parts of the image, default is 0.
        allow_missing_keys: don't raise exception if key is missing.
    Tr   Fr   r   r   r   )r   	thresholdabovecvalr   r   c                   s    t  || t|||| _d S r   )r   r   r,   filter)r   r   r  r  r  r   r   r   r   r   D  s    zThresholdIntensityd.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   )r   r   r	  r   r   r   r   r   O  s    zThresholdIntensityd.__call__)Tr   F)	r   r   r   r   r,   r   r   r   r   r   r   r   r   r>   5  s      c                      sZ   e Zd ZdZejZdddejdfddddddddd	d
	 fddZdddddZ	  Z
S )r?   aU  
    Dictionary-based wrapper of :py:class:`monai.transforms.ScaleIntensityRange`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: monai.transforms.MapTransform
        a_min: intensity original range min.
        a_max: intensity original range max.
        b_min: intensity target range min.
        b_max: intensity target range max.
        clip: whether to perform clip after scaling.
        dtype: output data type, if None, same as input image. defaults to float32.
        allow_missing_keys: don't raise exception if key is missing.
    NFr   r   r   r   r   r   )	r   a_mina_maxb_minb_maxclipr   r   r   c	           	        s&   t  || t||||||| _d S r   )r   r   r(   r   )	r   r   r
  r  r  r  r  r   r   r   r   r   r   h  s    zScaleIntensityRanged.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   r   r   r   r   r   r   v  s    zScaleIntensityRanged.__call__)r   r   r   r   r(   r   r   r   r   r   r   r   r   r   r   r?   V  s   $c                
      sP   e Zd ZdZddejdfddddddddd	 fd
dZdddddZ  ZS )r@   a  
    Dictionary-based wrapper of :py:class:`monai.transforms.ClipIntensityPercentiles`.
    Clip the intensity values of input image to a specific range based on the intensity distribution of the input.
    If `sharpness_factor` is provided, the intensity values will be soft clipped according to
    f(x) = x + (1/sharpness_factor) * softplus(- c(x - minv)) - (1/sharpness_factor)*softplus(c(x - maxv))
    NFr   r   r   r   r   )r   loweruppersharpness_factorr   r   r   r   c                   s&   t  || t|||||d| _d S )N)r  r  r  r   r   )r   r   r   r   )r   r   r  r  r  r   r   r   r   r   r   r     s    
    z"ClipIntensityPercentilesd.__init__r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   r   r   r   r   r   r     s    z"ClipIntensityPercentilesd.__call__)	r   r   r   r   r   r   r   r   r   r   r   r   r   r@   }  s   "c                      sH   e Zd ZdZejZdddddddd fdd	Zd
ddddZ  ZS )rA   aV  
    Dictionary-based wrapper of :py:class:`monai.transforms.AdjustContrast`.
    Changes image intensity with gamma transform. Each pixel/voxel intensity is updated as:

        `x = ((x - min) / intensity_range) ^ gamma * intensity_range + min`

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: monai.transforms.MapTransform
        gamma: gamma value to adjust the contrast as function.
        invert_image: whether to invert the image before applying gamma augmentation. If True, multiply all intensity
            values with -1 before the gamma transform and again after the gamma transform. This behaviour is mimicked
            from `nnU-Net <https://www.nature.com/articles/s41592-020-01008-z>`_, specifically `this
            <https://github.com/MIC-DKFZ/batchgenerators/blob/7fb802b28b045b21346b197735d64f12fbb070aa/batchgenerators/augmentations/color_augmentations.py#L107>`_
            function.
        retain_stats: if True, applies a scaling factor and an offset to all intensity values after gamma transform to
            ensure that the output intensity distribution has the same mean and standard deviation as the intensity
            distribution of the input. This behaviour is mimicked from `nnU-Net
            <https://www.nature.com/articles/s41592-020-01008-z>`_, specifically `this
            <https://github.com/MIC-DKFZ/batchgenerators/blob/7fb802b28b045b21346b197735d64f12fbb070aa/batchgenerators/augmentations/color_augmentations.py#L107>`_
            function.
        allow_missing_keys: don't raise exception if key is missing.
    Fr   r   r   r   )r   gammainvert_imageretain_statsr   r   c                   s    t  || t|||| _d S r   )r   r   r   adjuster)r   r   r  r  r  r   r   r   r   r     s    zAdjustContrastd.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   )r   r   r  r   r   r   r   r     s    zAdjustContrastd.__call__)FFF)	r   r   r   r   r   r   r   r   r   r   r   r   r   rA     s      c                	      s^   e Zd ZdZejZdddddddd	d
ddZdddd d fddZdddddZ  Z	S )rB   a  
    Dictionary-based version :py:class:`monai.transforms.RandAdjustContrast`.
    Randomly changes image intensity with gamma transform. Each pixel/voxel intensity is updated as:

        `x = ((x - min) / intensity_range) ^ gamma * intensity_range + min`

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: monai.transforms.MapTransform
        prob: Probability of adjustment.
        gamma: Range of gamma values.
            If single number, value is picked from (0.5, gamma), default is (0.5, 4.5).
        invert_image: whether to invert the image before applying gamma augmentation. If True, multiply all intensity
            values with -1 before the gamma transform and again after the gamma transform. This behaviour is mimicked
            from `nnU-Net <https://www.nature.com/articles/s41592-020-01008-z>`_, specifically `this
            <https://github.com/MIC-DKFZ/batchgenerators/blob/7fb802b28b045b21346b197735d64f12fbb070aa/batchgenerators/augmentations/color_augmentations.py#L107>`_
            function.
        retain_stats: if True, applies a scaling factor and an offset to all intensity values after gamma transform to
            ensure that the output intensity distribution has the same mean and standard deviation as the intensity
            distribution of the input. This behaviour is mimicked from `nnU-Net
            <https://www.nature.com/articles/s41592-020-01008-z>`_, specifically `this
            <https://github.com/MIC-DKFZ/batchgenerators/blob/7fb802b28b045b21346b197735d64f12fbb070aa/batchgenerators/augmentations/color_augmentations.py#L107>`_
            function.
        allow_missing_keys: don't raise exception if key is missing.
    r         ?g      @Fr   r   r   r   r   )r   r   r  r  r  r   r   c                 C  s6   t | || t| | t|d||d| _|| _d S )Nr   )r  r   r  r  )r-   r   r.   r   r  r  )r   r   r   r  r  r  r   r   r   r   r     s    	zRandAdjustContrastd.__init__Nr   r   r   c                   s    t  || | j|| | S r   )r   r   r  r   r   r   r   r     s    z$RandAdjustContrastd.set_random_stater   r   r   c                 C  sx   t |}| d  | jsB| |D ]}t|| t d||< q"|S | jd  | |D ]}| j|| dd||< qX|S r   )r   r   r   r   r0   r
   r  r   r   r   r   r     s    
zRandAdjustContrastd.__call__)r   r  FFF)NN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   rB     s           c                      s^   e Zd ZdZejZdddejdfdddddddddddd	 fd
dZdddddZ	  Z
S )rC   a   
    Dictionary-based wrapper of :py:class:`monai.transforms.ScaleIntensityRangePercentiles`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: monai.transforms.MapTransform
        lower: lower percentile.
        upper: upper percentile.
        b_min: intensity target range min.
        b_max: intensity target range max.
        clip: whether to perform clip after scaling.
        relative: whether to scale to the corresponding percentiles of [b_min, b_max]
        channel_wise: if True, compute intensity percentile and normalize every channel separately.
            default to False.
        dtype: output data type, if None, same as input image. defaults to float32.
        allow_missing_keys: don't raise exception if key is missing.
    Fr   r   r   r   r   r   )r   r  r  r  r  r  r   r   r   r   r   c              	     s*   t  ||
 t||||||||	| _d S r   )r   r   r)   r   )r   r   r  r  r  r  r  r   r   r   r   r   r   r   r     s    z(ScaleIntensityRangePercentilesd.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   r   r   r   r   r   r   .  s    z(ScaleIntensityRangePercentilesd.__call__)r   r   r   r   r)   r   r   r   r   r   r   r   r   r   r   rC   	  s   	(c                      sP   e Zd ZdZejZddedfdddddd	d
 fddZdddddZ  Z	S )rD   a  
    Dictionary-based wrapper of :py:class:`monai.transforms.MaskIntensity`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        mask_data: if mask data is single channel, apply to every channel
            of input image. if multiple channels, the channel number must
            match input data. the intensity values of input image corresponding
            to the selected values in the mask data will keep the original value,
            others will be set to `0`. if None, will extract the mask data from
            input data based on `mask_key`.
        mask_key: the key to extract mask data from input dictionary, only works
            when `mask_data` is None.
        select_fn: function to select valid values of the `mask_data`, default is
            to select `values > 0`.
        allow_missing_keys: don't raise exception if key is missing.

    NFr   r  r   r   r   r   )r   	mask_datamask_key	select_fnr   r   c                   s2   t  || t||d| _|d kr(|nd | _d S )N)r  r  )r   r   r   	converterr  )r   r   r  r  r  r   r   r   r   r   L  s    zMaskIntensityd.__init__r   r   r   c                 C  sN   t |}| |D ]6}| jd k	r6| || || j n| || ||< q|S r   )r   r   r  r  r   r   r   r   r   X  s    4zMaskIntensityd.__call__)
r   r   r   r   r   r   r/   r   r   r   r   r   r   r   rD   5  s   c                	      sJ   e Zd ZdZejZdddddddd	d
 fddZdddddZ  ZS )rE   a$  
    Dictionary-based wrapper of :py:class:`monai.transforms.SavitzkyGolaySmooth`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        window_length: length of the filter window, must be a positive odd integer.
        order: order of the polynomial to fit to each window, must be less than ``window_length``.
        axis: optional axis along which to apply the filter kernel. Default 1 (first spatial dimension).
        mode: optional padding mode, passed to convolution class. ``'zeros'``, ``'reflect'``, ``'replicate'``
            or ``'circular'``. default: ``'zeros'``. See ``torch.nn.Conv1d()`` for more information.
        allow_missing_keys: don't raise exception if key is missing.

    r   zerosFr   r   r   r   r   )r   window_lengthorderaxismoder   r   c                   s$   t  || t||||d| _d S )N)r  r  r  r   )r   r   r&   r  )r   r   r  r  r  r   r   r   r   r   r   q  s    	zSavitzkyGolaySmoothd.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   r   r   r  r   r   r   r   r   }  s    zSavitzkyGolaySmoothd.__call__)r   r  F)	r   r   r   r   r&   r   r   r   r   r   r   r   r   rE   _  s       c                      sD   e Zd ZdZejZdddddd fdd	Zd
ddddZ  ZS )rF   a  
    Dictionary-based wrapper of :py:class:`monai.transforms.MedianSmooth`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        radius: if a list of values, must match the count of spatial dimensions of input data,
            and apply every value in the list to 1 spatial dimension. if only 1 value provided,
            use it for all spatial dimensions.
        allow_missing_keys: don't raise exception if key is missing.

    Fr   Sequence[int] | intr   r   )r   radiusr   r   c                   s   t  || t|| _d S r   )r   r   r   r  )r   r   r#  r   r   r   r   r     s    zMedianSmoothd.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   r!  r   r   r   r   r     s    zMedianSmoothd.__call__)F)	r   r   r   r   r   r   r   r   r   r   r   r   r   rF     s   c                      sF   e Zd ZdZejZddddddd	 fd
dZdddddZ  ZS )rG   a  
    Dictionary-based wrapper of :py:class:`monai.transforms.GaussianSmooth`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        sigma: if a list of values, must match the count of spatial dimensions of input data,
            and apply every value in the list to 1 spatial dimension. if only 1 value provided,
            use it for all spatial dimensions.
        approx: discrete Gaussian kernel type, available options are "erf", "sampled", and "scalespace".
            see also :py:meth:`monai.networks.layers.GaussianFilter`.
        allow_missing_keys: don't raise exception if key is missing.

    erfFr   r   r   r   r   )r   sigmaapproxr   r   c                   s    t  || t||d| _d S N)r&  )r   r   r   r  )r   r   r%  r&  r   r   r   r   r     s    zGaussianSmoothd.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   r!  r   r   r   r   r     s    zGaussianSmoothd.__call__)r$  F)	r   r   r   r   r   r   r   r   r   r   r   r   r   rG     s     
c                
      s`   e Zd ZdZejZddddddd	d
ddddZdddd d fddZdddddZ  Z	S )rH   a  
    Dictionary-based wrapper of :py:class:`monai.transforms.GaussianSmooth`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        sigma_x: randomly select sigma value for the first spatial dimension.
        sigma_y: randomly select sigma value for the second spatial dimension if have.
        sigma_z: randomly select sigma value for the third spatial dimension if have.
        approx: discrete Gaussian kernel type, available options are "erf", "sampled", and "scalespace".
            see also :py:meth:`monai.networks.layers.GaussianFilter`.
        prob: probability of Gaussian smooth.
        allow_missing_keys: don't raise exception if key is missing.

    g      ?g      ?r$  r   Fr   r   r   r   r   r   )r   sigma_xsigma_ysigma_zr&  r   r   r   c                 C  s2   t | || t| | t||||dd| _d S )Nr   )r)  r*  r+  r&  r   )r-   r   r.   r   rand_smooth)r   r   r)  r*  r+  r&  r   r   r   r   r   r     s    
    zRandGaussianSmoothd.__init__Nr   r   r   c                   s    t  || | j|| | S r   )r   r   r,  r   r   r   r   r     s    z$RandGaussianSmoothd.set_random_stater   r   r   c                 C  sx   t |}| d  | jsB| |D ]}t|| t d||< q"|S | jd  | |D ]}| j|| dd||< qX|S r   )r   r   r   r   r0   r
   r,  r   r   r   r   r     s    
zRandGaussianSmoothd.__call__)r(  r(  r(  r$  r   F)NN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   rH     s            c                	      sJ   e Zd ZdZejZddddd	d
ddd fddZdddddZ  ZS )rI   aT  
    Dictionary-based wrapper of :py:class:`monai.transforms.GaussianSharpen`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        sigma1: sigma parameter for the first gaussian kernel. if a list of values, must match the count
            of spatial dimensions of input data, and apply every value in the list to 1 spatial dimension.
            if only 1 value provided, use it for all spatial dimensions.
        sigma2: sigma parameter for the second gaussian kernel. if a list of values, must match the count
            of spatial dimensions of input data, and apply every value in the list to 1 spatial dimension.
            if only 1 value provided, use it for all spatial dimensions.
        alpha: weight parameter to compute the final result.
        approx: discrete Gaussian kernel type, available options are "erf", "sampled", and "scalespace".
            see also :py:meth:`monai.networks.layers.GaussianFilter`.
        allow_missing_keys: don't raise exception if key is missing.

          @r         >@r$  Fr   r   r   r   r   r   )r   sigma1sigma2alphar&  r   r   c                   s$   t  || t||||d| _d S r'  )r   r   r   r  )r   r   r/  r0  r1  r&  r   r   r   r   r     s    	zGaussianSharpend.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   r!  r   r   r   r   r     s    zGaussianSharpend.__call__)r-  r   r.  r$  F)	r   r   r   r   r   r   r   r   r   r   r   r   r   rI     s         c                      sf   e Zd ZdZejZddd	d	d	d
d
d
d	ddddddZdddd d fddZdddddZ  Z	S )rJ   aP  
    Dictionary-based wrapper of :py:class:`monai.transforms.GaussianSharpen`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        sigma1_x: randomly select sigma value for the first spatial dimension of first gaussian kernel.
        sigma1_y: randomly select sigma value for the second spatial dimension(if have) of first gaussian kernel.
        sigma1_z: randomly select sigma value for the third spatial dimension(if have) of first gaussian kernel.
        sigma2_x: randomly select sigma value for the first spatial dimension of second gaussian kernel.
            if only 1 value `X` provided, it must be smaller than `sigma1_x` and randomly select from [X, sigma1_x].
        sigma2_y: randomly select sigma value for the second spatial dimension(if have) of second gaussian kernel.
            if only 1 value `Y` provided, it must be smaller than `sigma1_y` and randomly select from [Y, sigma1_y].
        sigma2_z: randomly select sigma value for the third spatial dimension(if have) of second gaussian kernel.
            if only 1 value `Z` provided, it must be smaller than `sigma1_z` and randomly select from [Z, sigma1_z].
        alpha: randomly select weight parameter to compute the final result.
        approx: discrete Gaussian kernel type, available options are "erf", "sampled", and "scalespace".
            see also :py:meth:`monai.networks.layers.GaussianFilter`.
        prob: probability of Gaussian sharpen.
        allow_missing_keys: don't raise exception if key is missing.

    r  r   r  g      $@r.  r$  r   Fr   r   r   r   r   r   )r   sigma1_xsigma1_ysigma1_zsigma2_xsigma2_ysigma2_zr1  r&  r   r   c                 C  s:   t | || t| |
 t||||||||	dd	| _d S )Nr   )	r4  r5  r6  r7  r8  r9  r1  r&  r   )r-   r   r.   r   rand_sharpen)r   r   r4  r5  r6  r7  r8  r9  r1  r&  r   r   r   r   r   r   >  s    zRandGaussianSharpend.__init__Nr   r   r   c                   s    t  || | j|| | S r   )r   r   r:  r   r   r   r   r   Z  s    z%RandGaussianSharpend.set_random_stater   r   c                 C  sx   t |}| d  | jsB| |D ]}t|| t d||< q"|S | jd  | |D ]}| j|| dd||< qX|S r   )r   r   r   r   r0   r
   r:  r   r   r   r   r   a  s    
zRandGaussianSharpend.__call__)
r2  r2  r2  r  r  r  r3  r$  r   F)NN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   rJ   $  s"             $   c                      sZ   e Zd ZdZejZdddddd	d
ddZdddd d fddZdddddZ  Z	S )rO   a  
    Dictionary-based version :py:class:`monai.transforms.RandHistogramShift`.
    Apply random nonlinear transform the image's intensity histogram.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: monai.transforms.MapTransform
        num_control_points: number of control points governing the nonlinear intensity mapping.
            a smaller number of control points allows for larger intensity shifts. if two values provided, number of
            control points selecting from range (min_value, max_value).
        prob: probability of histogram shift.
        allow_missing_keys: don't raise exception if key is missing.
    
   r   Fr   ztuple[int, int] | intr   r   r   )r   num_control_pointsr   r   r   c                 C  s,   t | || t| | t|dd| _d S )Nr   )r<  r   )r-   r   r.   r   r   )r   r   r<  r   r   r   r   r   r     s    zRandHistogramShiftd.__init__Nr   r   r   c                   s    t  || | j|| | S r   r   r   r   r   r   r     s    z$RandHistogramShiftd.set_random_stater   r   c                 C  sx   t |}| d  | jsB| |D ]}t|| t d||< q"|S | jd  | |D ]}| j|| dd||< qX|S r   r   r   r   r   r   r     s    
zRandHistogramShiftd.__call__)r;  r   F)NN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   rO   p  s         c                      sZ   e Zd ZdZejZdddddd	d
ddZdddd d fddZdddddZ  Z	S )rL   a  
    Dictionary-based version of RandGibbsNoise.

    Naturalistic image augmentation via Gibbs artifacts. The transform
    randomly applies Gibbs noise to 2D/3D MRI images. Gibbs artifacts
    are one of the common type of type artifacts appearing in MRI scans.

    The transform is applied to all the channels in the data.

    For general information on Gibbs artifacts, please refer to:
    https://pubs.rsna.org/doi/full/10.1148/rg.313105115
    https://pubs.rsna.org/doi/full/10.1148/radiographics.22.4.g02jl14949

    Args:
        keys: 'image', 'label', or ['image', 'label'] depending on which data
                you need to transform.
        prob (float): probability of applying the transform.
        alpha (float, Sequence[float]): Parametrizes the intensity of the Gibbs noise filter applied. Takes
            values in the interval [0,1] with alpha = 0 acting as the identity mapping.
            If a length-2 list is given as [a,b] then the value of alpha will be sampled
            uniformly from the interval [a,b].
            If a float is given, then the value of alpha will be sampled uniformly from the interval [0, alpha].
        allow_missing_keys: do not raise exception if key is missing.
    r   r   r   Fr   r   zfloat | Sequence[float]r   r   )r   r   r1  r   r   c                 C  s.   t | || tj| |d t|dd| _d S )Nr   r   )r1  r   )r-   r   r.   r   rand_gibbs_noise)r   r   r   r1  r   r   r   r   r     s    zRandGibbsNoised.__init__Nr   r   r   c                   s    t  || | j|| | S r   )r   r   r?  r   r   r   r   r     s    z RandGibbsNoised.set_random_stater   r   c                 C  sx   t |}| d  | jsB| |D ]}t|| t d||< q"|S | jd  | |D ]}| j|| dd||< qX|S r   )r   r   r   r   r0   r
   r?  r   r   r   r   r     s    
zRandGibbsNoised.__call__)r   r=  F)NN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   rL     s      c                   @  s<   e Zd ZdZejZddddddd	d
ZdddddZdS )rK   a  
    Dictionary-based version of GibbsNoise.

    The transform applies Gibbs noise to 2D/3D MRI images. Gibbs artifacts
    are one of the common type of type artifacts appearing in MRI scans.

    For general information on Gibbs artifacts, please refer to:
    https://pubs.rsna.org/doi/full/10.1148/rg.313105115
    https://pubs.rsna.org/doi/full/10.1148/radiographics.22.4.g02jl14949

    Args:
        keys: 'image', 'label', or ['image', 'label'] depending on which data
                you need to transform.
        alpha (float): Parametrizes the intensity of the Gibbs noise filter applied. Takes
            values in the interval [0,1] with alpha = 0 acting as the identity mapping.
        allow_missing_keys: do not raise exception if key is missing.
    r  Fr   r   r   r   )r   r1  r   r   c                 C  s   t | || t|| _d S r   )r-   r   r   	transform)r   r   r1  r   r   r   r   r     s    zGibbsNoised.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S r   r   r   r@  r   r   r   r   r     s    zGibbsNoised.__call__N)r  F)r   r   r   r   r   r   r   r   r   r   r   r   rK     s   c                      sF   e Zd ZdZejZddddddd	 fd
dZdddddZ  ZS )rM   a  
    Dictionary-based wrapper of :py:class:`monai.transforms.KSpaceSpikeNoise`.

    Applies localized spikes in `k`-space at the given locations and intensities.
    Spike (Herringbone) artifact is a type of data acquisition artifact which
    may occur during MRI scans.

    For general information on spike artifacts, please refer to:

    `AAPM/RSNA physics tutorial for residents: fundamental physics of MR imaging
    <https://pubmed.ncbi.nlm.nih.gov/16009826>`_.

    `Body MRI artifacts in clinical practice: A physicist's and radiologist's
    perspective <https://doi.org/10.1002/jmri.24288>`_.

    Args:
        keys: "image", "label", or ["image", "label"] depending
             on which data you need to transform.
        loc: spatial location for the spikes. For
            images with 3D spatial dimensions, the user can provide (C, X, Y, Z)
            to fix which channel C is affected, or (X, Y, Z) to place the same
            spike in all channels. For 2D cases, the user can provide (C, X, Y)
            or (X, Y).
        k_intensity: value for the log-intensity of the
            `k`-space version of the image. If one location is passed to ``loc`` or the
            channel is not specified, then this argument should receive a float. If
            ``loc`` is given a sequence of locations, then this argument should
            receive a sequence of intensities. This value should be tested as it is
            data-dependent. The default values are the 2.5 the mean of the
            log-intensity for each channel.
        allow_missing_keys: do not raise exception if key is missing.

    Example:
        When working with 4D data,
        ``KSpaceSpikeNoised("image", loc = ((3,60,64,32), (64,60,32)), k_intensity = (13,14))``
        will place a spike at `[3, 60, 64, 32]` with `log-intensity = 13`, and
        one spike per channel located respectively at `[: , 64, 60, 32]`
        with `log-intensity = 14`.
    NFr   ztuple | Sequence[tuple]zSequence[float] | float | Noner   r   )r   lock_intensityr   r   c                   s   t  || t||| _d S r   )r   r   r   r@  )r   r   rB  rC  r   r   r   r   r   (  s    zKSpaceSpikeNoised.__init__r   r   r   c                 C  s.   t |}| |D ]}| || ||< q|S )z
        Args:
            data: Expects image/label to have dimensions (C, H, W) or
                (C, H, W, D), where C is the channel.
        rA  r   r   r   r   r   2  s    zKSpaceSpikeNoised.__call__)NF)	r   r   r   r   r   r   r   r   r   r   r   r   r   rM     s   (  
c                      sZ   e Zd ZdZejZddddd	d	d
ddZdddd d fddZdddddZ  Z	S )rN   a  
    Dictionary-based version of :py:class:`monai.transforms.RandKSpaceSpikeNoise`.

    Naturalistic data augmentation via spike artifacts. The transform applies
    localized spikes in `k`-space.

    For general information on spike artifacts, please refer to:

    `AAPM/RSNA physics tutorial for residents: fundamental physics of MR imaging
    <https://pubmed.ncbi.nlm.nih.gov/16009826>`_.

    `Body MRI artifacts in clinical practice: A physicist's and radiologist's
    perspective <https://doi.org/10.1002/jmri.24288>`_.

    Args:
        keys: "image", "label", or ["image", "label"] depending
             on which data you need to transform.
        prob: probability to add spike artifact to each item in the
            dictionary provided it is realized that the noise will be applied
            to the dictionary.
        intensity_range: pass a tuple (a, b) to sample the log-intensity from the interval (a, b)
            uniformly for all channels. Or pass sequence of intervals
            ((a0, b0), (a1, b1), ...) to sample for each respective channel.
            In the second case, the number of 2-tuples must match the number of channels.
            Default ranges is `(0.95x, 1.10x)` where `x` is the mean
            log-intensity for each channel.
        channel_wise: treat each channel independently. True by default.
        allow_missing_keys: do not raise exception if key is missing.

    Example:
        To apply `k`-space spikes randomly on the image only, with probability
        0.5, and log-intensity sampled from the interval [13, 15] for each
        channel independently, one uses
        ``RandKSpaceSpikeNoised("image", prob=0.5, intensity_ranges=(13, 15), channel_wise=True)``.
    r   NTFr   r   z(Sequence[Sequence[float] | float] | Noner   )r   r   intensity_ranger   r   c                 C  s0   t | || tj| |d td||d| _d S )Nr>  r   )r   rD  r   )r-   r   r.   r    
rand_noise)r   r   r   rD  r   r   r   r   r   r   e  s    zRandKSpaceSpikeNoised.__init__r   r   r   c                   s    t  || | j|| | S r   )r   r   rE  r   r   r   r   r   q  s    z&RandKSpaceSpikeNoised.set_random_stater   r   c                 C  sl   t |}| d  | jsB| |D ]}t|| t d||< q"|S | |D ]}| j|| dd||< qL|S r   )r   r   r   r   r0   r
   rE  r   r   r   r   r   x  s    
zRandKSpaceSpikeNoised.__call__)r   NTF)NN)
r   r   r   r   r    r   r   r   r   r   r   r   r   r   rN   >  s   $       c                      sb   e Zd ZdZejZddddd	d
dddd	d	ddZdddd d fddZdddddZ  Z	S )rP   a(	  
    Dictionary-based wrapper of :py:class:`monai.transforms.RandCoarseDropout`.
    Expect all the data specified by `keys` have same spatial shape and will randomly dropout the same regions
    for every key, if want to dropout differently for every key, please use this transform separately.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        holes: number of regions to dropout, if `max_holes` is not None, use this arg as the minimum number to
            randomly select the expected number of regions.
        spatial_size: spatial size of the regions to dropout, if `max_spatial_size` is not None, use this arg
            as the minimum spatial size to randomly select size for every region.
            if some components of the `spatial_size` are non-positive values, the transform will use the
            corresponding components of input img size. For example, `spatial_size=(32, -1)` will be adapted
            to `(32, 64)` if the second spatial dimension size of img is `64`.
        dropout_holes: if `True`, dropout the regions of holes and fill value, if `False`, keep the holes and
            dropout the outside and fill value. default to `True`.
        fill_value: target value to fill the dropout regions, if providing a number, will use it as constant
            value to fill all the regions. if providing a tuple for the `min` and `max`, will randomly select
            value for every pixel / voxel from the range `[min, max)`. if None, will compute the `min` and `max`
            value of input image then randomly select value to fill, default to None.
        max_holes: if not None, define the maximum number to randomly select the expected number of regions.
        max_spatial_size: if not None, define the maximum spatial size to randomly select size for every region.
            if some components of the `max_spatial_size` are non-positive values, the transform will use the
            corresponding components of input img size. For example, `max_spatial_size=(32, -1)` will be adapted
            to `(32, 64)` if the second spatial dimension size of img is `64`.
        prob: probability of applying the transform.
        allow_missing_keys: don't raise exception if key is missing.

    TNr   Fr   r   r"  r   z"tuple[float, float] | float | Noner   Sequence[int] | int | Noner   )	r   holesspatial_sizedropout_holes
fill_value	max_holesmax_spatial_sizer   r   c
           
   	   C  s8   t | ||	 tj| |d t||||||dd| _d S )Nr>  r   )rG  rH  rI  rJ  rK  rL  r   )r-   r   r.   r   dropper)
r   r   rG  rH  rI  rJ  rK  rL  r   r   r   r   r   r     s    zRandCoarseDropoutd.__init__r   r   c                   s    t  || | j|| | S r   )r   r   rM  r   r   r   r   r     s    z#RandCoarseDropoutd.set_random_stater   r   r   c                 C  s   t |}| d  | jsB| |D ]}t|| t d||< q"|S | |}|dkr~| |D ]}t|| t d||< q^|S | j|| jdd   | |D ]}| j|| dd||< q|S Nr   r   r   Fr   )	r   r   r   r   r0   r
   r   rM  r  r   r   r   r   r     s    

zRandCoarseDropoutd.__call__)TNNNr   F)NN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   rP     s             c                	      s^   e Zd ZdZejZdddddd	d
ddddZdddd d fddZdddddZ  Z	S )rQ   a  
    Dictionary-based wrapper of :py:class:`monai.transforms.RandCoarseShuffle`.
    Expect all the data specified by `keys` have same spatial shape and will randomly dropout the same regions
    for every key, if want to shuffle different regions for every key, please use this transform separately.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        holes: number of regions to dropout, if `max_holes` is not None, use this arg as the minimum number to
            randomly select the expected number of regions.
        spatial_size: spatial size of the regions to dropout, if `max_spatial_size` is not None, use this arg
            as the minimum spatial size to randomly select size for every region.
            if some components of the `spatial_size` are non-positive values, the transform will use the
            corresponding components of input img size. For example, `spatial_size=(32, -1)` will be adapted
            to `(32, 64)` if the second spatial dimension size of img is `64`.
        max_holes: if not None, define the maximum number to randomly select the expected number of regions.
        max_spatial_size: if not None, define the maximum spatial size to randomly select size for every region.
            if some components of the `max_spatial_size` are non-positive values, the transform will use the
            corresponding components of input img size. For example, `max_spatial_size=(32, -1)` will be adapted
            to `(32, 64)` if the second spatial dimension size of img is `64`.
        prob: probability of applying the transform.
        allow_missing_keys: don't raise exception if key is missing.

    Nr   Fr   r   r"  r   rF  r   r   )r   rG  rH  rK  rL  r   r   c                 C  s4   t | || tj| |d t||||dd| _d S )Nr>  r   )rG  rH  rK  rL  r   )r-   r   r.   r   shuffle)r   r   rG  rH  rK  rL  r   r   r   r   r   r     s    
    zRandCoarseShuffled.__init__r   r   c                   s    t  || | j|| | S r   )r   r   rO  r   r   r   r   r     s    z#RandCoarseShuffled.set_random_stater   r   r   c                 C  s   t |}| d  | jsB| |D ]}t|| t d||< q"|S | |}|dkr~| |D ]}t|| t d||< q^|S | j|| jdd   | |D ]}| j|| dd||< q|S rN  )	r   r   r   r   r0   r
   r   rO  r  r   r   r   r   r     s    

zRandCoarseShuffled.__call__)NNr   F)NN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   rQ     s          c                      s^   e Zd ZdZejZdddddejdfddddd	d
dddd	 fddZdddddZ	  Z
S )rR   a  
    Dictionary-based wrapper of :py:class:`monai.transforms.HistogramNormalize`.

    Args:
        keys: keys of the corresponding items to be transformed.
            See also: :py:class:`monai.transforms.compose.MapTransform`
        num_bins: number of the bins to use in histogram, default to `256`. for more details:
            https://numpy.org/doc/stable/reference/generated/numpy.histogram.html.
        min: the min value to normalize input image, default to `255`.
        max: the max value to normalize input image, default to `255`.
        mask: if provided, must be ndarray of bools or 0s and 1s, and same shape as `image`.
            only points at which `mask==True` are used for the equalization.
            can also provide the mask by `mask_key` at runtime.
        mask_key: if mask is None, will try to get the mask with `mask_key`.
        dtype: output data type, if None, same as input image. defaults to float32.
        allow_missing_keys: do not raise exception if key is missing.

       r      NFr   r   r  r   r   r   r   )	r   num_binsminmaxmaskr  r   r   r   c	           	        s8   t  || t|||||d| _|d kr.|nd | _d S )N)rR  rS  rT  rU  r   )r   r   r   r@  r  )	r   r   rR  rS  rT  rU  r  r   r   r   r   r   r   ;  s    zHistogramNormalized.__init__r   r   r   c                 C  sN   t |}| |D ]6}| jd k	r6| || || j n| || ||< q|S r   )r   r   r  r@  r   r   r   r   r   J  s    4zHistogramNormalized.__call__)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rR   %  s   $c                	      sD   e Zd ZdZdddddd	dd
d fddZdddddZ  ZS )rS   a3  
    Creates a binary mask that defines the foreground based on thresholds in RGB or HSV color space.
    This transform receives an RGB (or grayscale) image where by default it is assumed that the foreground has
    low values (dark) while the background is white.

    Args:
        keys: keys of the corresponding items to be transformed.
        threshold: an int or a float number that defines the threshold that values less than that are foreground.
            It also can be a callable that receives each dimension of the image and calculate the threshold,
            or a string that defines such callable from `skimage.filter.threshold_...`. For the list of available
            threshold functions, please refer to https://scikit-image.org/docs/stable/api/skimage.filters.html
            Moreover, a dictionary can be passed that defines such thresholds for each channel, like
            {"R": 100, "G": "otsu", "B": skimage.filter.threshold_mean}
        hsv_threshold: similar to threshold but HSV color space ("H", "S", and "V").
            Unlike RBG, in HSV, value greater than `hsv_threshold` are considered foreground.
        invert: invert the intensity range of the input image, so that the dtype maximum is now the dtype minimum,
            and vice-versa.
        new_key_prefix: this prefix be prepended to the key to create a new key for the output and keep the value of
            key intact. By default not prefix is set and the corresponding array to the key will be replaced.
        allow_missing_keys: do not raise exception if key is missing.

    otsuNFr   zdict | Callable | str | floatz*dict | Callable | str | float | int | Noner   r   r   )r   r  hsv_thresholdinvertnew_key_prefixr   r   c                   s(   t  || t|||d| _|| _d S )N)r  rW  rX  )r   r   r   r@  rY  )r   r   r  rW  rX  rY  r   r   r   r   r   j  s    	zForegroundMaskd.__init__r   r   r   c                 C  sF   t |}| |D ].}| jd kr$|n| j| }| || ||< q|S r   r   r   rY  r@  r   r   r   r   new_keyr   r   r   r   w  s
    zForegroundMaskd.__call__)rV  NFNFr   r   r   r   r   r   r   r   r   r   r   rS   R  s         c                      s@   e Zd ZdZdddddd	d
 fddZdddddZ  ZS )rT   a\  Compute horizontal and vertical maps from an instance mask
    It generates normalized horizontal and vertical distances to the center of mass of each region.

    Args:
        keys: keys of the corresponding items to be transformed.
        dtype: the type of output Tensor. Defaults to `"float32"`.
        new_key_prefix: this prefix be prepended to the key to create a new key for the output and keep the value of
            key intact. Defaults to '"_hover", so if the input key is "mask" the output will be "hover_mask".
        allow_missing_keys: do not raise exception if key is missing.

    r   hover_Fr   r   r   r   r   )r   r   rY  r   r   c                   s$   t  || t|d| _|| _d S )N)r   )r   r   r   r@  rY  )r   r   r   rY  r   r   r   r   r     s    zComputeHoVerMapsd.__init__r   r   r   c                 C  sF   t |}| |D ].}| jd kr$|n| j| }| || ||< q|S r   rZ  r[  r   r   r   r     s
    zComputeHoVerMapsd.__call__)r   r^  Fr]  r   r   r   r   rT     s      )r   
__future__r   typingr   r   r   r   numpyr   monai.configr   r   monai.config.type_definitionsr	   monai.data.meta_objr
   Z monai.transforms.intensity.arrayr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   monai.transforms.transformr-   r.   monai.transforms.utilsr/   monai.utilsr0   r1   r2   monai.utils.enumsr3   __all__metar   r4   r5   r6   r7   r:   r;   r8   r9   ra   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rO   rL   rK   rM   rN   rP   rQ   rR   rS   rT   rU   rV   r   r   rW   rX   rY   rZ   r]   r^   rd   re   rf   rg   r[   r\   r_   r`   rc   rb   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sn  $i>D<Z%9+?A<(!'-A,*%#9)L2; AGWI-.!