o  i+@sddlmZddlmZmZmZddlmZddlZ ddl Z ddl m Z m Z ddlmZddlmZddlmZmZmZdd lmZmZdd lmZmZmZmZmZgd ZGd d d eeZ GdddeeZ!GdddeeZ"e"Z#Z$e!Z%Z&e Z'Z(dS)) annotations)HashableMappingSequence)AnyN)KeysCollection SequenceStr)NdarrayOrTensor)get_track_meta)RandSmoothDeformRandSmoothFieldAdjustContrastRandSmoothFieldAdjustIntensity) MapTransformRandomizableTransform)GridSampleModeGridSamplePadModeInterpolateModeconvert_to_tensorensure_tuple_rep) RandSmoothFieldAdjustContrastdRandSmoothFieldAdjustIntensitydRandSmoothDeformdRandSmoothFieldAdjustContrastDRandSmoothFieldAdjustIntensityDRandSmoothDeformD!RandSmoothFieldAdjustContrastDict"RandSmoothFieldAdjustIntensityDictRandSmoothDeformDictc`eZdZdZejZdejddddfd(ddZ d)d*fdd Z d+d,fd#d$ Z d-d&d'Z Z S).ra Dictionary version of RandSmoothFieldAdjustContrast. The field is randomized once per invocation by default so the same field is applied to every selected key. The `mode` parameter specifying interpolation mode for the field can be a single value or a sequence of values with one for each key in `keys`. Args: keys: key names to apply the augment to spatial_size: size of input arrays, all arrays stated in `keys` must have same dimensions rand_size: size of the randomized field to start from pad: number of pixels/voxels along the edges of the field to pad with 0 mode: interpolation mode to use when upsampling align_corners: if True align the corners when upsampling field prob: probability transform is applied gamma: (min, max) range for exponential field device: Pytorch device to define field on rN皙?)g?g@keysr spatial_size Sequence[int] rand_sizepadintmoder align_corners bool | NoneprobfloatgammaSequence[float] | floatdevicetorch.device | Nonec CNt||t||t|t|j|_t||||jd|d|| d|_dSNr?)r!r#r$r&r'r)r+r-) r__init__rrlenr r&r trans selfr r!r#r$r&r'r)r+r-r7j/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/transforms/smooth_field/dictionary.pyr2B  z'RandSmoothFieldAdjustContrastd.__init__seed int | Nonestatenp.random.RandomState | Nonereturnc t|||j|||SNsuperset_random_stater4r6r:r< __class__r7r8rC^z/RandSmoothFieldAdjustContrastd.set_random_statedata Any | NoneNonecs$td|jr|jdSdSr@)rB randomize _do_transformr4r6rHrEr7r8rKes z(RandSmoothFieldAdjustContrastd.randomize"Mapping[Hashable, NdarrayOrTensor]cC|t|}|js ||D] }t||td||<q|St||D]\}}|j|j |t |j |||d||<q'|SN) track_metaF rKdictrL key_iteratorrr enumerater4set_moder&r3r6rHdkeyidxr7r7r8__call__ksz'RandSmoothFieldAdjustContrastd.__call__r rr!r"r#r"r$r%r&rr'r(r)r*r+r,r-r.NN)r:r;r<r=r>rr@rHrIr>rJrHrNr>rN) __name__ __module__ __qualname____doc__r backendrAREAr2rCrKr[ __classcell__r7r7rEr8r,s rcr).ra Dictionary version of RandSmoothFieldAdjustIntensity. The field is randomized once per invocation by default so the same field is applied to every selected key. The `mode` parameter specifying interpolation mode for the field can be a single value or a sequence of values with one for each key in `keys`. Args: keys: key names to apply the augment to spatial_size: size of input arrays, all arrays stated in `keys` must have same dimensions rand_size: size of the randomized field to start from pad: number of pixels/voxels along the edges of the field to pad with 0 mode: interpolation mode to use when upsampling align_corners: if True align the corners when upsampling field prob: probability transform is applied gamma: (min, max) range of intensity multipliers device: Pytorch device to define field on rNr)rr1r rr!r"r#r$r%r&rr'r(r)r*r+r,r-r.c Cr/r0) rr2rrr3r r&r r4r5r7r7r8r2r9z(RandSmoothFieldAdjustIntensityd.__init__r:r;r<r=r>cr?r@rArDrEr7r8rCrGz0RandSmoothFieldAdjustIntensityd.set_random_staterHrIrJctd|jdSr@rBrKr4rMrEr7r8rK z)RandSmoothFieldAdjustIntensityd.randomizerNcCrOrPrRrWr7r7r8r[sz(RandSmoothFieldAdjustIntensityd.__call__r\r])r:r;r<r=r>rr@r^r_) r`rarbrcr rdrrer2rCrKr[rfr7r7rEr8rzs rc sneZdZdZejZdejdddej e j e j ddf d-ddZ d.d/fd#d$ Zd0d1fd(d) Zd2d+d,ZZS)3ra5 Dictionary version of RandSmoothDeform. The field is randomized once per invocation by default so the same field is applied to every selected key. The `field_mode` parameter specifying interpolation mode for the field can be a single value or a sequence of values with one for each key in `keys`. Similarly the `grid_mode` parameter can be one value or one per key. Args: keys: key names to apply the augment to spatial_size: input array size to which deformation grid is interpolated rand_size: size of the randomized field to start from pad: number of pixels/voxels along the edges of the field to pad with 0 field_mode: interpolation mode to use when upsampling the deformation field align_corners: if True align the corners when upsampling field prob: probability transform is applied def_range: value of the deformation range in image size fractions grid_dtype: type for the deformation grid calculated from the field grid_mode: interpolation mode used for sampling input using deformation grid grid_padding_mode: padding mode used for sampling input using deformation grid grid_align_corners: if True align the corners when sampling the deformation grid device: Pytorch device to define field on rNrr1Fr rr!r"r#r$r% field_moderr'r(r)r* def_ranger, grid_modegrid_padding_modestrgrid_align_cornersr-r.cCsnt||t||t|t|j|_t| t|j|_t||||jd|d|| |jd| | | d |_ dS)Nrr1) r#r!r$rjr'r)rk grid_dtyperlrmror-) rr2rrr3r rjrlr r4)r6r r!r#r$rjr'r)rkrprlrmror-r7r7r8r2s$   zRandSmoothDeformd.__init__r:r;r<r=r>cr?r@rArDrEr7r8rCrGz"RandSmoothDeformd.set_random_staterHrIrJcrgr@rhrMrEr7r8rK rizRandSmoothDeformd.randomizerNcCs|t|}|js ||D] }t||td||<q|St||D]-\}}|j|j |t |j |j |j |t |j |||d|jj ||<q'|SrP)rKrSrLrTrr rUr4set_field_moderjr3 set_grid_moderlr-rWr7r7r8r[szRandSmoothDeformd.__call__)r rr!r"r#r"r$r%rjrr'r(r)r*rkr,rlrrmrnror(r-r.r])r:r;r<r=r>rr@r^r_)r`rarbrcr rdrretorchfloat32rNEARESTrBORDERr2rCrKr[rfr7r7rEr8rs$ &r)) __future__rcollections.abcrrrtypingrnumpynprs monai.configrrmonai.config.type_definitionsr monai.data.meta_objr Z#monai.transforms.smooth_field.arrayr r r monai.transforms.transformrr monai.utilsrrrrr__all__rrrrrrrrrr7r7r7r8s$     NM\