Dictionary-based wrapper of :py:class:`monai.transforms.EnsureChannelFirst`.
| 257 | |
| 258 | |
| 259 | class EnsureChannelFirstd(MapTransform): |
| 260 | """ |
| 261 | Dictionary-based wrapper of :py:class:`monai.transforms.EnsureChannelFirst`. |
| 262 | """ |
| 263 | |
| 264 | backend = EnsureChannelFirst.backend |
| 265 | |
| 266 | def __init__( |
| 267 | self, keys: KeysCollection, strict_check: bool = True, allow_missing_keys: bool = False, channel_dim=None |
| 268 | ) -> None: |
| 269 | """ |
| 270 | Args: |
| 271 | keys: keys of the corresponding items to be transformed. |
| 272 | See also: :py:class:`monai.transforms.compose.MapTransform` |
| 273 | strict_check: whether to raise an error when the meta information is insufficient. |
| 274 | allow_missing_keys: don't raise exception if key is missing. |
| 275 | channel_dim: This argument can be used to specify the original channel dimension (integer) of the input array. |
| 276 | It overrides the `original_channel_dim` from provided MetaTensor input. |
| 277 | If the input array doesn't have a channel dim, this value should be ``'no_channel'``. |
| 278 | If this is set to `None`, this class relies on `img` or `meta_dict` to provide the channel dimension. |
| 279 | """ |
| 280 | super().__init__(keys, allow_missing_keys) |
| 281 | self.adjuster = EnsureChannelFirst(strict_check=strict_check, channel_dim=channel_dim) |
| 282 | |
| 283 | def __call__(self, data: Mapping[Hashable, torch.Tensor]) -> dict[Hashable, torch.Tensor]: |
| 284 | d = dict(data) |
| 285 | for key in self.key_iterator(d): |
| 286 | meta_dict = d[key].meta if isinstance(d[key], MetaTensor) else None # type: ignore[attr-defined] |
| 287 | d[key] = self.adjuster(d[key], meta_dict) |
| 288 | return d |
| 289 | |
| 290 | |
| 291 | class RepeatChanneld(MapTransform): |
no outgoing calls
searching dependent graphs…