From bd542f1f4bbc1ea4a5878243f7bd69ccf596c1f7 Mon Sep 17 00:00:00 2001 From: Karol Gotkowski Date: Tue, 13 Aug 2024 17:18:04 +0200 Subject: [PATCH] fix: Fixed image saving with missing metadata --- medvol/__init__.py | 2 +- medvol/medvol.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/medvol/__init__.py b/medvol/__init__.py index 89b0070..0702d9f 100644 --- a/medvol/__init__.py +++ b/medvol/__init__.py @@ -1,3 +1,3 @@ -__version__ = "0.0.5" +__version__ = "0.0.6" from medvol.medvol import MedVol \ No newline at end of file diff --git a/medvol/medvol.py b/medvol/medvol.py index 0b38208..475ce90 100644 --- a/medvol/medvol.py +++ b/medvol/medvol.py @@ -83,9 +83,13 @@ def _load(self, filepath): def save(self, filepath): image_sitk = sitk.GetImageFromArray(self.array) - image_sitk.SetSpacing(self.spacing.tolist()[::-1]) - image_sitk.SetOrigin(self.origin.tolist()[::-1]) - image_sitk.SetDirection(self.direction.flatten().tolist()[::-1]) - for key, value in self.header.items(): - image_sitk.SetMetaData(key, value) + if self.spacing is not None: + image_sitk.SetSpacing(self.spacing.tolist()[::-1]) + if self.origin is not None: + image_sitk.SetOrigin(self.origin.tolist()[::-1]) + if self.direction is not None: + image_sitk.SetDirection(self.direction.flatten().tolist()[::-1]) + if self.header is not None: + for key, value in self.header.items(): + image_sitk.SetMetaData(key, value) sitk.WriteImage(image_sitk, filepath) \ No newline at end of file