Create an ITK object from ``self.create_backend_obj(self.obj, ...)`` and call ``itk.imwrite``. Args: filename: filename or PathLike object. verbose: if ``True``, log the progress. kwargs: keyword arguments passed to ``itk.imwrite``,
(self, filename: PathLike, verbose: bool = False, **kwargs)
| 449 | ) |
| 450 | |
| 451 | def write(self, filename: PathLike, verbose: bool = False, **kwargs): |
| 452 | """ |
| 453 | Create an ITK object from ``self.create_backend_obj(self.obj, ...)`` and call ``itk.imwrite``. |
| 454 | |
| 455 | Args: |
| 456 | filename: filename or PathLike object. |
| 457 | verbose: if ``True``, log the progress. |
| 458 | kwargs: keyword arguments passed to ``itk.imwrite``, |
| 459 | currently support ``compression`` and ``imageio``. |
| 460 | |
| 461 | See also: |
| 462 | |
| 463 | - https://github.com/InsightSoftwareConsortium/ITK/blob/v5.2.1/Wrapping/Generators/Python/itk/support/extras.py#L809 |
| 464 | """ |
| 465 | super().write(filename, verbose=verbose) |
| 466 | self.data_obj = self.create_backend_obj( |
| 467 | cast(NdarrayOrTensor, self.data_obj), |
| 468 | channel_dim=self.channel_dim, |
| 469 | affine=self.affine, |
| 470 | dtype=self.output_dtype, |
| 471 | affine_lps_to_ras=self.affine_lps_to_ras, # type: ignore |
| 472 | **kwargs, |
| 473 | ) |
| 474 | itk.imwrite( |
| 475 | self.data_obj, filename, compression=kwargs.pop("compression", False), imageio=kwargs.pop("imageio", None) |
| 476 | ) |
| 477 | |
| 478 | @classmethod |
| 479 | def create_backend_obj( |