Skip to content
Snippets Groups Projects
Commit 8f8c3264 authored by Christian Kento Rasmussen's avatar Christian Kento Rasmussen
Browse files

Began work on function to save .vol file

parent 13958fda
No related branches found
No related tags found
1 merge request!45Save files function
...@@ -378,6 +378,8 @@ class DataLoader: ...@@ -378,6 +378,8 @@ class DataLoader:
match dt: match dt:
case 'float': case 'float':
dt = np.float32 dt = np.float32
case 'float32':
dt = np.float32
case 'uint8': case 'uint8':
dt = np.uint8 dt = np.uint8
case 'unsigned integer': case 'unsigned integer':
......
...@@ -119,6 +119,29 @@ class DataSaver: ...@@ -119,6 +119,29 @@ class DataSaver:
# Save image # Save image
nib.save(img, path) nib.save(img, path)
def save_vol(self, path, data):
""" Save data to a VOL file to the given path.
Args:
path (str): The path to save file to
data (numpy.ndarray): The data to be saved
"""
# Create custom .vgi metadata file
metadata = ""
metadata += "{volume1}\n"
metadata += "[file1]"
metadata += "Size = 1000 1000 766"
metadata += "datatype = float\n"
metadata += "Name = WFW_200kV_6W_1mmSn_6micro_1s.vol"
# Save metadata
with open(path[:-3] + ".vgi", "w") as f:
f.write(metadata)
# Save data using numpy in binary format
np.save(path[:-3] + ".vol", data)
def save(self, path, data): def save(self, path, data):
"""Save data to the given path. """Save data to the given path.
...@@ -185,6 +208,12 @@ class DataSaver: ...@@ -185,6 +208,12 @@ class DataSaver:
return self.save_tiff(path, data) return self.save_tiff(path, data)
elif path.endswith((".nii","nii.gz")): elif path.endswith((".nii","nii.gz")):
return self.save_nifti(path, data) return self.save_nifti(path, data)
elif path.endswith(("TXRM","XRM","TXM")):
raise NotImplementedError("Saving TXRM files is not yet supported")
elif path.endswith(("h5")):
raise NotImplementedError("Saving HDF5 files is not yet supported")
elif path.endswith((".vol",".vgi")):
raise NotImplementedError("Saving VOL files is not yet supported")
else: else:
raise ValueError("Unsupported file format") raise ValueError("Unsupported file format")
# If there is no file extension in the path # If there is no file extension in the path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment