Apply the transform to `img`.
(self, img: torch.Tensor)
| 311 | self.update_meta = update_meta |
| 312 | |
| 313 | def __call__(self, img: torch.Tensor) -> list[torch.Tensor]: |
| 314 | """ |
| 315 | Apply the transform to `img`. |
| 316 | """ |
| 317 | n_out = img.shape[self.dim] |
| 318 | if isinstance(img, torch.Tensor): |
| 319 | outputs = list(torch.split(img, 1, self.dim)) |
| 320 | else: |
| 321 | outputs = np.split(img, n_out, self.dim) |
| 322 | for idx, item in enumerate(outputs): |
| 323 | if not self.keepdim: |
| 324 | outputs[idx] = item.squeeze(self.dim) |
| 325 | if self.update_meta and isinstance(img, MetaTensor): |
| 326 | if not isinstance(item, MetaTensor): |
| 327 | item = MetaTensor(item, meta=img.meta) |
| 328 | if self.dim == 0: # don't update affine if channel dim |
| 329 | continue |
| 330 | ndim = len(item.affine) |
| 331 | shift = torch.eye(ndim, device=item.affine.device, dtype=item.affine.dtype) |
| 332 | shift[self.dim - 1, -1] = idx |
| 333 | item.affine = item.affine @ shift |
| 334 | return outputs |
| 335 | |
| 336 | |
| 337 | class CastToType(Transform): |
nothing calls this directly
no test coverage detected