U PhCLf@sNdZddlmZddlmZmZmZmZddlZ ddl m Z m Z ddl mZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZm 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/m0Z0m1Z1m2Z2m3Z3dd l4m5Z5m6Z6dd l7m8Z8dd l9m:Z:m;Z;mZ>d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrgfZ?e>@ZAGdsd d e6e5ZBGdtdde6e5ZCGdudde5ZDGdvdde6e5ZEGdwdde5ZFGdxdde6e5ZGGdydde5ZHGdzdde6e5ZIGd{d:d:e6e5ZJGd|dde6e5ZKGd}dde5ZLGd~dde5ZMGddde5ZNGddde5ZOGddde5ZPGddde6e5ZQGddde5ZRGddde5ZSGddde5ZTGddde5ZUGdd d e5ZVGdd!d!e6e5ZWGdd"d"e5ZXGdd#d#e6e5ZYGdd(d(e6e5ZZGdd%d%e6e5Z[Gdd$d$e5Z\Gdd&d&e5Z]Gdd'd'e6e5Z^Gdd)d)e6e5Z_Gdd*d*e6e5Z`Gdd+d+e5ZaGdd,d,e5ZbGdd-d-e5ZceBZdZeeCZfZgeDZhZieEZjZkeFZlZmeGZnZoeKZpZqeHZrZseIZtZueJZvZweLZxZyeMZzZ{eNZ|Z}eOZ~ZePZZeQZZeRZZeSZZeTZZeUZZeVZZeWZZeXZZeYZZeZZZe[ZZe\ZZe]ZZe^ZZe_ZZeaZZe`ZZebZZecZZdS)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)CallableHashableMappingSequenceN) DtypeLikeKeysCollection)NdarrayOrTensor)get_track_meta)"AdjustContrastClipIntensityPercentilesComputeHoVerMapsForegroundMaskGaussianSharpenGaussianSmooth GibbsNoiseHistogramNormalizeKSpaceSpikeNoise MaskIntensity MedianSmoothNormalizeIntensityRandAdjustContrast RandBiasFieldRandCoarseDropoutRandCoarseShuffleRandGaussianNoiseRandGaussianSharpenRandGaussianSmoothRandGibbsNoiseRandHistogramShiftRandKSpaceSpikeNoiseRandRicianNoiseRandScaleIntensityRandScaleIntensityFixedMeanRandShiftIntensityRandStdShiftIntensitySavitzkyGolaySmoothScaleIntensityScaleIntensityRangeScaleIntensityRangePercentilesShiftIntensityStdShiftIntensityThresholdIntensity) MapTransformRandomizableTransform) is_positive)convert_to_tensor ensure_tupleensure_tuple_rep)PostFixRandGaussianNoisedRandRicianNoisedShiftIntensitydRandShiftIntensitydScaleIntensitydRandScaleIntensitydStdShiftIntensitydRandStdShiftIntensitydRandBiasFielddNormalizeIntensitydThresholdIntensitydScaleIntensityRangedClipIntensityPercentilesdAdjustContrastdRandAdjustContrastdScaleIntensityRangePercentilesdMaskIntensitydSavitzkyGolaySmoothd MedianSmoothdGaussianSmoothdRandGaussianSmoothdGaussianSharpendRandGaussianSharpend GibbsNoisedRandGibbsNoisedKSpaceSpikeNoisedRandKSpaceSpikeNoisedRandHistogramShiftdRandCoarseDropoutdRandCoarseShuffledHistogramNormalizedForegroundMaskdComputeHoVerMapsdRandGaussianNoiseDRandGaussianNoiseDictShiftIntensityDShiftIntensityDictRandShiftIntensityDRandShiftIntensityDictScaleIntensityDScaleIntensityDictStdShiftIntensityDStdShiftIntensityDictRandScaleIntensityDRandScaleIntensityDictRandScaleIntensityFixedMeandRandScaleIntensityFixedMeanDictRandScaleIntensityFixedMeanDRandStdShiftIntensityDRandStdShiftIntensityDictRandBiasFieldDRandBiasFieldDictNormalizeIntensityDNormalizeIntensityDictThresholdIntensityDThresholdIntensityDictScaleIntensityRangeDScaleIntensityRangeDictClipIntensityPercentilesDClipIntensityPercentilesDictAdjustContrastDAdjustContrastDictRandAdjustContrastDRandAdjustContrastDictScaleIntensityRangePercentilesD"ScaleIntensityRangePercentilesDictMaskIntensityDMaskIntensityDictSavitzkyGolaySmoothDSavitzkyGolaySmoothDict MedianSmoothDMedianSmoothDictGaussianSmoothDGaussianSmoothDictRandGaussianSmoothDRandGaussianSmoothDictGaussianSharpenDGaussianSharpenDictRandGaussianSharpenDRandGaussianSharpenDict GibbsNoiseDGibbsNoiseDictRandGibbsNoiseDRandGibbsNoiseDictKSpaceSpikeNoiseDKSpaceSpikeNoiseDictRandHistogramShiftDRandHistogramShiftDictRandRicianNoiseDRandRicianNoiseDictRandCoarseDropoutDRandCoarseDropoutDictRandCoarseShuffleDRandCoarseShuffleDictHistogramNormalizeDHistogramNormalizeDictRandKSpaceSpikeNoiseDRandKSpaceSpikeNoiseDictForegroundMaskDForegroundMaskDictComputeHoVerMapsDComputeHoVerMapsDictc sneZdZdZejZdddejddfdddddd d d d d d Zdddddfdd Z dddddZ Z S)r4uF 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. 皙?FTrfloatrboolNone)keysprobmeanstddtypeallow_missing_keys sample_stdreturncCs2t|||t||t||d||d|_dS)N?)rrrrr)r-__init__r.rrand_gaussian_noise)selfrrrrrrrrZ/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/transforms/intensity/dictionary.pyrs  zRandGaussianNoised.__init__N int | Nonenp.random.RandomState | Noneseedstatercs t|||j|||SN)superset_random_staterrrr __class__rrrsz#RandGaussianNoised.set_random_state"Mapping[Hashable, NdarrayOrTensor]dict[Hashable, NdarrayOrTensor]datarcCst|}|d|jsB||D]}t||td||<q"|S||}|dkr~||D]}t||td||<q^|S|j||||D]}|j||dd||<q|S)N track_metarFimg randomize)dictr _do_transform key_iteratorr0r first_keyrrrdkeyrrrr__call__s  zRandGaussianNoised.__call__)NN) __name__ __module__ __qualname____doc__rbackendnpfloat32rrr __classcell__rrrrr4sc sveZdZdZejZddddddejdfddd d d d d d d d d ddZdddddfdd Z dddddZ Z S)r5a 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. rrrFTrrSequence[float] | floatrrr) rrrr channel_wiserelativerrrrc Cs6t||| t||td||||||d|_dS)Nr)rrrrrrr)r-rr.r!rand_rician_noise) rrrrrrrrrrrrrrs  zRandRicianNoised.__init__Nrrrcs t|||j|||Sr)rrrrrrrr sz!RandRicianNoised.set_random_staterrrcCslt|}|d|jsB||D]}t||td||<q"|S||D]}|j||dd||<qL|SNrTr)rrrrr0r rrrrrrrrr%s zRandRicianNoised.__call__)NN) rrrrr!rrrrrrrrrrrr5s"c sTeZdZdZejZdddedfdddddd dd d fd d ZddddZZ S)r6zR Dictionary-based wrapper of :py:class:`monai.transforms.ShiftIntensity`. FNrrr str | NoneKeysCollection | Nonestrr)roffsetsafe factor_key meta_keysmeta_key_postfixrrcst||t|t|j|_|dkr8tdt|jnt||_t|jt|jkr^tdt|t|j|_ t |||_ dS)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.) rrr2lenrrr1r ValueErrorrr*shifter)rrrrrrrrrrrr9s!"zShiftIntensityd.__init__rrc Cst|}|||j|j|jD]f\}}}}|p:|d|}||krR|||nd}|dkrbdn |jj|}|j|||d||<q|S)N_)r)rrrrrgetrr) rrrrrmeta_keyrfactorrrrrrbszShiftIntensityd.__call__) rrrrr*rDEFAULT_POST_FIXrrrrrrrr62s")c speZdZdZejZdddedddfddddd d d ddd d ddZdddddfdd ZddddZ Z S)r7zS Dictionary-based version :py:class:`monai.transforms.RandShiftIntensity`. FNrrtuple[float, float] | floatrrrrrr) roffsetsrrrrrrrrc Cst||| t||t|t|j|_|dkrDtdt|jnt||_t|jt|jkrjt dt|t|j|_ t ||d|d|_ dS)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. Nrr)rrrr) r-rr.r2rrrr1rrrr$r) rrrrrrrrrrrrrrus( "zRandShiftIntensityd.__init__rrrcs t|||j|||Srrrrrrrrrsz$RandShiftIntensityd.set_random_staterrc Cst|}|d|jsB||D]}t||td||<q"|S||}|dkr~||D]}t||td||<q^|S|j|||||j|j |j D]P\}}}}|p|d|}||kr|| |nd}|j|||dd||<q|S)NrrrF)rr) rrrrr0r rrrrrr) rrrrrrrrrrrrrs,  zRandShiftIntensityd.__call__)NN) rrrrr$rrrrrrrrrrr7ns"3c sTeZdZdZejZddejdfddddddddfd d Zd d d ddZ Z S)r:zU Dictionary-based wrapper of :py:class:`monai.transforms.StdShiftIntensity`. Frrrrr)rrnonzerorrrrcs"t||t|||||_dS)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)rrr+r)rrrrrrrrrrrszStdShiftIntensityd.__init__rrrcCs.t|}||D]}|||||<q|Sr)rrrrrrrrszStdShiftIntensityd.__call__) rrrrr+rrrrrrrrrrr:s c sleZdZdZejZdddejdfdddddddd d d d Zdddddfdd Z dddddZ Z S)r;zV Dictionary-based version :py:class:`monai.transforms.RandStdShiftIntensity`. rFrrrrrr)rfactorsrrrrrrcCs2t|||t||t||||dd|_dS)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)rrrrrN)r-rr.r%r)rrrrrrrrrrrrs zRandStdShiftIntensityd.__init__Nrrrcs t|||j|||Srrrrrrrsz'RandStdShiftIntensityd.set_random_staterrrcCsxt|}|d|jsB||D]}t||td||<q"|S|jd||D]}|j||dd||<qX|SNrFrrrrrr0r rrrrrrs  zRandStdShiftIntensityd.__call__)NN) rrrrr%rrrrrrrrrrrr;sc sZeZdZdZejZddddejdfdddddd dd d fd d ZdddddZ Z S)r8a 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)``. rrNFr float | Nonerrr)rminvmaxvrrrrrcs$t||t||||||_dS)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)rrr'scaler)rrrrrrrrrrrr/szScaleIntensityd.__init__rrrcCs.t|}||D]}|||||<q|SrrrrrrrrrJszScaleIntensityd.__call__) rrrrr'rrrrrrrrrrr8&s"c sheZdZdZejZddejdfddddddd d d d Zdddddfdd Z dddddZ Z S)r9zS Dictionary-based version :py:class:`monai.transforms.RandScaleIntensity`. rFrrrrrr)rrrrrrrcCs0t|||t||t||d|d|_dS)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)rrrrN)r-rr.r"r)rrrrrrrrrrrXs zRandScaleIntensityd.__init__Nrrrcs t|||j|||Srrrrrrrrrssz$RandScaleIntensityd.set_random_staterrrcCst|}|d|jsB||D]}t||td||<q"|S||}|dkr~||D]}t||td||<q^|S|j||||D]}|j||dd||<q|S)NrrFr)rrrrr0r rrrrrrrzs  zRandScaleIntensityd.__call__)NN) rrrrr"rrrrrrrrrrrr9Qsc sleZdZdZejZdddejdfdddddd dd d d d Zdddddfdd Z dddddZ Z S)raz 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. TFrrrrrrr)rr fixed_meanpreserve_rangerrrrcCs@t|||t||||_||_t||j||dd|_dS)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)rrrrrN)r-rr.rrr#r)rrrrrrrrrrrrs z%RandScaleIntensityFixedMeand.__init__Nrrrcs t|||j|||Srrrrrrrsz-RandScaleIntensityFixedMeand.set_random_staterrrcCsxt|}|d|jsB||D]}t||td||<q"|S|jd||D]}|j||dd||<qX|Sr)rrrrr0r rrrrrrs  z%RandScaleIntensityFixedMeand.__call__)NN) rrrrr#rrrrrrrrrrrras#c sjeZdZdZejZddejddfdddd d d d d ddZdddddfdd Z dddddZ Z S)r<zN Dictionary-based version :py:class:`monai.transforms.RandBiasField`. )rrrFrinttuple[float, float]rrrr)rdegree coeff_rangerrrrcCs0t|||t||t|||dd|_dS)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)rrrrN)r-rr.rrand_bias_field)rrrrrrrrrrrs zRandBiasFieldd.__init__Nrrrcs t|||j|||Sr)rrrrrrrrszRandBiasFieldd.set_random_staterrrcCst|}|d|jsB||D]}t||td||<q"|S||}|dkr~||D]}t||td||<q^|S|jj||jddd||D]}|j||dd||<q|S)Nrr)img_sizeFr) rrrrr0r rrshaperrrrrs  zRandBiasFieldd.__call__)NN) rrrrrrrrrrrrrrrrr<sc sZeZdZdZejZddddejdfddddddddd fd d Zd d dddZ 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. NFrNdarrayOrTensor | Nonerrr)r subtrahenddivisorrrrrrcs$t||t||||||_dSr)rrr normalizer)rrrrrrrrrrrr!s zNormalizeIntensityd.__init__rrrcCs.t|}||D]}|||||<q|Sr)rrrrrrrr.szNormalizeIntensityd.__call__) rrrrrrrrrrrrrrrr= s" csHeZdZdZejZdddddddd fd d Zd d dddZZS)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. TrFrrrr)r thresholdabovecvalrrcs t||t||||_dSr)rrr,filter)rrrrrrrrrrDszThresholdIntensityd.__init__rrrcCs.t|}||D]}|||||<q|Sr)rrr rrrrrOszThresholdIntensityd.__call__)TrF) rrrrr,rrrrrrrrr>5s  c sZeZdZdZejZdddejdfddddddddd d fd d Zd ddddZ 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. NFrrrrrr) ra_mina_maxb_minb_maxcliprrrc s&t||t|||||||_dSr)rrr(r) rrr r r r rrrrrrrhs zScaleIntensityRanged.__init__rrrcCs.t|}||D]}|||||<q|SrrrrrrrvszScaleIntensityRanged.__call__) rrrrr(rrrrrrrrrrr?Vs$c sPeZdZdZddejdfddddddddd fd d Zd d d ddZZS)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)) NFrrrrr)rloweruppersharpness_factorrrrrcs&t||t|||||d|_dS)N)rrrrr)rrr r)rrrrrrrrrrrrs z"ClipIntensityPercentilesd.__init__rrcCs.t|}||D]}|||||<q|Srrrrrrrsz"ClipIntensityPercentilesd.__call__) rrrrrrrrrrrrrr@}s "csHeZdZdZejZddddddddfdd Zd d d d dZZS)rAaV 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 `_, specifically `this `_ 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 `_, specifically `this `_ function. allow_missing_keys: don't raise exception if key is missing. Frrrr)rgamma invert_image retain_statsrrcs t||t||||_dSr)rrr adjuster)rrrrrrrrrrszAdjustContrastd.__init__rrrcCs.t|}||D]}|||||<q|Sr)rrrrrrrrszAdjustContrastd.__call__)FFF) rrrrr rrrrrrrrrAs c s^eZdZdZejZdddddddd d d d Zdddddfdd ZdddddZZ S)rBa 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 `_, specifically `this `_ 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 `_, specifically `this `_ function. allow_missing_keys: don't raise exception if key is missing. r?g@Frrrrr)rrrrrrrcCs6t|||t||t|d||d|_||_dS)Nr)rrrr)r-rr.rrr)rrrrrrrrrrrs  zRandAdjustContrastd.__init__Nrrrcs t|||j|||Sr)rrrrrrrrsz$RandAdjustContrastd.set_random_staterrrcCsxt|}|d|jsB||D]}t||td||<q"|S|jd||D]}|j||dd||<qX|Sr)rrrrr0r rrrrrrs  zRandAdjustContrastd.__call__)rrFFF)NN) rrrrrrrrrrrrrrrBsc s^eZdZdZejZdddejdfdddddddddddd fd d Zd d dddZ Z S)rCa  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. Frrrrrr) rrrr r rrrrrrc s*t|| t|||||||| |_dSr)rrr)r) rrrrr r rrrrrrrrrs z(ScaleIntensityRangePercentilesd.__init__rrrcCs.t|}||D]}|||||<q|Srrrrrrr.sz(ScaleIntensityRangePercentilesd.__call__) rrrrr)rrrrrrrrrrrC s (csPeZdZdZejZddedfdddddd d fd d Zd ddddZZ S)rDa 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. NFrrrrrr)r mask_datamask_key select_fnrrcs2t||t||d|_|dkr(|nd|_dS)N)rr)rrr converterr)rrrrrrrrrrLszMaskIntensityd.__init__rrrcCsNt|}||D]6}|jdk r6|||||jn |||||<q|Sr)rrrrrrrrrXs4zMaskIntensityd.__call__) rrrrrrr/rrrrrrrrD5s c sJeZdZdZejZdddddddd d fd d Zd ddddZZS)rEa$ 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. rzerosFrrrrr)r window_lengthorderaxismoderrcs$t||t||||d|_dS)N)rrrr )rrr&r)rrrrrr rrrrrqs zSavitzkyGolaySmoothd.__init__rrrcCs.t|}||D]}|||||<q|Srrrrrrrrr}szSavitzkyGolaySmoothd.__call__)rrF) rrrrr&rrrrrrrrrE_s csDeZdZdZejZddddddfdd Zd d d d dZZS)rFa 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. FrSequence[int] | intrr)rradiusrrcst||t||_dSr)rrrr)rrr#rrrrrszMedianSmoothd.__init__rrrcCs.t|}||D]}|||||<q|Srr!rrrrrszMedianSmoothd.__call__)F) rrrrrrrrrrrrrrFs csFeZdZdZejZddddddd fd d Zd d dddZZS)rGa 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. erfFrrrrr)rsigmaapproxrrcs t||t||d|_dSN)r&)rrrr)rrr%r&rrrrrszGaussianSmoothd.__init__rrrcCs.t|}||D]}|||||<q|Srr!rrrrrszGaussianSmoothd.__call__)r$F) rrrrrrrrrrrrrrGs  c s`eZdZdZejZddddddd d d d d dZdddddfdd ZdddddZZ S)rHa 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$rFrrrrrr)rsigma_xsigma_ysigma_zr&rrrcCs2t|||t||t||||dd|_dS)Nr)r)r*r+r&r)r-rr.r rand_smooth)rrr)r*r+r&rrrrrrs  zRandGaussianSmoothd.__init__Nrrrcs t|||j|||Sr)rrr,rrrrrsz$RandGaussianSmoothd.set_random_staterrrcCsxt|}|d|jsB||D]}t||td||<q"|S|jd||D]}|j||dd||<qX|Sr)rrrrr0r r,rrrrrs  zRandGaussianSmoothd.__call__)r(r(r(r$rF)NN) rrrrrrrrrrrrrrrHsc sJeZdZdZejZddddd d d d d fdd ZdddddZZS)rIaT 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$Frrrrrr)rsigma1sigma2alphar&rrcs$t||t||||d|_dSr')rrrr)rrr/r0r1r&rrrrrs zGaussianSharpend.__init__rrrcCs.t|}||D]}|||||<q|Srr!rrrrrszGaussianSharpend.__call__)r-rr.r$F) rrrrrrrrrrrrrrIs c sfeZdZdZejZddd d d d d d d d d d d ddZdddddfdd ZdddddZZ S)rJaP 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. rrrg$@r.r$rFrrrrrr) rsigma1_xsigma1_ysigma1_zsigma2_xsigma2_ysigma2_zr1r&rrc Cs:t||| t|| t|||||||| dd |_dS)Nr) r4r5r6r7r8r9r1r&r)r-rr.r rand_sharpen) rrr4r5r6r7r8r9r1r&rrrrrr>s zRandGaussianSharpend.__init__Nrrrcs t|||j|||Sr)rrr:rrrrrZsz%RandGaussianSharpend.set_random_staterrcCsxt|}|d|jsB||D]}t||td||<q"|S|jd||D]}|j||dd||<qX|Sr)rrrrr0r r:rrrrras  zRandGaussianSharpend.__call__) r2r2r2rrrr3r$rF)NN) rrrrrrrrrrrrrrrJ$s"$csZeZdZdZejZdddddd d d d Zdddddfdd ZdddddZZ S)rOa 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. rFrztuple[int, int] | intrrr)rnum_control_pointsrrrcCs,t|||t||t|dd|_dS)Nr)r<r)r-rr.rr)rrr<rrrrrrs zRandHistogramShiftd.__init__Nrrrcs t|||j|||Srrrrrrrsz$RandHistogramShiftd.set_random_staterrcCsxt|}|d|jsB||D]}t||td||<q"|S|jd||D]}|j||dd||<qX|Srrrrrrrs  zRandHistogramShiftd.__call__)r;rF)NN) rrrrrrrrrrrrrrrOps csZeZdZdZejZdddddd d d d Zdddddfdd ZdddddZZ S)rLa 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. rrrFrrzfloat | Sequence[float]rr)rrr1rrcCs.t|||tj||dt|dd|_dS)Nrr)r1r)r-rr.rrand_gibbs_noise)rrrr1rrrrrszRandGibbsNoised.__init__Nrrrcs t|||j|||Sr)rrr?rrrrrsz RandGibbsNoised.set_random_staterrcCsxt|}|d|jsB||D]}t||td||<q"|S|jd||D]}|j||dd||<qX|Sr)rrrrr0r r?rrrrrs  zRandGibbsNoised.__call__)rr=F)NN) rrrrrrrrrrrrrrrLs c@s<eZdZdZejZddddddd d Zd d d ddZdS)rKa 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. rFrrrr)rr1rrcCst|||t||_dSr)r-rr transform)rrr1rrrrrszGibbsNoised.__init__rrrcCs.t|}||D]}|||||<q|Srrrr@rrrrrszGibbsNoised.__call__N)rF)rrrrrrrrrrrrrKscsFeZdZdZejZddddddd fd d Zd d dddZZS)rMa 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 `_. `Body MRI artifacts in clinical practice: A physicist's and radiologist's perspective `_. 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`. NFrztuple | Sequence[tuple]zSequence[float] | float | Nonerr)rloc k_intensityrrcst||t|||_dSr)rrrr@)rrrBrCrrrrr(szKSpaceSpikeNoised.__init__rrrcCs.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. rArrrrr2szKSpaceSpikeNoised.__call__)NF) rrrrrrrrrrrrrrMs ( csZeZdZdZejZddddd d d d d Zdd dddfdd ZdddddZZ S)rNa 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 `_. `Body MRI artifacts in clinical practice: A physicist's and radiologist's perspective `_. 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)``. rNTFrrz(Sequence[Sequence[float] | float] | Noner)rrintensity_rangerrcCs0t|||tj||dtd||d|_dS)Nr>r)rrDr)r-rr.r rand_noise)rrrrDrrrrrreszRandKSpaceSpikeNoised.__init__rrrcs t|||j|||Sr)rrrErrrrrqsz&RandKSpaceSpikeNoised.set_random_staterrcCslt|}|d|jsB||D]}t||td||<q"|S||D]}|j||dd||<qL|Sr)rrrrr0r rErrrrrxs zRandKSpaceSpikeNoised.__call__)rNTF)NN) rrrrr rrrrrrrrrrN>s$ c sbeZdZdZejZddddd d d d d d d ddZdd dddfdd ZdddddZZ S)rPa( 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. TNrFrrr"rz"tuple[float, float] | float | NonerSequence[int] | int | Noner) rholes spatial_size dropout_holes fill_value max_holesmax_spatial_sizerrc Cs8t||| tj||dt||||||dd|_dS)Nr>r)rGrHrIrJrKrLr)r-rr.rdropper) rrrGrHrIrJrKrLrrrrrrs zRandCoarseDropoutd.__init__rrcs t|||j|||Sr)rrrMrrrrrsz#RandCoarseDropoutd.set_random_staterrrcCst|}|d|jsB||D]}t||td||<q"|S||}|dkr~||D]}t||td||<q^|S|j||jdd||D]}|j||dd||<q|SNrrrFr) rrrrr0r rrMrrrrrrs  zRandCoarseDropoutd.__call__)TNNNrF)NN) rrrrrrrrrrrrrrrPs c s^eZdZdZejZdddddd d d d d dZdddddfdd ZdddddZZ S)rQa 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. NrFrrr"rrFrr)rrGrHrKrLrrcCs4t|||tj||dt||||dd|_dS)Nr>r)rGrHrKrLr)r-rr.rshuffle)rrrGrHrKrLrrrrrrs zRandCoarseShuffled.__init__rrcs t|||j|||Sr)rrrOrrrrrsz#RandCoarseShuffled.set_random_staterrrcCst|}|d|jsB||D]}t||td||<q"|S||}|dkr~||D]}t||td||<q^|S|j||jdd||D]}|j||dd||<q|SrN) rrrrr0r rrOrrrrrrs  zRandCoarseShuffled.__call__)NNrF)NN) rrrrrrrrrrrrrrrQsc s^eZdZdZejZdddddejdfddddd d d d d d fdd ZdddddZ Z S)rRa 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. rNFrrrrrrr) rnum_binsminmaxmaskrrrrc s8t||t|||||d|_|dkr.|nd|_dS)N)rRrSrTrUr)rrrr@r) rrrRrSrTrUrrrrrrr;s zHistogramNormalized.__init__rrrcCsNt|}||D]6}|jdk r6|||||jn |||||<q|Sr)rrrr@rrrrrJs4zHistogramNormalized.__call__) rrrrrrrrrrrrrrrrR%s$c sDeZdZdZdddddd dd d fd d ZdddddZZS)rSa3 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. otsuNFrzdict | Callable | str | floatz*dict | Callable | str | float | int | Nonerrr)rr hsv_thresholdinvertnew_key_prefixrrcs(t||t|||d|_||_dS)N)rrWrX)rrrr@rY)rrrrWrXrYrrrrrjs zForegroundMaskd.__init__rrrcCsFt|}||D].}|jdkr$|n|j|}|||||<q|SrrrrYr@rrrrnew_keyrrrrws zForegroundMaskd.__call__)rVNFNFrrrrrrrrrrrrSRs cs@eZdZdZdddddd d fd d Zd ddddZZS)rTa\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. rhover_Frrrrr)rrrYrrcs$t||t|d|_||_dS)N)r)rrr r@rY)rrrrYrrrrrs zComputeHoVerMapsd.__init__rrrcCsFt|}||D].}|jdkr$|n|j|}|||||<q|SrrZr[rrrrs zComputeHoVerMapsd.__call__)rr^Fr]rrrrrTs  )r __future__rtypingrrrrnumpyr monai.configrrmonai.config.type_definitionsr monai.data.meta_objr Z monai.transforms.intensity.arrayr r r rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,monai.transforms.transformr-r.monai.transforms.utilsr/ monai.utilsr0r1r2monai.utils.enumsr3__all__metarr4r5r6r7r:r;r8r9rar<r=r>r?r@rArBrCrDrErFrGrHrIrJrOrLrKrMrNrPrQrRrSrTrUrVrrrWrXrYrZr]r^rdrerfrgr[r\r_r`rcrbrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxryrzr{r|r}r~rrrrrrrrrrrrrrrrrrrrrrrrrrrrr sn   $  i>D<Z%9+?A<(!'-A,*%#9)L2; AGWI-.!