11#!/usr/bin/python3.7
22'''
3- NIfTI Image Converter (v0.2.0 )
3+ NIfTI Image Converter (v0.2.5 )
44Created by Alexander Laurence
557 May 2019
66MIT License
@@ -26,22 +26,22 @@ def main(argv):
2626 inputfile = arg
2727 elif opt in ("-o" , "--output" ):
2828 outputfile = arg
29- print ('Input file is " ' , inputfile )
30- print ('Output file is " ' , outputfile )
29+ print ('Input file is ' , inputfile )
30+ print ('Output folder is ' , outputfile )
3131
3232 # set fn as your 4d nifti file
3333 image_array = nibabel .load (inputfile ).get_data ()
34+ print (len (image_array .shape ))
3435
3536 # if 4D image inputted
36- if len (image_array ) == 4 :
37+ if len (image_array . shape ) == 4 :
3738 # set 4d array dimension values
3839 nx , ny , nz , nw = image_array .shape
3940
4041 # set destination folder
41- dst = outputfile + "_" + inputfile [:- 4 ]
42- if not os .path .exists (dst ):
43- os .makedirs (dst )
44- print ("Created ouput directory: " + dst )
42+ if not os .path .exists (outputfile ):
43+ os .makedirs (outputfile )
44+ print ("Created ouput directory: " + outputfile )
4545
4646 print ("Converting NIfTI to png..." )
4747
@@ -65,23 +65,22 @@ def main(argv):
6565
6666 #move images to folder
6767 src = image_name
68- shutil .move (src , dst )
68+ shutil .move (src , outputfile )
6969 slice_counter += 1
7070 image_counter += 1
7171 volume_counter += 1
7272
7373 print ("Finished converting images" )
7474
7575 # else if 3D image inputted
76- elif len (image_array ) == 3 :
76+ elif len (image_array . shape ) == 3 :
7777 # set 4d array dimension values
7878 nx , ny , nz = image_array .shape
7979
8080 # set destination folder
81- dst = outputfile + "_" + inputfile [:- 4 ]
82- if not os .path .exists (dst ):
83- os .makedirs (dst )
84- print ("Created ouput directory: " + dst )
81+ if not os .path .exists (outputfile ):
82+ os .makedirs (outputfile )
83+ print ("Created ouput directory: " + outputfile )
8584
8685 print ("Converting NIfTI to png..." )
8786
@@ -100,7 +99,7 @@ def main(argv):
10099
101100 #move images to folder
102101 src = image_name
103- shutil .move (src , dst )
102+ shutil .move (src , outputfile )
104103 slice_counter += 1
105104 image_counter += 1
106105
@@ -110,4 +109,4 @@ def main(argv):
110109
111110# call the function to start the program
112111if __name__ == "__main__" :
113- convert (sys .argv [1 :])
112+ main (sys .argv [1 :])
0 commit comments