44import glob
55import matplotlib .backends .backend_pdf
66import nibabel as nib
7- import nibabel as nii
8- import matplotlib . pyplot as plt
7+ from nilearn . plotting import plot_img
8+ from nilearn . image import index_img
99import pv_conv2Nifti as pr
1010import alive_progress as ap
1111import pv_parser as par
@@ -93,7 +93,14 @@ def CheckingRawFeatures(Path):
9393 if os .path .isfile (CP_v ) and os .path .isfile (CP_a ):
9494 try :
9595 pv .read_2dseq (map_raw = False , pv6 = False )
96- input_file = nii .squeeze_image (pv .nim )
96+ input_file = nib .squeeze_image (pv .nim )
97+ # this is a workaround to convert the data for nilearn plotting
98+ affine = np .eye (4 )
99+ affine [0 , 0 ] = pv .nim .header .get ('pixdim' )[1 ]
100+ affine [1 , 1 ] = pv .nim .header .get ('pixdim' )[2 ]
101+ affine [2 , 2 ] = pv .nim .header .get ('pixdim' )[3 ]
102+ affine [3 , 3 ] = pv .nim .header .get ('pixdim' )[4 ]
103+ input_file = nib .Nifti1Image (input_file .get_fdata (), affine = affine ,dtype = int (32 ))
97104 except ValueError :
98105 ErorrList .append (tf + "_Value Error" )
99106 print (tf )
@@ -135,21 +142,21 @@ def CheckingRawFeatures(Path):
135142# continue
136143# =============================================================================
137144 ########### Slice extraction
138- selected_img = Image_Selection (input_file )
139145 qc_path = os .path .join (saving_path ,"manual_slice_inspection" )
140146 if not os .path .isdir (qc_path ):
141147 os .mkdir (qc_path )
142148 img_name = str .split (tf ,os .sep )[- 2 ]
143149 full_img_name = str (N )+ "_" + img_name + "_" + str (dd )+ ".png" .replace (".nii" ,"" ).replace (".gz" ,"" )
144150 img_names_new .append (full_img_name )
145151
146- #plt.figure()
147- plt .axis ('off' )
148- plt .imshow (selected_img ,cmap = 'gray' )
149- #svg_path = os.path.join(qc_path,+ img_name+".png").replace(".nii","").replace(".gz","")
152+ # grandjean patch to output ortho representation of the image in manual slice inspection
150153 svg_path = os .path .join (qc_path ,str (N )+ "_" + img_name + "_" + str (dd )+ ".png" ).replace (".nii" ,"" ).replace (".gz" ,"" )
151154 dd = dd + 1
152- plt .savefig (svg_path )
155+ if len (input_file .shape ) == 4 :
156+ input_file_img = index_img (input_file ,0 )
157+ else :
158+ input_file_img = input_file
159+ plot_img (input_file_img , title = full_img_name , output_file = svg_path )
153160 ########### Slice extraction
154161 # other Features
155162 SpatRes = ResCalculator (input_file )
@@ -210,7 +217,7 @@ def CheckingRawFeatures(Path):
210217 df ["corresponding_img" ] = img_names_new
211218 df ['SpatRx' ] = np .array (SpatRes_vec )[:,0 ]
212219 df ['SpatRy' ] = np .array (SpatRes_vec )[:,1 ]
213- df ['Slicethick ' ] = np .array (SpatRes_vec )[:,2 ]
220+ df ['SpatRz ' ] = np .array (SpatRes_vec )[:,2 ]
214221 df ['Ghosting' ] = np .array (GMetric_vec )
215222
216223
@@ -340,7 +347,6 @@ def CheckingNiftiFeatures(Path):
340347 continue
341348
342349 ########### Slice extraction
343- selected_img = Image_Selection (input_file )
344350 qc_path = os .path .join (Path ,"manual_slice_inspection" )
345351 if not os .path .isdir (qc_path ):
346352 os .mkdir (qc_path )
@@ -349,12 +355,14 @@ def CheckingNiftiFeatures(Path):
349355 full_img_name = (str (N )+ "_" + folder_name + "_" + img_name + "_" + str (dd )+ ".png" ).replace (".nii" ,"" ).replace (".gz" ,"" )
350356 img_names_new .append (full_img_name )
351357
352- #plt.figure()
353- plt .axis ('off' )
354- plt .imshow (selected_img ,cmap = 'gray' )
355- svg_path = os .path .join (qc_path ,str (N )+ "_" + folder_name + "_" + img_name + "_" + str (dd )+ ".png" ).replace (".nii" ,"" ).replace (".gz" ,"" )
358+ # grandjean patch to output ortho representation of the image in manual slice inspection
359+ svg_path = os .path .join (qc_path ,str (N )+ "_" + img_name + "_" + str (dd )+ ".png" ).replace (".nii" ,"" ).replace (".gz" ,"" )
356360 dd = dd + 1
357- plt .savefig (svg_path )
361+ if len (input_file .shape ) == 4 :
362+ input_file_img = index_img (input_file ,0 )
363+ else :
364+ input_file_img = input_file
365+ plot_img (input_file_img , title = full_img_name , output_file = svg_path )
358366 ########### Slice extraction
359367 # other Features
360368 SpatRes = ResCalculator (input_file )
@@ -419,7 +427,7 @@ def CheckingNiftiFeatures(Path):
419427 df ["corresponding_img" ] = img_names_new
420428 df ['SpatRx' ] = np .array (SpatRes_vec )[:,0 ]
421429 df ['SpatRy' ] = np .array (SpatRes_vec )[:,1 ]
422- df ['Slicethick ' ] = np .array (SpatRes_vec )[:,2 ]
430+ df ['SpatRz ' ] = np .array (SpatRes_vec )[:,2 ]
423431 df ['Ghosting' ] = np .array (GMetric_vec )
424432
425433
0 commit comments