Skip to content

Commit

Permalink
fix: Fixed image saving with missing metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Karol-G committed Aug 13, 2024
1 parent c99a609 commit bd542f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion medvol/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.0.5"
__version__ = "0.0.6"

from medvol.medvol import MedVol
14 changes: 9 additions & 5 deletions medvol/medvol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit bd542f1

Please sign in to comment.