Created
March 25, 2024 18:55
-
-
Save Palpatineli/c057cf6e1b2934d28fe9ec2df427390e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3.10 | |
from pathlib import Path | |
import argparse | |
import SimpleITK as sitk | |
def main(folder: str, output: str | None): | |
input_path = Path(folder) | |
output_path = input_path if output is None else Path(output) | |
output_path.mkdir(parents=True, exist_ok=True) | |
for file in input_path.iterdir(): | |
img = sitk.ReadImage(file) | |
sitk.WriteImage(img, output_path.joinpath(file.stem + '.nii.gz'), useCompression=True) | |
print(f'[success] converted {file.name} to nii') | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser('mha2nixi') | |
parser.add_argument('folder', type=str) | |
parser.add_argument('output', default=None, type=str) | |
args = parser.parse_args() | |
main(args.folder, args.output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment