diff --git a/qim3d/io/convert.py b/qim3d/io/convert.py index 18b22fd61061ab95ef3780bfdc7a8308976a269b..5efee712d39158248f36578ac7125222db90e0fd 100644 --- a/qim3d/io/convert.py +++ b/qim3d/io/convert.py @@ -31,6 +31,8 @@ class Convert: match input_ext, output_ext: case (".tif", ".zarr") | (".tiff", ".zarr"): return self.convert_tif_to_zarr(input_path, output_path) + case (".nii", ".zarr"): + return self.convert_nifti_to_zarr(input_path, output_path) case _: raise ValueError("Unsupported file format") # Load a directory @@ -38,6 +40,8 @@ class Convert: match input_ext, output_ext: case (".zarr", ".tif") | (".zarr", ".tiff"): return self.convert_zarr_to_tif(input_path, output_path) + case (".zarr", ".nii"): + return self.convert_zarr_to_tif(input_path, output_path) case _: raise ValueError("Unsupported file format") # Fail @@ -126,6 +130,18 @@ class Convert: 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)): """Convert a file to another format without loading the entire file into memory