Skip to content

Commit c61cb88

Browse files
authored
Merge pull request #28 from grandjeanlab/main
make orthogonal qc plots with nilearn
2 parents 87e6981 + 42ce726 commit c61cb88

File tree

4 files changed

+38
-48
lines changed

4 files changed

+38
-48
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@ Main function: *ParsingData*
2525
See the full manual [here](https://github.com/Aswendt-Lab/AIDAqc/blob/main/docs/AIDAqc_v2_1.pdf).
2626

2727
<h3>Docker/Apptainer Usage</h3>
28-
Build:
2928

30-
```docker build aidaqc:2.1 .```
29+
```{bash}
30+
#Build
3131
32-
Running the main ParsingData.py:
32+
docker build aidaqc:2.1 .
3333
34-
```docker run -v /your/project/data:/data -v /your/project/qc aidaqc:2.1 -i /data -o /qc -f raw```
35-
=======
36-
For installation in a [apptainer](https://apptainer.org/) container for GNU/Linux:
34+
# Running the main ParsingData.py:
3735
38-
```{bash}
36+
docker run -v /your/project/data:/data -v /your/project/qc aidaqc:2.1 -i /data -o /qc -f raw
3937
38+
```
39+
40+
For installation in a [apptainer](https://apptainer.org/) container for GNU/Linux:
41+
```{bash}
4042
# Download the repository
4143
git clone https://github.com/Aswendt-Lab/AIDAqc.git
4244
cd AIDAqc
@@ -45,7 +47,7 @@ cd AIDAqc
4547
apptainer build aidaqc.sif apptainer.def
4648
4749
# Get into a bash shell in the container
48-
apptainer run aidaqc.sif
50+
apptainer shell aidaqc.sif
4951
5052
```
5153

@@ -64,7 +66,7 @@ This tool has been validated and used in the following publication: [Publication
6466
A total of 23 datasets from various institutes were used for validation and testing. These datasets can be found via: [Datasets Link](https://gin.g-node.org/Aswendt_Lab/2023_Kalantari_AIDAqc)
6567

6668
<h3>Download test dataset</h3>
67-
https://gin.g-node.org/Aswendt_Lab/testdata_aidaqc
69+
[Dataset Link](https://gin.g-node.org/Aswendt_Lab/testdata_aida)
6870

6971
[<h3><b>CONTACT</h3></b>](https://neurologie.uk-koeln.de/forschung/ag-neuroimaging-neuroengineering/)
7072
Aref Kalantari (aref.kalantari-sarcheshmehATuk-koeln.de) and Markus Aswendt (markus.aswendtATuk-koeln.de)

apptainer.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ From: ubuntu:latest
2828

2929
apt-get update -yy
3030
apt-get install -yy --no-install-recommends git python3 python3-pip fonts-unifont
31-
apt-get install -yy --reinstall ttf-mscorefonts-installer
3231

3332
git clone https://github.com/Aswendt-Lab/AIDAqc.git
3433
cd AIDAqc
@@ -44,4 +43,4 @@ From: ubuntu:latest
4443

4544
%runscript
4645

47-
bash
46+
ParsingData.py

scripts/FeatureCheck.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import glob
55
import matplotlib.backends.backend_pdf
66
import 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
99
import pv_conv2Nifti as pr
1010
import alive_progress as ap
1111
import 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

scripts/QC.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,6 @@ def GhostCheck(input_file):
9696

9797
#%% Res function
9898

99-
def Image_Selection(input_file):
100-
101-
img = input_file
102-
img_data=img.get_fdata()
103-
img_shape=img_data.shape
104-
middle=int(img_shape[2]/2)
105-
if len(img_shape) == 3:
106-
selected_img= img_data[:, :,middle]
107-
108-
elif len(img_shape) > 3:
109-
time_middle=int(img_shape[3]/2)
110-
selected_img= img_data[:, :,middle,time_middle]
111-
112-
selected_img= np.rot90(selected_img,k=-1)
113-
return selected_img
114-
115-
116-
#%%
117-
11899

119100
def ResCalculator(input_file):
120101

@@ -553,7 +534,7 @@ def QCPlot(Path):
553534
D = Abook[nn]
554535
for cc, C in enumerate(COL):
555536
Data = list(D[C])
556-
if C == 'SpatRx' or C == 'SpatRy' or C == 'Slicethick':
537+
if C == 'SpatRx' or C == 'SpatRy' or C == 'SpatRz':
557538
# Plot pie plots
558539
labels = list(set(Data))
559540
sizes = [Data.count(l) for l in labels]

0 commit comments

Comments
 (0)