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

added function to convert zarr to nifti

parent cddb52ef
No related branches found
No related tags found
2 merge requests!102Conv zarr tiff folders,!100Conv zarr nifti
...@@ -31,6 +31,8 @@ class Convert: ...@@ -31,6 +31,8 @@ class Convert:
match input_ext, output_ext: match input_ext, output_ext:
case (".tif", ".zarr") | (".tiff", ".zarr"): case (".tif", ".zarr") | (".tiff", ".zarr"):
return self.convert_tif_to_zarr(input_path, output_path) return self.convert_tif_to_zarr(input_path, output_path)
case (".nii", ".zarr"):
return self.convert_nifti_to_zarr(input_path, output_path)
case _: case _:
raise ValueError("Unsupported file format") raise ValueError("Unsupported file format")
# Load a directory # Load a directory
...@@ -38,6 +40,8 @@ class Convert: ...@@ -38,6 +40,8 @@ class Convert:
match input_ext, output_ext: match input_ext, output_ext:
case (".zarr", ".tif") | (".zarr", ".tiff"): case (".zarr", ".tif") | (".zarr", ".tiff"):
return self.convert_zarr_to_tif(input_path, output_path) return self.convert_zarr_to_tif(input_path, output_path)
case (".zarr", ".nii"):
return self.convert_zarr_to_tif(input_path, output_path)
case _: case _:
raise ValueError("Unsupported file format") raise ValueError("Unsupported file format")
# Fail # Fail
...@@ -126,6 +130,18 @@ class Convert: ...@@ -126,6 +130,18 @@ class Convert:
return z return z
def convert_zarr_to_nifti(self, zarr_path, nifti_path):
"""Convert a zarr file to a nifti file
Args:
zarr_path (str): path to the zarr file
nifti_path (str): path to the nifti file
Returns:
None
"""
z = zarr.open(zarr_path)
nib.save(nib.Nifti1Image(z, np.eye(4)), nifti_path)
def convert(input_path: str, output_path: str, chunk_shape: tuple = (64, 64, 64)): def convert(input_path: str, output_path: str, chunk_shape: tuple = (64, 64, 64)):
"""Convert a file to another format without loading the entire file into memory """Convert a file to another format without loading the entire file into memory
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment