U Ph+ @s ddlmZddlmZmZmZddlmZddlZ ddl Z ddl m Z m Z ddlmZddlmZddlmZmZmZdd lmZmZdd lmZmZmZmZmZd d d ddddddg ZGdd d eeZ Gdd d eeZ!Gdd d eeZ"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_repRandSmoothFieldAdjustContrastdRandSmoothFieldAdjustIntensitydRandSmoothDeformdRandSmoothFieldAdjustContrastDRandSmoothFieldAdjustIntensityDRandSmoothDeformD!RandSmoothFieldAdjustContrastDict"RandSmoothFieldAdjustIntensityDictRandSmoothDeformDictc seZdZdZejZdejddddfddddd d d d d d ddZdddddfdd Z ddddfdd Z dddddZ 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@r Sequence[int]intr bool | NonefloatSequence[float] | floattorch.device | None keys spatial_size rand_sizepadmode align_cornersprobgammadevicec CsNt||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.r6]/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/transforms/smooth_field/dictionary.pyr1Bs  z'RandSmoothFieldAdjustContrastd.__init__ int | Nonenp.random.RandomState | Noneseedstatereturncs t|||j|||SNsuperset_random_stater3r5r;r< __class__r6r7rA^sz/RandSmoothFieldAdjustContrastd.set_random_state Any | NoneNonedatar=cs td|jr|jdSr>)r@ randomize _do_transformr3r5rHrCr6r7rIes z(RandSmoothFieldAdjustContrastd.randomize"Mapping[Hashable, NdarrayOrTensor]cCs|t|}|js@||D]}t||td||<q |St||D]8\}}|j|j |t |j |||d||<qN|SN) track_metaF rIdictrJ key_iteratorrr enumerater3set_moder*r2r5rHdkeyidxr6r6r7__call__ksz'RandSmoothFieldAdjustContrastd.__call__)NN)N) __name__ __module__ __qualname____doc__r backendrAREAr1rArIrX __classcell__r6r6rCr7r,s c seZdZdZejZdejddddfddddd d d d d d ddZdddddfdd Z ddddfdd Z dddddZ Z S) 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)rr0rrr rr!r"r#r$r%c CsNt||t||t|t|j|_t||||jd|d|| d|_dSr/) rr1rrr2r&r*r r3r4r6r6r7r1s  z(RandSmoothFieldAdjustIntensityd.__init__r8r9r:cs t|||j|||Sr>r?rBrCr6r7rAsz0RandSmoothFieldAdjustIntensityd.set_random_staterErFrGcstd|jdSr>r@rIr3rKrCr6r7rIs z)RandSmoothFieldAdjustIntensityd.randomizerLcCs|t|}|js@||D]}t||td||<q |St||D]8\}}|j|j |t |j |||d||<qN|SrMrOrTr6r6r7rXsz(RandSmoothFieldAdjustIntensityd.__call__)NN)N) rYrZr[r\r r]rr^r1rArIrXr_r6r6rCr7rzs cseZdZdZejZdejdddej e j e j ddf dddd d d d d d dd dd ddZd ddddfdd Zd!dddfdd ZdddddZZS)"ra5 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 rNrr0Frrr rr!r"r#strr$) r&r'r(r) field_moder+r, def_range grid_modegrid_padding_modegrid_align_cornersr.cCsnt||t||t|t|j|_t| t|j|_t||||jd|d|| |jd| | | d |_ dS)Nrr0) r(r'r)rbr+r,rc grid_dtyperdrerfr.) rr1rrr2r&rbrdr r3)r5r&r'r(r)rbr+r,rcrgrdrerfr.r6r6r7r1s$  zRandSmoothDeformd.__init__r8r9r:cs t|||j|||Sr>r?rBrCr6r7rAsz"RandSmoothDeformd.set_random_staterErFrGcstd|jdSr>r`rKrCr6r7rI s zRandSmoothDeformd.randomizerLcCs|t|}|js@||D]}t||td||<q |St||D]Z\}}|j|j |t |j |j |j |t |j |||d|jj ||<qN|SrM)rIrPrJrQrr rRr3set_field_moderbr2 set_grid_moderdr.rTr6r6r7rXszRandSmoothDeformd.__call__)NN)N)rYrZr[r\r r]rr^torchfloat32rNEARESTrBORDERr1rArIrXr_r6r6rCr7rs$&&)) __future__rcollections.abcrrrtypingrnumpynprj monai.configrrmonai.config.type_definitionsr monai.data.meta_objr Z#monai.transforms.smooth_field.arrayr r r monai.transforms.transformrr monai.utilsrrrrr__all__rrrrrrrrrr6r6r6r7 s4     NM\