Resample ``self.data_obj`` if needed. This method assumes ``self.data_obj`` is a 'channel-last' ndarray. Args: meta_dict: a metadata dictionary for affine, original affine and spatial shape information. Optional keys are ``"spatial_shape"``, ``"affine"`
(self, meta_dict: Mapping | None, resample: bool = True, **options)
| 585 | ) |
| 586 | |
| 587 | def set_metadata(self, meta_dict: Mapping | None, resample: bool = True, **options): |
| 588 | """ |
| 589 | Resample ``self.data_obj`` if needed. This method assumes ``self.data_obj`` is a 'channel-last' ndarray. |
| 590 | |
| 591 | Args: |
| 592 | meta_dict: a metadata dictionary for affine, original affine and spatial shape information. |
| 593 | Optional keys are ``"spatial_shape"``, ``"affine"``, ``"original_affine"``. |
| 594 | resample: if ``True``, the data will be resampled to the original affine (specified in ``meta_dict``). |
| 595 | options: keyword arguments passed to ``self.resample_if_needed``, |
| 596 | currently support ``mode``, ``padding_mode``, ``align_corners``, and ``dtype``, |
| 597 | defaulting to ``bilinear``, ``border``, ``False``, and ``np.float64`` respectively. |
| 598 | """ |
| 599 | original_affine, affine, spatial_shape = self.get_meta_info(meta_dict) |
| 600 | if ( |
| 601 | self.output_dtype is None and self.data_obj is not None and hasattr(self.data_obj, "dtype") |
| 602 | ): # pylint: disable=E0203 |
| 603 | self.output_dtype = self.data_obj.dtype # type: ignore |
| 604 | self.data_obj, self.affine = self.resample_if_needed( |
| 605 | data_array=cast(NdarrayOrTensor, self.data_obj), |
| 606 | affine=affine, |
| 607 | target_affine=original_affine if resample else None, |
| 608 | output_spatial_shape=spatial_shape if resample else None, |
| 609 | mode=options.pop("mode", GridSampleMode.BILINEAR), |
| 610 | padding_mode=options.pop("padding_mode", GridSamplePadMode.BORDER), |
| 611 | align_corners=options.pop("align_corners", False), |
| 612 | dtype=options.pop("dtype", np.float64), |
| 613 | ) |
| 614 | |
| 615 | def write(self, filename: PathLike, verbose: bool = False, **obj_kwargs): |
| 616 | """ |