U Phn@sdZddlmZddlZddlmZmZmZddlm Z ddl m Z m Z m Z ddlZddlZddlmZmZddlmZdd lmZmZdd lmZdd lmZdd lmZmZdd l m!Z!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>m?Z?m@Z@mAZAddlBmCZCmDZDddlEmFZFddlGmHZHmIZIddlJmKZKmLZLmMZMddlNmOZOddddddddddddd 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`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddgnZPeKQZRGdd=d=e!ZSGddde!ZTGdd4d4e!ZUGdd]d]e!ZVGddZdZe!ZWGddfdfe!eZXGddde!ZYGddxdxe!eZZGdd7d7e!Z[Gddrdre!Z\Gddldle!Z]Gddudue!Z^Gdd|d|e!eZ_Gdd1d1e!Z`Gdd`d`e!ZaGddKdKe!ZbGddidie!ZcGdd.d.e!ZdGddcdce!ZeGdd(d(e!ZfGdd"d"e!ZgGddGdGe!eZhGddTdTehe#ZiGddDdDe!ZjGdd:d:e!eZkGddde!eZlGdd%d%e!ZmGddde"e!ZnGdd{d{e!ZoGddWdWe!eZpGddJdJe!ZqGdd>d>e!ZrGddmdme!ZsGdd)d)e!ZtGddNdNe!eZuGddde!ZvGddAdAe!ZwGddQdQe!e#ZxexZyZzewZ{Z|eSZ}Z~eTZZeUZZeWZZeVZZeXZZeYZZeZZZe[ZZe\ZZe]ZZe^ZZe_ZZe`ZZeaZZecZZedZZeeZZefZZegZZehZZejZZekZZelZZemZZenZZeoZZepZZeiZZeqZZerZZesZZetZZeuZZevZZebZZdS)z A collection of dictionary-based wrappers around the "vanilla" transforms for utility functions defined in :py:class:`monai.transforms.utility.array`. Class names are ended with 'd' to denote dictionary-based transforms. ) annotationsN)CallableHashableMapping)deepcopy)AnySequencecast) DtypeLikeKeysCollection)NdarrayOrTensor)MetaObj MetaTensor) no_collation)InvertibleTransform)MultiSampleTraitRandomizableTrait) MapTransform RandomizableRandomizableTransform)AddCoordinateChannelsAddExtremePointsChannel AsChannelLast CastToTypeClassesToIndices(ConvertToMultiChannelBasedOnBratsClassesCuCIM DataStatsEnsureChannelFirst EnsureType FgBgToIndicesIdentity ImageFilterIntensityStats LabelToMaskLambda MapLabelValueRemoveRepeatedChannel RepeatChannel SimulateDelaySplitDim SqueezeDimToCupyToDeviceToNumpyToPIL TorchVisionToTensor Transpose)extreme_points_to_imageget_extreme_points) concatenate) ensure_tupleensure_tuple_rep)PostFix TraceKeysTransformBackends)convert_to_dst_typeAddCoordinateChannelsDAddCoordinateChannelsDictAddCoordinateChannelsdAddExtremePointsChannelDAddExtremePointsChannelDictAddExtremePointsChanneldAsChannelLastDAsChannelLastDictAsChannelLastd CastToTypeDCastToTypeDict CastToTyped ConcatItemsDConcatItemsDict ConcatItemsd)ConvertToMultiChannelBasedOnBratsClassesD,ConvertToMultiChannelBasedOnBratsClassesDict)ConvertToMultiChannelBasedOnBratsClassesd CopyItemsD CopyItemsDict CopyItemsdCuCIMdCuCIMD CuCIMDict DataStatsD DataStatsDict DataStatsd DeleteItemsDDeleteItemsDict DeleteItemsdEnsureChannelFirstDEnsureChannelFirstDictEnsureChannelFirstd EnsureTypeDEnsureTypeDict EnsureTypedFgBgToIndicesDFgBgToIndicesDictFgBgToIndicesd IdentityD IdentityDict IdentitydIntensityStatsdIntensityStatsDIntensityStatsDict ImageFilterd LabelToMaskDLabelToMaskDict LabelToMaskdLambdaD LambdaDictLambdadMapLabelValueDMapLabelValueDictMapLabelValuedFlattenSubKeysdFlattenSubKeysDFlattenSubKeysDict RandCuCIMd RandCuCIMD RandCuCIMDictRandImageFilterd RandLambdaDRandLambdaDict RandLambdadRandTorchVisionDRandTorchVisionDictRandTorchVisiondRemoveRepeatedChannelDRemoveRepeatedChannelDictRemoveRepeatedChanneldRepeatChannelDRepeatChannelDictRepeatChanneld SelectItemsDSelectItemsDict SelectItemsdSimulateDelayDSimulateDelayDictSimulateDelayd SplitDimD SplitDimDict SplitDimd SqueezeDimDSqueezeDimDict SqueezeDimdToCupyD ToCupyDictToCupyd ToDeviced ToDeviceD ToDeviceDictToNumpyD ToNumpyDictToNumpydToPILD ToPILDictToPILd ToTensorD ToTensorDict ToTensord TorchVisionDTorchVisionDict TorchVisiond Transposed TransposeDict TransposeDClassesToIndicesdClassesToIndicesDClassesToIndicesDictcsBeZdZdZejZdddddfdd Zd d d d d ZZS)rezL Dictionary-based wrapper of :py:class:`monai.transforms.Identity`. Fr boolNonekeysallow_missing_keysreturncst||t|_dS)z Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` allow_missing_keys: don't raise exception if key is missing. N)super__init__r!identityselfrr __class__X/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/transforms/utility/dictionary.pyrszIdentityd.__init__"Mapping[Hashable, NdarrayOrTensor]dict[Hashable, NdarrayOrTensor]datarcCs.t|}||D]}|||||<q|SN)dict key_iteratorrrrdkeyrrr__call__szIdentityd.__call__)F) __name__ __module__ __qualname____doc__r!backendrr __classcell__rrrrres csDeZdZdZejZddddddfd d Zd d d ddZZS)rDzQ Dictionary-based wrapper of :py:class:`monai.transforms.AsChannelLast`. rFr intrr)r channel_dimrrcst||t|d|_dS)aY Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` channel_dim: which dimension of input image is the channel, default is the first dimension. allow_missing_keys: don't raise exception if key is missing. )rN)rrr converter)rrrrrrrrszAsChannelLastd.__init__rrrcCs.t|}||D]}|||||<q|SrrrrrrrrrszAsChannelLastd.__call__)rF) rrrrrrrrrrrrrrDs csDeZdZdZejZddddddfd d Zd d d ddZZS)r\zV Dictionary-based wrapper of :py:class:`monai.transforms.EnsureChannelFirst`. TFNr rr)r strict_checkrrcs t||t||d|_dS)a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` strict_check: whether to raise an error when the meta information is insufficient. allow_missing_keys: don't raise exception if key is missing. channel_dim: This argument can be used to specify the original channel dimension (integer) of the input array. It overrides the `original_channel_dim` from provided MetaTensor input. If the input array doesn't have a channel dim, this value should be ``'no_channel'``. If this is set to `None`, this class relies on `img` or `meta_dict` to provide the channel dimension. )rrN)rrradjuster)rrrrrrrrrszEnsureChannelFirstd.__init__Mapping[Hashable, torch.Tensor]dict[Hashable, torch.Tensor]rcCsLt|}||D]4}t||tr.||jnd}||||||<q|Sr)rr isinstancermetar)rrrr meta_dictrrrrs zEnsureChannelFirstd.__call__)TFN) rrrrrrrrrrrrrr\scsDeZdZdZejZddddddfdd Zd d d d dZZS)rzQ Dictionary-based wrapper of :py:class:`monai.transforms.RepeatChannel`. Fr rrrrrepeatsrrcst||t||_dSa2 Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` repeats: the number of repetitions for each element. allow_missing_keys: don't raise exception if key is missing. N)rrr(repeaterrrrrrrrrszRepeatChanneld.__init__rrrcCs.t|}||D]}|||||<q|Srrrrrrrrr szRepeatChanneld.__call__)F) rrrrr(rrrrrrrrrs csDeZdZdZejZddddddfdd Zd d d d dZZS)rzY Dictionary-based wrapper of :py:class:`monai.transforms.RemoveRepeatedChannel`. Fr rrrrcst||t||_dSr)rrr'rrrrrr.szRemoveRepeatedChanneld.__init__rrrcCs.t|}||D]}|||||<q|Srrrrrrr9szRemoveRepeatedChanneld.__call__)F) rrrrr'rrrrrrrrr's c sHeZdZejZddddddddd d fd d Zd ddddZZS)rNrTFr zSequence[str] | Nonerrr)routput_postfixesdimkeepdim update_meta list_outputrrcsHt||||_t||||_||_|jdkrD|jdk rDtddS)a' Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` output_postfixes: the postfixes to construct keys to store split data. for example: if the key of input data is `pred` and split 2 classes, the output data keys will be: pred_(output_postfixes[0]), pred_(output_postfixes[1]) if None, using the index number: `pred_0`, `pred_1`, ... `pred_N`. dim: which dimension of input image is the channel, default to 0. keepdim: if `True`, output will have singleton in the split dimension. If `False`, this dimension will be squeezed. update_meta: if `True`, copy `[key]_meta_dict` for each output and update affine to reflect the cropped image list_output: it `True`, the output will be a list of dictionaries with the same keys as original. allow_missing_keys: don't raise exception if key is missing. NzG`output_postfixes` should not be provided when `list_output` is `True`.)rrrr*splitterr ValueError)rrrrrrrrrrrrCs zSplitDimd.__init__rzAdict[Hashable, torch.Tensor] | list[dict[Hashable, torch.Tensor]]rcs>t|tt}jrg}fdd|D}t|D]H}tt||}tt|D]}t|||<qh| |q@|S|D]} |} j dkrtt t | nj } t | t | krtdt | dt | dt| D]<\} } |d| | } | kr.td| d| | <qqS)Ncsg|]}|qSr)r.0rrrrr lsz&SplitDimd.__call__..z-count of splits must match output_postfixes, z != ._z input data already contains key )rlistsetrrzipr differencerappendrrrangelenr enumerate RuntimeError)rrall_keysoutputresultsrownew_dictkrrets postfixesirZ split_keyrrrrds,     zSplitDimd.__call__)NrTTFF)rrrr*rrrrrrrrr@s"!c@sBeZdZdZejZejdfddddddd Zd d d d dZ dS)rGzN Dictionary-based wrapper of :py:class:`monai.transforms.CastToType`. Fr ;Sequence[DtypeLike | torch.dtype] | DtypeLike | torch.dtyperr)rdtyperrcCs,t|||t|t|j|_t|_dS)a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` dtype: convert image to this data type, default is `np.float32`. it also can be a sequence of dtypes or torch.dtype, each element corresponds to a key in ``keys``. allow_missing_keys: don't raise exception if key is missing. N)rrr7rrrrr)rrrrrrrrszCastToTyped.__init__rrrcCs:t|}|||jD]\}}|j|||d||<q|S)N)rrrrrrrrrrrrrrszCastToTyped.__call__N) rrrrrrnpfloat32rrrrrrrGs c sZeZdZdZejZdddddd dd d fd d ZdddddZdddddZZ S)rzL Dictionary-based wrapper of :py:class:`monai.transforms.ToTensor`. NTFr ztorch.dtype | Noneztorch.device | str | Noner bool | Noner)rrdevice wrap_sequence track_metarrcs$t||t||||d|_dS)a; Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` dtype: target data content type to convert, for example: torch.float, etc. device: specify the target device to put the Tensor data. wrap_sequence: if `False`, then lists will recursively call this function, default to `True`. E.g., if `False`, `[1, 2]` -> `[tensor(1), tensor(2)]`, if `True`, then `[1, 2]` -> `tensor([1, 2])`. track_meta: if `True` convert to ``MetaTensor``, otherwise to Pytorch ``Tensor``, if ``None`` behave according to return value of py:func:`monai.data.meta_obj.get_track_meta`. allow_missing_keys: don't raise exception if key is missing. )rrrrN)rrr1r)rrrrrrrrrrrszToTensord.__init__rrrcCs:t|}||D]"}|||||<|||q|Sr)rrrpush_transformrrrrrs zToTensord.__call__cCs>t|}||D]&}|||t}|||||<q|Sr)rr pop_transformr.)rrrrinverse_transformrrrinverses  zToTensord.inverse)NNTNF) rrrrr1rrrrrrrrrrs c sLeZdZdZejZddddd d d d d d fdd ZdddddZZS)r_a Dictionary-based wrapper of :py:class:`monai.transforms.EnsureType`. Ensure the input data to be a PyTorch Tensor or numpy array, support: `numpy array`, `PyTorch Tensor`, `float`, `int`, `bool`, `string` and `object` keep the original. If passing a dictionary, list or tuple, still return dictionary, list or tuple and recursively convert every item to the expected data type if `wrap_sequence=False`. Note: Currently, we only convert tensor data to numpy array or scalar number in the inverse operation. tensorNTFr strrztorch.device | Nonerrr)r data_typerrrrrrcs6t||t|t|j|_t||||d|_dS)a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` data_type: target data type to convert, should be "tensor" or "numpy". dtype: target data content type to convert, for example: np.float32, torch.float, etc. It also can be a sequence of dtype, each element corresponds to a key in ``keys``. device: for Tensor data type, specify the target device. wrap_sequence: if `False`, then lists will recursively call this function, default to `True`. E.g., if `False`, `[1, 2]` -> `[tensor(1), tensor(2)]`, if `True`, then `[1, 2]` -> `tensor([1, 2])`. track_meta: whether to convert to `MetaTensor` when `data_type` is "tensor". If False, the output data type will be `torch.Tensor`. Default to the return value of `get_track_meta`. allow_missing_keys: don't raise exception if key is missing. )r rrrN)rrr7rrrrr)rrr rrrrrrrrrszEnsureTyped.__init__rrrcCs8t|}|||jD]\}}||||||<q|SrrrrrrrszEnsureTyped.__call__)r NNTNF) rrrrrrrrrrrrrr_s "csFeZdZdZejZddddddd fd d Zd d dddZZS)rK Dictionary-based wrapper of :py:class:`monai.transforms.ToNumpy`. NTFr r rrrrrrrcs t||t||d|_dS)a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` dtype: target data type when converting to numpy array. wrap_sequence: if `False`, then lists will recursively call this function, default to `True`. E.g., if `False`, `[1, 2]` -> `[array(1), array(2)]`, if `True`, then `[1, 2]` -> `array([1, 2])`. allow_missing_keys: don't raise exception if key is missing. rrN)rrr.rrrrrrrrrrszToNumpyd.__init__Mapping[Hashable, Any]dict[Hashable, Any]rcCs.t|}||D]}|||||<q|Srrrrrrr&szToNumpyd.__call__)NTF) rrrrr.rrrrrrrrr scsFeZdZdZejZddddddd fd d Zd d dddZZS)ra Dictionary-based wrapper of :py:class:`monai.transforms.ToCupy`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` dtype: data type specifier. It is inferred from the input by default. if not None, must be an argument of `numpy.dtype`, for more details: https://docs.cupy.dev/en/stable/reference/generated/cupy.array.html. wrap_sequence: if `False`, then lists will recursively call this function, default to `True`. E.g., if `False`, `[1, 2]` -> `[array(1), array(2)]`, if `True`, then `[1, 2]` -> `array([1, 2])`. allow_missing_keys: don't raise exception if key is missing. NTFr znp.dtype | Nonerrr cs t||t||d|_dS)Nr)rrr,rrrrrr>szToCupyd.__init__rrrcCs.t|}||D]}|||||<q|SrrrrrrrHszToCupyd.__call__)NTF) rrrrr,rrrrrrrrr-s csBeZdZdZejZdddddfdd Zd d d d d ZZS)rr Fr rrrcst||t|_dS)z Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` allow_missing_keys: don't raise exception if key is missing. N)rrr/rrrrrrVszToPILd.__init__rrrcCs.t|}||D]}|||||<q|Srrrrrrr`szToPILd.__call__)F) rrrrr/rrrrrrrrrOs csTeZdZdZejZddddddfdd Zd d d d dZddd ddZZ S)rzM Dictionary-based wrapper of :py:class:`monai.transforms.Transpose`. Fr Sequence[int] | Nonerr)rindicesrrcst||t||_dSr)rrr2 transform)rrrrrrrrnszTransposed.__init__rrrcCsbt|}||D]J}|||||<|jjpFt||jddd}|j||d|idq|S)Nr extra_info)rrrrrndimr)rrrrrrrrrrs  zTransposed.__call__rrcCsnt|}||D]V}|||}t|tjd}t|}t| }|||||<| ||q|S)Nr) rrget_most_recent_transformrarrayr9 EXTRA_INFOargsortr2tolistr)rrrrrZ fwd_indicesZ inv_indicesrrrrr{s   zTransposed.inverse)F) rrrrr2rrrrrrrrrrgs  csBeZdZdZejejgZd dddddfd d Zd d Z Z S)rYz Delete specified items from data dictionary to release memory. It will remove the key-values and copy the others to construct a new dictionary. rFr r Sequence[bool] | boolr)rsepuse_rercs(t|||_t|t|j|_dS)a Args: keys: keys of the corresponding items to delete, can be "A{sep}B{sep}C" to delete key `C` in nested dictionary, `C` can be regular expression. See also: :py:class:`monai.transforms.compose.MapTransform` sep: the separator tag to define nested dictionary keys, default to ".". use_re: whether the specified key is a regular expression, it also can be a list of bool values, mapping them to `keys`. N)rrrr7rrr )rrrr rrrrs zDeleteItemsd.__init__csVdddfdd t|}tttt|j|jD]\}}||j||}q4|S)NFr)r csL|dt|dkr4|dd||<|Sfdd|DS)Nrcs4i|],\}}rt|r*s|kr||qSr)research)rrvrr rr sz?DeleteItemsd.__call__.._delete_item..)ritems)rrr  _delete_itemr%rr)s  z+DeleteItemsd.__call__.._delete_item)F) rrr rr rr splitr)rrrrr rr(rrs  zDeleteItemsd.__call__)rF rrrrr:TORCHNUMPYrrrrrrrrrYs c@s$eZdZdZejejgZddZdS)rz Select only specified items from data dictionary to release memory. It will copy the selected key-values and construct a new dictionary. csfdd|DS)Ncsi|]}||qSrrrrrrr&sz)SelectItemsd.__call__..)r)rrrr.rrszSelectItemsd.__call__N) rrrrr:r,r-rrrrrrrs csDeZdZdZejejgZddddddd fd d Zd d Z Z S)rsa] If an item is dictionary, it flatten the item by moving the sub-items (defined by sub-keys) to the top level. {"pred": {"a": ..., "b", ... }} --> {"a": ..., "b", ... } Args: keys: keys of the corresponding items to be flatten sub_keys: the sub-keys of items to be flatten. If not provided all the sub-keys are flattened. delete_keys: whether to delete the key of the items that their sub-keys are flattened. Default to True. prefix: optional prefix to be added to the sub-keys when moving to the top level. By default no prefix will be added. NTr KeysCollection | Noner str | Noner)rsub_keys delete_keysprefixrcs"t|||_||_||_dSr)rrr1r2r3)rrr1r2r3rrrrs zFlattenSubKeysd.__init__cCst|}||D]x}|jdkr,||n|j}|D]F}|jrP|jd|n|}||krltd|d|||||<q6|jr||=q|S)Nr'zR' already exists in the top-level keys. Please change `prefix` to avoid duplicity.)rrr1rr3rr2)rrrrr1skZsk_toprrrrs zFlattenSubKeysd.__call__)NTNr+rrrrrss  csFeZdZdZejZddddddd fd d Zd d dddZZS)rzN Dictionary-based wrapper of :py:class:`monai.transforms.SqueezeDim`. rTFr rrr)rrrrrcs t||t||d|_dS)a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` dim: dimension to be squeezed. Default: 0 (the first dimension) update_meta: whether to update the meta info if the input is a metatensor. Default is ``True``. allow_missing_keys: don't raise exception if key is missing. )rrN)rrr+r)rrrrrrrrrs zSqueezeDimd.__init__rrrcCs.t|}||D]}|||||<q|SrrrrrrrszSqueezeDimd.__call__)rTF) rrrrr+rrrrrrrrrsc sPeZdZdZejZdddd d d d d d d d d fdd ZdddddZZS)rVzM Dictionary-based wrapper of :py:class:`monai.transforms.DataStats`. DataTFNrr zSequence[str] | strrz$Sequence[Callable] | Callable | Noner rr) rr3r  data_shape value_range data_valueadditional_infonamerrc st|| t|t|j|_t|t|j|_t|t|j|_t|t|j|_t|t|j|_ t|t|j|_ t |d|_ dS)a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` prefix: will be printed in format: "{prefix} statistics". it also can be a sequence of string, each element corresponds to a key in ``keys``. data_type: whether to show the type of input data. it also can be a sequence of bool, each element corresponds to a key in ``keys``. data_shape: whether to show the shape of input data. it also can be a sequence of bool, each element corresponds to a key in ``keys``. value_range: whether to show the value range of input data. it also can be a sequence of bool, each element corresponds to a key in ``keys``. data_value: whether to show the raw value of input data. it also can be a sequence of bool, each element corresponds to a key in ``keys``. a typical example is to print some properties of Nifti image: affine, pixdim, etc. additional_info: user can define callable function to extract additional info from input data. it also can be a sequence of string, each element corresponds to a key in ``keys``. name: identifier of `logging.logger` to use, defaulting to "DataStats". allow_missing_keys: don't raise exception if key is missing. )r;N) rrr7rrr3r r7r8r9r:rprinter) rrr3r r7r8r9r:r;rrrrrs"zDataStatsd.__init__rrrc Cs`t|}|||j|j|j|j|j|jD]0\}}}}}}} ||||||||| ||<q*|Sr) rrr3r r7r8r9r:r<) rrrrr3r r7r8r9r:rrrr;s zDataStatsd.__call__)r6TTTFNrF) rrrrrrrrrrrrrrV s&+csDeZdZdZejZddddddfd d Zd d d ddZZS)rzQ Dictionary-based wrapper of :py:class:`monai.transforms.SimulateDelay`. Fr zSequence[float] | floatrr)r delay_timerrcs,t||t|t|j|_t|_dS)a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` delay_time: The minimum amount of time, in fractions of seconds, to accomplish this identity task. It also can be a sequence of string, each element corresponds to a key in ``keys``. allow_missing_keys: don't raise exception if key is missing. N)rrr7rrr>r)delayer)rrr>rrrrrKs zSimulateDelayd.__init__rrrcCs:t|}|||jD]\}}|j|||d||<q|S)N)r>)rrr>r?)rrrrr>rrrr[szSimulateDelayd.__call__)r=F) rrrrr)rrrrrrrrrDs csLeZdZdZejejgZdddddd d fd d Zd ddddZ Z S)rPz Copy specified items from data dictionary and save with different key names. It can copy several items together and copy several times. r!NFr rr/rr)rtimesnamesrrcst|||dkr&td|d|_|dkrHfddjDnt|}t|tj|krtdt|dtj|d|_dS) a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` times: expected copy times, for example, if keys is "img", times is 3, it will add 3 copies of "img" data to the dictionary, default to 1. names: the names corresponding to the newly copied data, the length should match `len(keys) x times`. for example, if keys is ["img", "seg"] and times is 2, names can be: ["img_1", "seg_1", "img_2", "seg_2"]. if None, use "{key}_{index}" as key for copy times `N`, index from `0` to `N-1`. allow_missing_keys: don't raise exception if key is missing. Raises: ValueError: When ``times`` is nonpositive. ValueError: When ``len(names)`` is not ``len(keys) * times``. Incompatible values. r!ztimes must be positive, got rNcs*g|]"}tjD]}|d|qqS)r)rr@)rrrrrrrs z'CopyItemsd.__init__..z8len(names) must match len(keys) * times, got len(names)=z len(keys) * times=)rrrr@rr6rrA)rrr@rArrrBrrjs$zCopyItemsd.__init__rrrcCst|}t|j}t|jD]x}|||j|||d|D]P\}}||krbtd|d||}t|t j t j frt |nt|||<qBq|S)zi Raises: KeyError: When a key in ``self.names`` already exists in ``data``. r!zKey z already exists in data.)rrrrr@rrAKeyErrorrtorchTensorrndarrayr copy_itemsr)rrrZkey_lenrrnew_keyvalrrrrs *,zCopyItemsd.__call__)r!NFr+rrrrrPbs $csLeZdZdZejejgZddddddd fd d Zd d dddZ Z S)rJa Concatenate specified items from data dictionary together on the first dim to construct a big array. Expect all the items are numpy array or PyTorch Tensor or MetaTensor. Return the first input's meta information when items are MetaTensor. rFr r rrr)rr;rrrcst||||_||_dS)a Args: keys: keys of the corresponding items to be concatenated together. See also: :py:class:`monai.transforms.compose.MapTransform` name: the name corresponding to the key to store the concatenated data. dim: on which dimension to concatenate the items, default is 0. allow_missing_keys: don't raise exception if key is missing. N)rrr;r)rrr;rrrrrrs zConcatItemsd.__init__rrrcCst|}g}d}||D]>}|dkr4t||}nt|||sJtd|||qt|dkrj|S|tjkrtj ||j d||j <n4t |t jrt j||j d||j <ntd|d|S)z Raises: TypeError: When items in ``data`` differ in type. TypeError: When the item type is not in ``Union[numpy.ndarray, torch.Tensor, MetaTensor]``. Nz*All items in data must have the same type.raxis)rzUnsupported data type: zB, available options are (numpy.ndarray, torch.Tensor, MetaTensor).)rrtyper TypeErrorrrrrFr5rr; issubclassrDrEcat)rrrrr rrrrrs&    zConcatItemsd.__call__)rFr+rrrrrJs  c sZeZdZdZejZedddfdddddddd fd d Zd d dddZddZ Z S)roa Dictionary-based wrapper of :py:class:`monai.transforms.Lambda`. For example: .. code-block:: python :emphasize-lines: 2 input_data={'image': np.zeros((10, 2, 2)), 'label': np.ones((10, 2, 2))} lambd = Lambdad(keys='label', func=lambda x: x[:4, :, :]) print(lambd(input_data)['label'].shape) (4, 2, 2) Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` func: Lambda/function to be applied. It also can be a sequence of Callable, each element corresponds to a key in ``keys``. inv_func: Lambda/function of inverse operation if want to invert transforms, default to `lambda x: x`. It also can be a sequence of Callable, each element corresponds to a key in ``keys``. track_meta: If `False`, then standard data objects will be returned (e.g., torch.Tensor` and `np.ndarray`) as opposed to MONAI's enhanced objects. By default, this is `True`. overwrite: whether to overwrite the original data in the input dictionary with lambda function output. it can be bool or str, when setting to str, it will create a new key for the output and keep the value of key intact. default to True. it also can be a sequence of bool or str, each element corresponds to a key in ``keys``. allow_missing_keys: don't raise exception if key is missing. Note: The inverse operation doesn't allow to define `extra_info` or access other information, such as the image's original size. If need these complicated information, please write a new InvertibleTransform directly. TFr Sequence[Callable] | Callablerz+Sequence[bool] | bool | Sequence[str] | strr)rfuncinv_funcr overwriterrcsTt||t|t|j|_t|t|j|_t|t|j|_t|d|_ dS)N)r) rrr7rrrQrRrSr%_lambdrrrQrRrrSrrrrrs zLambdad.__init__rrrcCsft|}|||j|jD]F\}}}|j|||d}|rNt|trN|||<qt|tr|||<q|S)N)imgrQ)rrrQrSrTrrr rrrrrQrSretrrrrs   zLambdad.__call__cCsBt|}|||jD]&\}}|jj||d}|r|||<q|S)Nr.)rrrSrTr)rrrrrSrXrrrrs  zLambdad.inverse) rrrrr%rrrrrrrrrrros"  c @sVeZdZdZejZeddddfdddddd dd d d d ZddZdddddZ dS)r|a Randomizable version :py:class:`monai.transforms.Lambdad`, the input `func` may contain random logic, or randomly execute the function based on `prob`. so `CacheDataset` will not execute it and cache the results. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` func: Lambda/function to be applied. It also can be a sequence of Callable, each element corresponds to a key in ``keys``. inv_func: Lambda/function of inverse operation if want to invert transforms, default to `lambda x: x`. It also can be a sequence of Callable, each element corresponds to a key in ``keys``. track_meta: If `False`, then standard data objects will be returned (e.g., torch.Tensor` and `np.ndarray`) as opposed to MONAI's enhanced objects. By default, this is `True`. overwrite: whether to overwrite the original data in the input dictionary with lambda function output. default to True. it also can be a sequence of bool, each element corresponds to a key in ``keys``. prob: probability of executing the random function, default to 1.0, with 100% probability to execute. note that all the data specified by `keys` will share the same random probability to execute or not. allow_missing_keys: don't raise exception if key is missing. For more details, please check :py:class:`monai.transforms.Lambdad`. Note: The inverse operation doesn't allow to define `extra_info` or access other information, such as the image's original size. If need these complicated information, please write a new InvertibleTransform directly. T?Fr rPrrfloatr)rrQrRrrSprobrrc Cs,tj|||||||dtj||dddS)NrUT)rr[ do_transform)rorr)rrrQrRrrSr[rrrrr7s  zRandLambdad.__init__cCs||t|}|||j|jD]j\}}}||}t|tsHt|}|jrx|j||d}|j |d|j |idn | ||r$|||<q$|S)N)rQ lambda_infor) randomizerrrQrSrr _do_transformrTrrrWrrrrLs    zRandLambdad.__call__rrrcCst|}|||jD]d\}}t||tr|||}|tjr||j |tj d|j ||}|r|||<q|S)Nr]) rrrSrrrr9 DO_TRANSFORMapplied_operationsrrrTr)rrrrrStrrXrrrr\s  zRandLambdad.inverseN) rrrrr%rrrrrrrrrr|scsFeZdZdZejZdddddddfdd Zd d d d dZZS)rla Dictionary-based wrapper of :py:class:`monai.transforms.LabelToMask`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` select_labels: labels to generate mask from. for 1 channel label, the `select_labels` is the expected label values, like: [1, 2, 3]. for One-Hot format label, the `select_labels` is the expected channel indices. merge_channels: whether to use `np.any()` to merge the result on channel dim. if yes, will return a single channel mask with binary data. allow_missing_keys: don't raise exception if key is missing. Fr zSequence[int] | intrr)r select_labelsmerge_channelsrrcs t||t||d|_dS)N)rcrd)rrr$r)rrrcrdrrrrr{szLabelToMaskd.__init__rrrcCs.t|}||D]}|||||<q|SrrrrrrrszLabelToMaskd.__call__)FF) rrrrr$rrrrrrrrrlis  c sLeZdZdZejZddddd d d d d dfdd ZdddddZZS)rba Dictionary-based wrapper of :py:class:`monai.transforms.FgBgToIndices`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` fg_postfix: postfix to save the computed foreground indices in dict. for example, if computed on `label` and `postfix = "_fg_indices"`, the key will be `label_fg_indices`. bg_postfix: postfix to save the computed background indices in dict. for example, if computed on `label` and `postfix = "_bg_indices"`, the key will be `label_bg_indices`. image_key: if image_key is not None, use ``label == 0 & image > image_threshold`` to determine the negative sample(background). so the output items will not map to all the voxels in the label. image_threshold: if enabled image_key, use ``image > image_threshold`` to determine the valid image content area and select background only in this area. output_shape: expected shape of output indices. if not None, unravel indices to specified shape. allow_missing_keys: don't raise exception if key is missing. _fg_indices _bg_indicesNr=Fr r r0rZrrr)r fg_postfix bg_postfix image_keyimage_threshold output_shaperrcs0t||||_||_||_t|||_dSr)rrrgrhrir r)rrrgrhrirjrkrrrrrs zFgBgToIndicesd.__init__rrrcCs`t|}|jr||jnd}||D]4}||||\|t||j<|t||j<q&|Sr)rrirrr rgrhrrrimagerrrrrs 2zFgBgToIndicesd.__call__)rerfNr=NF) rrrrr rrrrrrrrrbs"c sLeZdZdZejZddddd d d dd d d fdd ZddddZZS)ra Dictionary-based wrapper of :py:class:`monai.transforms.ClassesToIndices`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` indices_postfix: postfix to save the computed indices of all classes in dict. for example, if computed on `label` and `postfix = "_cls_indices"`, the key will be `label_cls_indices`. num_classes: number of classes for argmax label, not necessary for One-Hot label. image_key: if image_key is not None, use ``image > image_threshold`` to define valid region, and only select the indices within the valid region. image_threshold: if enabled image_key, use ``image > image_threshold`` to determine the valid image content area and select only the indices of classes in this area. output_shape: expected shape of output indices. if not None, unravel indices to specified shape. max_samples_per_class: maximum length of indices to sample in each class to reduce memory consumption. Default is None, no subsampling. allow_missing_keys: don't raise exception if key is missing. _cls_indicesNr=Fr r  int | Noner0rZrrr) rindices_postfix num_classesrirjrkmax_samples_per_classrrc s.t||||_||_t|||||_dSr)rrrprirr) rrrprqrirjrkrrrrrrrs zClassesToIndicesd.__init__rr.cCsNt|}|jr||jnd}||D]"}|||||t||j<q&|Sr)rrirrr rprlrrrrs  zClassesToIndicesd.__call__)rnNNr=NNF) rrrrrrrrrrrrrrs$cs@eZdZdZejZd dddfdd Zdd d d d ZZS)rMa Dictionary-based wrapper of :py:class:`monai.transforms.ConvertToMultiChannelBasedOnBratsClasses`. Convert labels to multi channels based on brats18 classes: label 1 is the necrotic and non-enhancing tumor core label 2 is the peritumoral edema label 4 is the GD-enhancing tumor The possible classes are TC (Tumor core), WT (Whole tumor) and ET (Enhancing tumor). Fr rrrcst||t|_dSr)rrrrrrrrrsz2ConvertToMultiChannelBasedOnBratsClassesd.__init__rrrcCs.t|}||D]}|||||<q|Srrrrrrrsz2ConvertToMultiChannelBasedOnBratsClassesd.__call__)F) rrrrrrrrrrrrrrMs c @sTeZdZdZejZddd d d d d d d dddZdddddZdddddZdS)rAa^ Dictionary-based wrapper of :py:class:`monai.transforms.AddExtremePointsChannel`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` label_key: key to label source to get the extreme points. background: Class index of background label, defaults to 0. pert: Random perturbation amount to add to the points, defaults to 0.0. 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. rescale_min: minimum value of output data. rescale_max: maximum value of output data. allow_missing_keys: don't raise exception if key is missing. rr=@rYFr r rrZz?Sequence[float] | float | Sequence[torch.Tensor] | torch.Tensorr)r label_key backgroundpertsigma rescale_min rescale_maxrc Cs<t|||||_||_g|_||_||_||_||_dSr) rrrwrxpointsrvryrzr{) rrrvrwrxryrzr{rrrrrs z!AddExtremePointsChanneld.__init__r r)labelrcCst||j|j|jd|_dS)N) rand_staterwrx)r4Rrwrxr|)rr}rrrr^-sz"AddExtremePointsChanneld.randomizerrrcCst|}||j}|jddkr(td||dddf||D]H}||}t|j||j|j |j d}t ||^}}t ||gdd||<qH|S)Nrr!z$Only supports single channel labels!)r|r}ryrzr{rJ) rrvshaperr^rr3r|ryrzr{r;r5)rrrr}rrV points_imagerrrrr0s" z!AddExtremePointsChanneld.__call__N)rr=rtrurYF) rrrrrrrr^rrrrrrAscsDeZdZdZejZddddddfdd Zd d d d dZZS)ra Dictionary-based wrapper of :py:class:`monai.transforms.TorchVision` for non-randomized transforms. For randomized transforms of TorchVision use :py:class:`monai.transforms.RandTorchVisiond`. Note: As most of the TorchVision transforms only work for PIL image and PyTorch Tensor, this transform expects input data to be dict of PyTorch Tensors, users can easily call `ToTensord` transform to convert Numpy to Tensor. Fr r rrrr;rrcs*t||||_t|f|||_dS)a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` name: The transform name in TorchVision package. allow_missing_keys: don't raise exception if key is missing. args: parameters for the TorchVision transform. kwargs: parameters for the TorchVision transform. N)rrr;r0transrrr;rargskwargsrrrrSs zTorchVisiond.__init__rrrcCs.t|}||D]}|||||<q|SrrrrrrrrrbszTorchVisiond.__call__)F) rrrrr0rrrrrrrrrGs c@s<eZdZdZejZdddddddd Zd d d d dZdS)ra Dictionary-based wrapper of :py:class:`monai.transforms.TorchVision` for randomized transforms. For deterministic non-randomized transforms of TorchVision use :py:class:`monai.transforms.TorchVisiond`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` name: The transform name in TorchVision package. allow_missing_keys: don't raise exception if key is missing. args: parameters for the TorchVision transform. kwargs: parameters for the TorchVision transform. Note: - As most of the TorchVision transforms only work for PIL image and PyTorch Tensor, this transform expects input data to be dict of PyTorch Tensors. Users should call `ToTensord` transform first to convert Numpy to Tensor. - This class inherits the ``Randomizable`` purely to prevent any dataset caching to skip the transform computation. If the random factor of the underlying torchvision transform is not derived from `self.R`, the results may not be deterministic. See Also: :py:class:`monai.transforms.Randomizable`. Fr r rrrcOs*t|||||_t|f|||_dSr)rrr;r0rrrrrrszRandTorchVisiond.__init__rrrcCs.t|}||D]}|||||<q|SrrrrrrrszRandTorchVisiond.__call__N)F)rrrrr0rrrrrrrriscsNeZdZdZejZejdfdddddddfd d Zd d d ddZ Z S)rrzQ Dictionary-based wrapper of :py:class:`monai.transforms.MapLabelValue`. Fr rr rr)r orig_labels target_labelsrrrcs"t||t|||d|_dS)a8 Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` orig_labels: original labels that map to others. target_labels: expected label values, 1: 1 map to the `orig_labels`. dtype: convert the output data to dtype, default to float32. if dtype is from PyTorch, the transform will use the pytorch backend, else with numpy backend. allow_missing_keys: don't raise exception if key is missing. )rrrN)rrr&mapper)rrrrrrrrrrszMapLabelValued.__init__rrrcCs.t|}||D]}|||||<q|Sr)rrrrrrrrszMapLabelValued.__call__) rrrrr&rrrrrrrrrrrrs c sVeZdZdZejZdddedfddddddddd d fd d Zd dddZZ S)rfaK Dictionary-based wrapper of :py:class:`monai.transforms.IntensityStats`. Compute statistics for the intensity values of input image and store into the metadata dictionary. For example: if `ops=[lambda x: np.mean(x), "max"]` and `key_prefix="orig"`, may generate below stats: `{"orig_custom_0": 1.5, "orig_max": 3.0}`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` ops: expected operations to compute statistics for the intensity. if a string, will map to the predefined operations, supported: ["mean", "median", "max", "min", "std"] mapping to `np.nanmean`, `np.nanmedian`, `np.nanmax`, `np.nanmin`, `np.nanstd`. if a callable function, will execute the function on input image. key_prefix: the prefix to combine with `ops` name to generate the key to store the results in the metadata dictionary. if some `ops` are callable functions, will use "{key_prefix}_custom_{index}" as the key, where index counts from 0. mask_keys: if not None, specify the mask array for the image to extract only the interested area to compute statistics, mask must have the same shape as the image. it should be a sequence of strings or None, map to the `keys`. channel_wise: whether to compute statistics for every channel of input image separately. if True, return a list of values for every operation, default to False. meta_keys: explicitly indicate the key of the corresponding metadata dictionary. used to store the computed statistics to the meta dict. 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 store the computed statistics to the meta dict. allow_missing_keys: don't raise exception if key is missing. NFr zSequence[str | Callable]r r/rr) rops key_prefix mask_keys channel_wise meta_keysmeta_key_postfixrrc st||t|||d|_|dkr6tdt|jnt||_|dkrXtdt|jnt||_ t|jt|j kr~t dt|t|j|_ dS)N)rrrz.meta_keys should have the same length as keys.) rrr#statsr7rrr6rrrr) rrrrrrrrrrrrrs ""zIntensityStatsd.__init__r)rcCszt|}|||j|j|jD]V\}}}}|p:|d|}|j|||||dk r`||ndd\||<||<q|S)Nr)rV meta_datamask)rrrrrrget)rrrrmask_keymeta_keyrrrrrszIntensityStatsd.__call__) rrrrr#rDEFAULT_POST_FIXrrrrrrrrfs"$csDeZdZdZejZddddddfdd Zd d d d dZZS)rzL Dictionary-based wrapper of :py:class:`monai.transforms.ToDevice`. Fr ztorch.device | strrr)rrrrc s&t||tfd|i||_dS)a Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` device: target device to move the Tensor, for example: "cuda:1". allow_missing_keys: don't raise exception if key is missing. kwargs: other args for the PyTorch `Tensor.to()` API, for more details: https://pytorch.org/docs/stable/generated/torch.Tensor.to.html. rN)rrr-r)rrrrrrrrrs zToDeviced.__init__rrrcCs.t|}||D]}|||||<q|Srrrrrrr szToDeviced.__call__)F) rrrrr-rrrrrrrrrs cs6eZdZdZd dddddfdd Zd d ZZS) rQa Dictionary-based wrapper of :py:class:`monai.transforms.CuCIM` for non-randomized transforms. For randomized transforms of CuCIM use :py:class:`monai.transforms.RandCuCIMd`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` name: The transform name in CuCIM package. allow_missing_keys: don't raise exception if key is missing. args: parameters for the CuCIM transform. kwargs: parameters for the CuCIM transform. Note: CuCIM transforms only work with CuPy arrays, this transform expects input data to be `cupy.ndarray`. Users can call `ToCuPy` transform to convert a numpy array or torch tensor to cupy array. Fr r rrrcs,tj||d||_t|f|||_dS)Nrs)rrr;rrrrrrr%szCuCIMd.__init__cCs.t|}||D]}|||||<q|Sz Args: data: Dict[Hashable, `cupy.ndarray`] Returns: Dict[Hashable, `cupy.ndarray`] rrrrrr*s zCuCIMd.__call__)F)rrrrrrrrrrrrQsc@s.eZdZdZd ddddddd Zd d Zd S)rva` Dictionary-based wrapper of :py:class:`monai.transforms.CuCIM` for randomized transforms. For deterministic non-randomized transforms of CuCIM use :py:class:`monai.transforms.CuCIMd`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` name: The transform name in CuCIM package. allow_missing_keys: don't raise exception if key is missing. args: parameters for the CuCIM transform. kwargs: parameters for the CuCIM transform. Note: - CuCIM transform only work with CuPy arrays, so this transform expects input data to be `cupy.ndarray`. Users should call `ToCuPy` transform first to convert a numpy array or torch tensor to cupy array. - This class inherits the ``Randomizable`` purely to prevent any dataset caching to skip the transform computation. If the random factor of the underlying cuCIM transform is not derived from `self.R`, the results may not be deterministic. See Also: :py:class:`monai.transforms.Randomizable`. Fr r rrrcOs*t|||||_t|f|||_dSr)rrr;rrrrrrrNszRandCuCIMd.__init__cCs.t|}||D]}|||||<q|SrrrrrrrSs zRandCuCIMd.__call__N)F)rrrrrrrrrrrv9scsDeZdZdZejZddddddfdd Zd d d d dZZS)r>am Dictionary-based wrapper of :py:class:`monai.transforms.AddCoordinateChannels`. Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` spatial_dims: the spatial dimensions that are to have their coordinates encoded in a channel and appended to the input image. E.g., `(0, 1, 2)` represents `H, W, D` dims and append three channels to the input image, encoding the coordinates of the input's three spatial dimensions. allow_missing_keys: don't raise exception if key is missing. Fr z Sequence[int]rr)r spatial_dimsrrcst||t|d|_dS)N)r)rrradd_coordinate_channels)rrrrrrrrrszAddCoordinateChannelsd.__init__rrrcCs.t|}||D]}|||||<q|Sr)rrrrrrrrvszAddCoordinateChannelsd.__call__)F) rrrrrrrrrrrrrr>bs csFeZdZdZejZddddddd fd d Zd d dddZZS)ria Dictionary-based wrapper of :py:class:`monai.transforms.ImageFilter`. Args: keys: keys of the corresponding items to be transformed. See also: monai.transforms.MapTransform kernel: A string specifying the kernel or a custom kernel as `torch.Tenor` or `np.ndarray`. Available options are: `mean`, `laplacian`, `elliptical`, `sobel_{w,h,d}`` kernel_size: A single integer value specifying the size of the quadratic or cubic kernel. Computational complexity increases exponentially with kernel_size, which should be considered when choosing the kernel size. allow_missing_keys: Don't raise exception if key is missing. NFr str | NdarrayOrTensorrorr)rkernel kernel_sizerrc s"t||t||f||_dSr)rrr"filter)rrrrrrrrrrszImageFilterd.__init__rrrcCs.t|}||D]}|||||<q|Sr)rrrrrrrrszImageFilterd.__call__)NF) rrrrr"rrrrrrrrri}s  c@s@eZdZdZejZdddddd d d d d ZdddddZdS)rya< Dictionary-based wrapper of :py:class:`monai.transforms.RandomFilterKernel`. Args: keys: keys of the corresponding items to be transformed. See also: monai.transforms.MapTransform kernel: A string specifying the kernel or a custom kernel as `torch.Tenor` or `np.ndarray`. Available options are: `mean`, `laplacian`, `elliptical`, `sobel_{w,h,d}`` kernel_size: A single integer value specifying the size of the quadratic or cubic kernel. Computational complexity increases exponentially with kernel_size, which should be considered when choosing the kernel size. prob: Probability the transform is applied to the data allow_missing_keys: Don't raise exception if key is missing. N皙?Fr rrorZrr)rrrr[rrcKs.t|||t||t||f||_dSr)rrrr"r)rrrrr[rrrrrrs  zRandImageFilterd.__init__rrrcCs>t|}|d|jr:||D]}|||||<q"|Sr)rr^r_rrrrrrrs  zRandImageFilterd.__call__)NrF)rrrrr"rrrrrrrrys )r __future__rr"collections.abcrrrcopyrtypingrrr numpyrrD monai.configr r monai.config.type_definitionsr monai.data.meta_tensorr rmonai.data.utilsrmonai.transforms.inversermonai.transforms.traitsrrmonai.transforms.transformrrrmonai.transforms.utility.arrayrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2monai.transforms.utilsr3r40monai.transforms.utils_pytorch_numpy_unificationr5 monai.utilsr6r7monai.utils.enumsr8r9r:monai.utils.type_conversionr;__all__rrrerDr\rrrrGrr_rrrrrYrrsrrVrrPrJror|rlrbrrMrArrrrrfrrQrvr>riryRandImageFilterDRandImageFilterDict ImageFilterDImageFilterDictrcrdrBrCrZr[rrrrrrrErFrrr]r^rrrrrrrrrWrXrrrrrTrUrrrNrOrHrIrmrnrjrkr`rarrrKrLr?r@rrr}r~rzr{rprqrgrhrrrRrSrwrxr<r=rtrurrrr s     |  q B#34!"#& 1;=5GN$/0C"%$D&)&,