MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / set_metadata

Method set_metadata

monai/data/image_writer.py:425–449  ·  view source on GitHub ↗

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 = None, resample: bool = True, **options)

Source from the content-addressed store, hash-verified

423 self.data_obj = self.data_obj[..., 0]
424
425 def set_metadata(self, meta_dict: Mapping | None = None, resample: bool = True, **options):
426 """
427 Resample ``self.data_obj`` if needed. This method assumes ``self.data_obj`` is a 'channel-last' ndarray.
428
429 Args:
430 meta_dict: a metadata dictionary for affine, original affine and spatial shape information.
431 Optional keys are ``"spatial_shape"``, ``"affine"``, ``"original_affine"``.
432 resample: if ``True``, the data will be resampled to the original affine (specified in ``meta_dict``).
433 options: keyword arguments passed to ``self.resample_if_needed``,
434 currently support ``mode``, ``padding_mode``, ``align_corners``, and ``dtype``,
435 defaulting to ``bilinear``, ``border``, ``False``, and ``np.float64`` respectively.
436 """
437 original_affine, affine, spatial_shape = self.get_meta_info(meta_dict)
438 if self.output_dtype is None and hasattr(self.data_obj, "dtype"): # pylint: disable=E0203
439 self.output_dtype = self.data_obj.dtype # type: ignore
440 self.data_obj, self.affine = self.resample_if_needed(
441 data_array=cast(NdarrayOrTensor, self.data_obj),
442 affine=affine,
443 target_affine=original_affine if resample else None,
444 output_spatial_shape=spatial_shape if resample else None,
445 mode=options.pop("mode", GridSampleMode.BILINEAR),
446 padding_mode=options.pop("padding_mode", GridSamplePadMode.BORDER),
447 align_corners=options.pop("align_corners", False),
448 dtype=options.pop("dtype", np.float64),
449 )
450
451 def write(self, filename: PathLike, verbose: bool = False, **kwargs):
452 """

Callers 3

test_channel_shapeMethod · 0.95
test_rgbMethod · 0.95
__call__Method · 0.45

Calls 3

resample_if_neededMethod · 0.80
popMethod · 0.80
get_meta_infoMethod · 0.45

Tested by 2

test_channel_shapeMethod · 0.76
test_rgbMethod · 0.76