-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (52 loc) · 2.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
import os
import glob
import pprint
from dcm2nii_mercure import convert_dicom_to_nifti
from nii2dcm_mercure import convert_nifti_to_dicom
from ants_motionCorrection import run_antsMotionCorr
def pretty_print_args(*args, **kwargs):
print("Arguments given to the function:")
pprint.pprint(args)
print("Keyword arguments given to the function:")
pprint.pprint(kwargs)
def main():
if len(sys.argv) != 3:
print("Error: Missing arguments!")
print("Usage: python main.py [input-folder] [output-folder]")
sys.exit(1)
dicom_in_folder = sys.argv[1]
nii_temp_folder = dicom_in_folder
output_dir = sys.argv[2]
## dcm2nii module
try:
convert_dicom_to_nifti(dicom_in_folder, nii_temp_folder)
print("DICOM to NIfTI conversion completed successfully.")
except Exception as e:
print(f"An error occurred during DICOM to NIfTI conversion: {e}")
return
nii_files = glob.glob(f'{nii_temp_folder}/*.nii') + glob.glob(f'{nii_temp_folder}/*.nii.gz')
if not nii_files:
print("No NIfTI files found in the temp folder.")
sys.exit(1)
nii_temp_file = nii_files[-1]
## processing module
try:
print("Processing NIfTI file...")
#print(f"Input NIfTI file: {nii_temp_file}")
#print(f"Output folder: {output_dir}")
nii_temp_file_out = run_antsMotionCorr(nii_temp_file, nii_temp_folder)
print("Processing completed successfully.")
except Exception as e:
print(f"An error occurred during processing: {e}")
return
## nii2dcm module
try:
convert_nifti_to_dicom(dicom_in_folder, nii_temp_file_out, output_dir)
print("NIfTI to DICOM conversion completed successfully.")
except Exception as e:
print(f"An error occurred during NIfTI to DICOM conversion: {e}")
print("--------------------------------------------------------------------------------")
pretty_print_args(dicom_in_folder, nii_temp_file_out, output_dir)
if __name__ == "__main__":
main()