Brain MRI Dataset Featuring a Full Clinical Protocol With and Without Intentional Motion.
The 5 matches
- [1] § Technical Validation › Registration and Analysis ↔ MotionCorrectedClinicalMRProtocol/analysis_img_quality.py, lines 15–74 · score 0.71 · FreeSurfer, uncorrected scan, ground truth, T1 MPR, motion correction, prospective
- [2] § Technical Validation › Observer scores ↔ MotionCorrectedClinicalMRProtocol/generate_plots_manuscript.py, lines 582–650 · score 0.63 · T1 STIR, T2 TSE, T2 FLAIR, 1–5, T1 MPR, motion
- [3] § Methods › Clinical MRI protocol ↔ MotionCorrectedClinicalMRProtocol/generate_plots_manuscript.py, lines 582–650 · score 0.61 · T1 STIR, T2 TSE, T2 FLAIR, T1 MPR, DWI, MR
- [4] § Data Records ↔ MotionCorrectedClinicalMRProtocol/recon_register.py, lines 8–88 · score 0.58 · T1 TIRM, T2 TSE, FreeSurfer, MPRAGE, FLAIR, motion correction
- [5] § Background & Summary ↔ MotionCorrectedClinicalMRProtocol/generate_plots_manuscript.py, lines 527–580 · score 0.55 · image quality metrics, observer scores, retrospective, PMC, prospective, motion correction
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 1,187 lines · 47 KB · MIT · 3 matches
- import numpy as np
- import matplotlib
- import matplotlib.pyplot as plt
- import glob
- import os
- import string
- import nibabel as nib
- from statsmodels.stats.multitest import multipletests
- from utils import Show_Stars, SortFiles, MakeBoxplot, DrawLines2, DrawLines
- from statistical_tests import PerformWilcoxonMotion, PerformWilcoxonAllImg
- plt.style.use('seaborn-whitegrid')
- matplotlib.rc('axes', edgecolor='black')
- from matplotlib.ticker import ScalarFormatter
- out_dir = '../Results/Plots/'
- in_dir_mot = '../Results/Motion_Estimates/'
- in_dir_met = '../Results/Metrics_Results/'
- in_dir_qs = '../ObserverQualityScores/'
- out_dir_metrics = '../Results/Metrics_Results/Comparison/'
- subdir = []
- for i in range(1,10):
- subdir.append('Subject_0'+str(i)+'/')
- for i in range(10,20):
- subdir.append('Subject_'+str(i)+'/')
- for i in range(20,23):
- subdir.append('Subject_'+str(i)+'/')
- sequs = ['T1_MPR', 'T2_FLAIR', 'T2_TSE', 'T1_TIRM', 'T2STAR', 'DIFF']
- save = '_2022_05_27'
- plot_motion = True
- plot_still = True
- plot_nod = True
- plot_DWI = True
- calc_ADC_hist = True
- ''' (1) Plot motion data: '''
- if plot_motion:
- # calculate p-values - first STILL, then NOD, then SHAKE, in each
- # cathegory: RMS, then median, then maximum
- p_values = []
- effect_size = []
- for mot in ['STILL', 'NOD', 'SHAKE']:
- RMS, median, maxim, descr = [], [], [], []
- for sequ in sequs:
- if mot == 'SHAKE' and sequ != 'T1_MPR':
- continue
- # find the most recent data:
- file = glob.glob(in_dir_mot+'MotionMetrics_'+mot+'/'+sequ+'*.txt')
- file = [f for f in file if 'mid' not in f] #sort out 'mid'
- if len(file)>0:
- file = SortFiles(file)
- metrics = np.loadtxt(file[0], unpack=True, skiprows=1)
- RMS.append(metrics[0])
- RMS.append(metrics[3])
- median.append(metrics[1])
- median.append(metrics[4])
- maxim.append(metrics[2])
- maxim.append(metrics[5])
- descr.append(sequ)
- descr.append(sequ)
- p_val, ind, alt, ES = PerformWilcoxonMotion(['RMS', 'Med', 'Max'], mot,
- [RMS, median, maxim],
- in_dir_mot, save,)
- p_values.append(p_val)
- effect_size.append(ES)
- #correct for multiple comparisons:
- p_values = np.concatenate(p_values)
- rej, p_values_cor, _, __ = multipletests(p_values, alpha=0.05,
- method='fdr_bh', is_sorted=False,
- returnsorted=False)
- p_values_cor_still = p_values_cor[0:18]
- p_values_cor_nod = p_values_cor[18:36]
- p_values_cor_shake = p_values_cor[36:]
- ind_p = np.array([[0,1], [2,3], [4,5], [6,7], [8,9], [10,11]])
- ind_sh = np.array([[0,1]])
- # plot:
- num = 0
- plt.figure(figsize=(13,10))
- for mot in ['STILL', 'NOD']:
- RMS, median, maxim, descr = [], [], [], []
- for sequ in sequs:
- # find the most recent data:
- file = glob.glob(in_dir_mot+'MotionMetrics_'+mot+'/'+sequ+'*.txt')
- file = [f for f in file if 'mid' not in f] # sort out mid
- if len(file)>0:
- file = SortFiles(file)
- # load the most recent file:
- metrics = np.loadtxt(file[0], unpack=True, skiprows=1)
- RMS.append(metrics[0])
- RMS.append(metrics[3])
- median.append(metrics[1])
- median.append(metrics[4])
- maxim.append(metrics[2])
- maxim.append(metrics[5])
- descr.append(sequ)
- descr.append(sequ)
- if mot == 'NOD':
- mot_s = 'SHAKE'
- RMS_s, median_s, maxim_s, descr_s = [], [], [], []
- sequ = 'T1_MPR'
- # find the most recent data:
- file = glob.glob(in_dir_mot+'MotionMetrics_'+mot_s+'/'+sequ+'*.txt')
- file = [f for f in file if 'mid' not in f] # sort out mid
- if len(file)>0:
- file = SortFiles(file)
- # load the most recent file
- metrics = np.loadtxt(file[0], unpack=True, skiprows=1)
- RMS_s.append(metrics[0])
- RMS_s.append(metrics[3])
- median_s.append(metrics[1])
- median_s.append(metrics[4])
- maxim_s.append(metrics[2])
- maxim_s.append(metrics[5])
- descr_s.append(sequ)
- descr_s.append(sequ)
- mean_RMS_s, mean_med_s, mean_max_s = [], [], []
- for i in range(len(RMS_s)):
- mean_RMS_s.append(np.mean(RMS_s[i]))
- mean_med_s.append(np.mean(median_s[i]))
- mean_max_s.append(np.mean(maxim_s[i]))
- # calculate mean values and define colors
- mean_RMS, mean_med, mean_max = [], [], []
- for i in range(len(RMS)):
- mean_RMS.append(np.mean(RMS[i]))
- mean_med.append(np.mean(median[i]))
- mean_max.append(np.mean(maxim[i]))
- colors = []
- labels = []
- for i in range(int(len(RMS)/2)):
- colors.append('tab:orange')
- colors.append('tab:blue')
- labels.append('without PMC')
- labels.append('with PMC')
- small = dict(markersize=3)
- # change 'TIRM' into STIR for descr:
- # and change 'TRACEW_B0' to 'DWI'
- for i in range(len(descr)):
- if descr[i]=='TRACEW_B0':
- descr[i]='DWI'
- if descr[i]=='T1_TIRM':
- descr[i]='T1_STIR'
- if descr[i]=='T2STAR':
- descr[i]='T2*'
- # plot the data:
- if mot=='STILL':
- ax0=plt.subplot2grid((4,5), (0,0), colspan=4)
- ax = ax0
- else:
- ax1=plt.subplot2grid((4,5), (2,0), colspan=4)
- ax = ax1
- MakeBoxplot(RMS, colors)
- for i in range(len(mean_RMS)):
- plt.plot(i+1, mean_RMS[i], '.', c=colors[i], ls='')
- if mot=='STILL':
- for y1, y2 in zip(RMS[4], RMS[5]):
- plt.plot([5,6], [y1, y2], 'darkslategray', lw=0.7)
- for y1, y2 in zip(RMS[8], RMS[9]):
- plt.plot([9,10], [y1, y2], 'darkslategray', lw=0.7)
- plt.title(mot+' scans', fontsize=17)
- plt.ylabel('RMS displ [mm]')
- plt.xticks(ticks=np.arange(1, len(RMS)+1), labels=descr)
- lim = plt.gca().get_ylim()
- plt.ylim(lim[0],(lim[1]-lim[0])*1.2+lim[0])
- ax.text(-0.1, .95, string.ascii_lowercase[num], transform=ax.transAxes,
- size=20, weight='bold')
- num += 1
- if mot=='STILL':
- use = 0
- low = -1
- if mot == 'NOD':
- use = 1
- low = -4
- max_RMS = [np.amax(RMS[i]) for i in range(len(RMS))]
- if mot=='STILL':
- Show_Stars(p_values_cor_still[0:6], ind_p, np.arange(1, len(RMS)+1),
- max_RMS, dh=0.05, col='black')
- ax01=plt.subplot2grid((4,5), (1,0), colspan=4)
- ax = ax01
- else:
- Show_Stars(p_values_cor_nod[0:6], ind_p, np.arange(1, len(RMS)+1),
- max_RMS, col='black')
- ax2=plt.subplot2grid((4,5), (3,0), colspan=4)
- ax = ax2
- MakeBoxplot(maxim, colors)
- for i in range(0,2):
- plt.plot(i+1, mean_max[i], '.', c=colors[i], ls='',
- label=labels[i])
- for i in range(2,len(mean_RMS)):
- plt.plot(i+1, mean_max[i], '.', c=colors[i], ls='')
- if mot=='STILL':
- for y1, y2 in zip(maxim[4], maxim[5]):
- plt.plot([5,6], [y1, y2], 'darkslategray', lw=0.7)
- for y1, y2 in zip(maxim[8], maxim[9]):
- plt.plot([9,10], [y1, y2], 'darkslategray', lw=0.7)
- plt.ylabel('Maximum displ [mm]')
- plt.xticks(ticks=np.arange(1, len(RMS)+1), labels=descr)
- lim = plt.gca().get_ylim()
- plt.ylim(lim[0],(lim[1]-lim[0])*1.1+lim[0])
- ax.text(-0.1, .95, string.ascii_lowercase[num], transform=ax.transAxes,
- size=20, weight='bold')
- num += 1
- if mot=='STILL':
- use = 0
- low = -3
- max_max = [np.amax(maxim[i]) for i in range(len(RMS))]
- if mot=='STILL':
- Show_Stars(p_values_cor_still[12:], ind_p, np.arange(1, len(RMS)+1),
- max_max, col='black')
- legend = plt.legend(loc='upper center', bbox_to_anchor=(1.16, 1.3),
- fontsize=13, frameon=True)
- else:
- Show_Stars(p_values_cor_nod[12:], ind_p, np.arange(1, len(RMS)+1),
- max_max, col='black')
- if mot == 'NOD':
- ax4=plt.subplot2grid((4,5), (2,4))
- ax = ax4
- ax1.get_shared_y_axes().join(ax1, ax4)
- MakeBoxplot(RMS_s, colors)
- for i in range(len(mean_RMS_s)):
- plt.plot(i+1, mean_RMS_s[i], '.', c=colors[i], ls='')
- plt.title(mot_s+' scans', fontsize=17)
- plt.xticks(ticks=np.arange(1, len(RMS_s)+1), labels=descr_s)
- lim = plt.gca().get_ylim()
- plt.ylim(lim[0],(lim[1]-lim[0])*1.1+lim[0])
- ax.text(-0.3, .95, string.ascii_lowercase[num],
- transform=ax.transAxes, size=20, weight='bold')
- num += 1
- max_RMS = [np.amax(RMS_s[i]) for i in range(len(RMS_s))]
- Show_Stars(np.array([p_values_cor_shake[0]]), ind_sh,
- np.arange(1, len(RMS)+1), max_RMS, col='black')
- ax5=plt.subplot2grid((4,5), (3,4))
- ax = ax5
- ax2.get_shared_y_axes().join(ax2, ax5)
- MakeBoxplot(maxim_s, colors)
- for i in range(0,2):
- plt.plot(i+1, mean_max_s[i], '.', c=colors[i], ls='',
- label=labels[i])
- for i in range(2,len(mean_RMS_s)):
- plt.plot(i+1, mean_max_s[i], '.', c=colors[i], ls='')
- plt.xticks(ticks=np.arange(1, len(RMS_s)+1), labels=descr_s)
- lim = plt.gca().get_ylim()
- plt.ylim(lim[0],(lim[1]-lim[0])*1.1+lim[0])
- ax.text(-0.3, .95, string.ascii_lowercase[num],
- transform=ax.transAxes, size=20, weight='bold')
- num += 1
- max_max = [np.amax(maxim[i]) for i in range(len(RMS_s))]
- Show_Stars(np.array([p_values_cor_shake[2]]), ind_sh,
- np.arange(1, len(RMS)+1), max_max, col='black')
- legend.get_frame().set_linewidth(2)
- plt.subplots_adjust(hspace=0.4, wspace=0.4)
- plt.savefig(out_dir+'Boxplot_motion_'+save+'.tiff', format='tiff',
- bbox_inches='tight', dpi=200)
- plt.savefig(out_dir+'Boxplot_motion_'+save+'.png', format='png',
- bbox_inches='tight', dpi=200)
- plt.show()
- ''' (2) Import image quality metrics: '''
- withRR = True
- onlyRR = False
- quality_scores = True
- show_stat_test = True
- sequs = ['T1_MPR', 'T2_FLAIR', 'T2_TSE', 'T1_TIRM', 'T2STAR', 'TRACEW_B1000']
- ssims, psnrs, tgs, qss, names_tes = [], [], [], [], []
- p_ssims, p_psnrs, p_tgs, p_qss, ind_ps = [], [], [], [], []
- for sequ in sequs:
- n = len(subdir)
- if sequ == 'T1_MPR':
- m = 10
- names = np.array(['MOCO_ON_STILL', 'MOCO_ON_SHAKE_RR', 'MOCO_ON_SHAKE',
- 'MOCO_ON_NOD_RR', 'MOCO_ON_NOD', 'MOCO_OFF_STILL',
- 'MOCO_OFF_SHAKE_RR', 'MOCO_OFF_SHAKE',
- 'MOCO_OFF_NOD_RR', 'MOCO_OFF_NOD'])
- else:
- m = 6
- names = np.array(['MOCO_ON_STILL', 'MOCO_ON_NOD_RR', 'MOCO_ON_NOD',
- 'MOCO_OFF_STILL', 'MOCO_OFF_NOD_RR', 'MOCO_OFF_NOD'])
- ssim, psnr, tg_, qs = np.zeros((n,m)), np.zeros((n,m)), np.zeros((n,m)), np.zeros((n,m))
- i=0
- print('Files used for calculation:')
- for sub in subdir:
- # skip all volunteers where the following sequences were not acquired
- if sequ in ['ADC', 'TRACEW_B0', 'TRACEW_B1000', 'T2_FLAIR', 'T2STAR']:
- tmp = os.listdir(in_dir_met+sub)
- tmp_ = ''
- if sequ not in tmp_.join(tmp):
- continue
- folder = in_dir_met+sub
- file_ = glob.glob(folder+'Values_*'+sequ+'*')
- file = [f for f in file_ if f.find('Retro')==-1]
- if len(file)>0:
- # get the most recent file:
- file = SortFiles(file, True)
- print(file[0])
- tmp1 = np.loadtxt(file[0], unpack=True, dtype=str, usecols=0,
- skiprows=1)
- tmp2, tmp3, tmp4 = np.loadtxt(file[0], unpack=True,
- usecols=(1,2,3), skiprows=1)
- if sequ == 'T2STAR' and np.size(tmp1) == 1:
- # A few subject only contain a MOCO OFF STILL T2STAR scan.
- # Those were only acquired for comparison with susceptibility
- # weighted scans and are not included in analysis of image
- # quality metrics.
- continue
- incl = []
- for na,s,p,t in zip(tmp1, tmp2, tmp3, tmp4):
- if sequ in ['T2STAR', 'ADC', 'TRACEW_B0', 'TRACEW_B1000']:
- if 'NOD' in na:
- na = na+'_RR'
- ind = np.where(names==na)[0][0]
- ssim[i,ind], psnr[i,ind], tg_[i,ind] = s, p, t
- incl.append(ind)
- # 0 entires represent non-existing scans
- # do the same for quality scores:
- if sequ not in ['T2STAR', 'ADC', 'TRACEW_B0', 'TRACEW_B1000']:
- file = glob.glob(in_dir_qs+sequ+' Score.txt')
- if len(file)>0:
- # get the most recent file:
- file = SortFiles(file)
- print(file[0])
- subj_names = np.loadtxt(file[0], unpack=True, dtype=str, usecols=0,
- skiprows=1)
- tmp1 = np.loadtxt(file[0], unpack=True, dtype=str, usecols=1,
- skiprows=1)
- tmp2, tmp3, tmp4 = np.loadtxt(file[0], unpack=True, usecols=(2,3,4),
- skiprows=1)
- tmp1 = tmp1[subj_names==sub[:-1]]
- tmp2 = tmp2[subj_names==sub[:-1]]
- tmp3 = tmp3[subj_names==sub[:-1]]
- tmp4 = tmp4[subj_names==sub[:-1]]
- incl = []
- for na,q1,q2,q3 in zip(tmp1, tmp2, tmp3, tmp4):
- if 'RETRO' not in na:
- ind = np.where(names==na[:-1])[0][0]
- # average the scores of the three raters with double weight for the radiologist
- qs[i,ind] = (q1+q2+2*q3)/4
- incl.append(ind)
- # for DWI quality ranks instead of quality scores:
- elif sequ == 'TRACEW_B1000':
- file = glob.glob(in_dir_qs+'DWI Rank.txt')
- if len(file)>0:
- # get the most recent file:
- file = SortFiles(file)
- print(file[0])
- subj_names = np.loadtxt(file[0], unpack=True, dtype=str, usecols=0,
- skiprows=1)
- tmp1 = np.loadtxt(file[0], unpack=True, dtype=str, usecols=1,
- skiprows=1)
- tmp2 = np.loadtxt(file[0], unpack=True, usecols=(2),
- skiprows=1)
- tmp1 = tmp1[subj_names==sub[:-1]]
- tmp2 = tmp2[subj_names==sub[:-1]]
- incl = []
- for na,q in zip(tmp1, tmp2):
- if 'NOD' in na:
- na = na+'_RR'
- if 'RETRO' not in na:
- ind = np.where(names==na)[0][0]
- qs[i,ind] = q
- incl.append(ind)
- else:
- qs = np.zeros_like(ssim)
- i+=1
- names = np.tile(names, (n,1))
- # check that names are the same for all volunteers:
- for i in range(1, len(subdir)):
- if np.all(names[0]==names[i], axis=0)==False:
- print('ERROR: Names of 0 and '+str(i)+' are not the same!')
- names = names[0]
- ''' sort out values == 0 (corresponding to missing scans) '''
- ssim[ssim==0] = np.nan
- psnr[psnr==0] = np.nan
- tg_[tg_==0] = np.nan
- qs[qs==0] = np.nan
- ''' perform parametric tests:'''
- # resort names and data (only for test), final resorting will be performed
- # after RR scans are potentially sorted out:
- names_ch = []
- for n in names:
- ind=n.find('_', 5)
- if 'OFF' in n:
- tmp = 'C'
- elif 'ON' in n:
- tmp = 'A'
- elif 'RETRO' in n:
- tmp = 'B'
- names_ch.append(n[ind+1:]+'_'+tmp)
- names_ch = np.array(names_ch)
- ind = np.argsort(names_ch)[::-1]
- ssim_p, psnr_p, tg_p, qs_p = ssim[:,ind], psnr[:,ind], tg_[:,ind], qs[:,ind]
- names_p = names_ch[ind]
- p_ssim, rej_ssim, ind_p, alt = PerformWilcoxonAllImg('SSIM', ssim_p, sequ,
- out_dir_metrics, save)
- p_psnr, rej_psnr, ind_p, alt = PerformWilcoxonAllImg('PSNR', psnr_p, sequ,
- out_dir_metrics, save)
- p_tg, rej_tg, ind_p, alt = PerformWilcoxonAllImg('TG', tg_p, sequ,
- out_dir_metrics, save)
- p_qs, rej_qs, ind_p, alt = PerformWilcoxonAllImg('QS', qs_p, sequ,
- out_dir_metrics, save)
- # sort out the relevant tests:
- if onlyRR == True:
- if sequ == 'T1_MPR':
- rel_tests = [0,1,4]
- p_ssim, p_psnr = p_ssim[rel_tests], p_psnr[rel_tests]
- p_tg, p_qs = p_tg[rel_tests], p_qs[rel_tests]
- ind_p = np.array([[0,1], [2,3], [4,5]])
- else:
- rel_tests = [0,1]
- p_ssim, p_psnr = p_ssim[rel_tests], p_psnr[rel_tests]
- p_tg, p_qs = p_tg[rel_tests], p_qs[rel_tests]
- ind_p = np.array([[0,1], [2,3]])
- if withRR == False:
- findRRs = np.char.find(names, 'RR')
- findRRs = (findRRs<0)
- names = names[findRRs]
- ssim, psnr, tg_ = ssim[findRRs], psnr[findRRs], tg_[findRRs]
- ssim = np.reshape(ssim, (len(subdir), int(len(ssim)/len(subdir))))
- psnr = np.reshape(psnr, (len(subdir), int(len(psnr)/len(subdir))))
- tg_ = np.reshape(tg_, (len(subdir), int(len(tg_)/len(subdir))))
- qs = np.reshape(qs, (len(subdir), int(len(qs)/len(subdir))))
- names = np.reshape(names, (len(subdir), int(len(names)/len(subdir))))
- if onlyRR == True:
- findRRs = np.char.find(names, 'RR')
- findstills = np.char.find(names, 'STILL')
- both = findRRs*findstills
- both = (both<0)
- names = names[both]
- ssim, psnr, tg_, qs = ssim[:,both], psnr[:,both], tg_[:,both], qs[:,both]
- std_ssim, std_psnr = np.nanstd(ssim, axis=0), np.nanstd(psnr, axis=0)
- std_tg_, std_qs = np.nanstd(tg_, axis=0), np.nanstd(qs, axis=0)
- mean_ssim, mean_psnr = np.nanmean(ssim, axis=0), np.nanmean(psnr, axis=0)
- mean_tg_, mean_qs = np.nanmean(tg_, axis=0), np.nanmean(qs, axis=0)
- # Final resorting:
- names_ch = []
- for n in names:
- ind=n.find('_', 5)
- if 'OFF' in n:
- tmp = 'C'
- elif 'ON' in n:
- tmp = 'A'
- elif 'RETRO' in n:
- tmp = 'B'
- names_ch.append(n[ind+1:]+'_'+tmp)
- names_ch = np.array(names_ch)
- ind = np.argsort(names_ch)[::-1]
- ssim, psnr, tg_, qs = ssim[:,ind], psnr[:,ind], tg_[:,ind], qs[:,ind]
- names = names[ind]
- mean_ssim, mean_psnr = mean_ssim[ind], mean_psnr[ind]
- mean_tg_, mean_qs = mean_tg_[ind], mean_qs[ind]
- names_te = []
- for i in range(int(len(names))):
- tmp = names[i]
- if 'RETRO' in tmp:
- app = 'retrospective MoCo'
- elif 'ON' in tmp:
- app = 'prospective MoCo'
- elif 'OFF' in tmp:
- app = 'no MoCo'
- if onlyRR == False:
- if 'RR' in tmp or 'STILL' in tmp:
- app = app + ' no REAC'
- else:
- app = app + ' with REAC'
- names_te.append(app)
- # sort out nans (whole rows for subjects wihtout that sequence)
- mask = np.where(np.isnan(ssim[:,0])==False)[0]
- ssim = ssim[mask]
- mask = np.where(np.isnan(psnr[:,0])==False)[0]
- psnr = psnr[mask]
- mask = np.where(np.isnan(tg_[:,0])==False)[0]
- tg_ = tg_[mask]
- mask = np.where(np.isnan(qs[:,0])==False)[0]
- qs = qs[mask]
- # normalise tg values by dividing with mean value of off still
- val = np.mean(tg_[:,0])
- tg_ = tg_/val
- # new color code:
- color_dict = {'retrospective MoCo': 'tab:green',
- 'prospective MoCo': 'tab:blue', 'no MoCo':'tab:orange'}
- if onlyRR == False:
- color_dict = {'retrospective MoCo no REAC': 'tab:green',
- 'prospective MoCo no REAC': 'tab:blue',
- 'no MoCo no REAC':'tab:orange',
- 'retrospective MoCo with REAC': 'tab:gray',
- 'prospective MoCo with REAC': 'tab:olive',
- 'no MoCo with REAC':'tab:cyan'}
- ssims.append(ssim)
- psnrs.append(psnr)
- tgs.append(tg_)
- qss.append(qs)
- names_tes.append(names_te)
- p_ssims.append(p_ssim)
- p_psnrs.append(p_psnr)
- p_tgs.append(p_tg)
- p_qss.append(p_qs)
- ind_ps.append(ind_p)
- ''' (3) Plot image quality metrics for still scans: '''
- if plot_still:
- metrics = [tgs, qss, np.array([qss[-1]])]
- p_values = [p_tgs, p_qss[0:4], np.array([p_qss[-1]])]
- labels = ['Tenengrad', 'Observer Scores', 'Quality Rank']
- colors = ['tab:orange', 'tab:blue', 'tab:orange', 'tab:blue', 'tab:orange',
- 'tab:blue', 'tab:orange', 'tab:blue', 'tab:orange', 'tab:blue',
- 'tab:orange', 'tab:blue']
- fig_labels = ['without PMC', 'with PMC']
- small = dict(markersize=3)
- x = np.arange(1,13)
- a = [0,2,4,6,8,10]
- b = [1,3,5,7,9,11]
- c = [1,3,5,7,9,11]
- d = [2,4,6,8,10,12]
- num = 0
- plt.figure(figsize=(10,9))
- for i, metric, p, lab in zip(range(0,3), metrics, p_values, labels):
- m_still = []
- means = []
- for m in metric:
- if len(m)>0:
- m_still.append(m[:,0])
- m_still.append(m[:,1])
- means.append(np.nanmean(m[:,0]))
- means.append(np.nanmean(m[:,1]))
- p_still = []
- for pval in p:
- p_still.append(pval[0])
- if i == 0:
- ax = plt.subplot2grid((2,6), (0,0), colspan=6)
- box1 = plt.boxplot(m_still, flierprops=small)
- for j in range(len(means)):
- plt.errorbar(x[j], means[j], yerr=None, color=colors[j], fmt='.', capsize=3)
- ticklabels = ['T1_MPR', 'T2_FLAIR', 'T2_TSE', 'T1_STIR', 'T2*', 'TRACEW']
- ticks = [1.5, 3.5, 5.5, 7.5, 9.5, 11.5]
- plt.xticks(labels=ticklabels, ticks=ticks, fontsize=14)
- elif i == 1:
- ax = plt.subplot2grid((2,6), (1,0), colspan=4)
- box1 = plt.boxplot(m_still[0:8], flierprops=small)
- for j in range(len(means)-2):
- plt.errorbar(x[j], means[j], yerr=None, color=colors[j], fmt='.', capsize=3)
- for j in range(0,2):
- plt.errorbar(x[j], means[j], yerr=None, color=colors[j], fmt='.',
- capsize=3, label=fig_labels[j])
- ticklabels = ['T1_MPR', 'T2_FLAIR', 'T2_TSE', 'T1_STIR']
- ticks = [1.5, 3.5, 5.5, 7.5]
- plt.xticks(labels=ticklabels, ticks=ticks, fontsize=14)
- else:
- ax = plt.subplot2grid((2,6), (1,5), colspan=1)
- box1 = plt.boxplot(m_still, flierprops=small)
- for j in range(len(means)):
- plt.errorbar(x[j], means[j], yerr=None, color=colors[j], fmt='.', capsize=3)
- ticklabels = ['DWI']
- ticks = [1.5]
- plt.xticks(labels=ticklabels, ticks=ticks, fontsize=14)
- plt.yticks([2,3,4])
- for patch, patch2, color in zip(box1['boxes'], box1['medians'], colors):
- patch.set(color=color, lw=1.7)
- patch2.set(color='k', lw=1.7)
- plt.ylabel(lab, fontsize=15)
- if show_stat_test == True:
- maxi = []
- for v in m_still:
- maxi.append(np.amax(v))
- if i == 0:
- indices = [[0,1], [2,3], [4,5], [6,7], [8,9], [10,11]]
- Show_Stars(np.array(p_still), indices[0:len(p_still)], x, maxi,
- col='black')
- elif i ==1:
- indices = [[0,1], [2,3], [4,5], [6,7]]
- Show_Stars(np.array(p_still), indices[0:len(p_still)], x[0:8], maxi[0:8],
- col='black')
- else:
- indices = [[0,1]]
- Show_Stars(np.array(p_still), indices[0:len(p_still)], x, maxi,
- col='black')
- lim = plt.gca().get_ylim()
- plt.ylim(lim[0],(lim[1]-lim[0])*1.05+lim[0])
- DrawLines2(a[0:len(p_still)],b[0:len(p_still)],c[0:len(p_still)],
- d[0:len(p_still)],m_still, lw=0.7, col='darkslategray')
- if i == 2:
- ax.text(-0.6, 0.95, string.ascii_lowercase[num],
- transform=ax.transAxes, size=24, weight='bold')
- else:
- ax.text(-0.1, 0.95, string.ascii_lowercase[num],
- transform=ax.transAxes, size=24, weight='bold')
- num += 1
- plt.yticks(fontsize=13)
- plt.tick_params('both', length=0)
- plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
- if i == 0:
- xlim = plt.gca().get_xlim()
- if i == 1:
- legend = plt.legend( loc='lower left', ncol=2,
- bbox_to_anchor=(0.4, -0.3), fontsize=14,
- frameon=True)
- plt.yticks(ticks=[2.5, 3, 3.5, 4, 4.5, 5])
- legend.get_frame().set_linewidth(2)
- plt.subplots_adjust(hspace=0.2, wspace=0.3)
- plt.savefig(out_dir+'Metrics_still'+save+'.tiff', format='tiff',
- bbox_inches='tight', dpi=200)
- plt.savefig(out_dir+'Metrics_still'+save+'.png', format='png',
- bbox_inches='tight', dpi=200)
- plt.show()
- ''' (4) Plot image quality metrics for nodding scans: '''
- if plot_nod:
- # first MPRAGE and FLAIR
- metrics = [ssims, psnrs, tgs, qss]
- p_values = [p_ssims, p_psnrs, p_tgs, p_qss[0:4]]
- labels = ['SSIM', 'PSNR', 'Tenengrad', 'Observer Scores']
- color_dict = {'prospective MoCo no REAC': 'tab:blue',
- 'no MoCo no REAC':'tab:orange',
- 'prospective MoCo with REAC': 'tab:green',
- 'no MoCo with REAC':'tab:cyan'}
- name_dict = {'prospective MoCo no REAC': 'with PMC without REAC',
- 'no MoCo no REAC':'without PMC without REAC',
- 'prospective MoCo with REAC': 'with PMC with REAC',
- 'no MoCo with REAC':'without PMC with REAC'}
- small = dict(markersize=3)
- x = np.concatenate((np.arange(1,9), np.arange(10,14)), axis=None)
- a = [0,2,4,6]
- b = [1,3,5,7]
- c = [1,3,5,7]
- d = [2,4,6,8]
- a_ = [0,2]
- b_ = [1,3]
- c_ = [10,12]
- d_ = [11,13]
- num = 0
- plt.figure(figsize=(11,8))
- for i, metric, p, lab in zip(range(0,4), metrics, p_values, labels):
- means = []
- names = []
- # first MPR
- tmp = metric[0]
- m_mpr = tmp[:,2:]
- names = names_tes[0][2:]
- # then FLAIR
- tmp = metric[1]
- m_fl = tmp[:,2:]
- names = np.concatenate((names, names_tes[1][2:]), axis=None)
- p_mot = []
- indices = []
- for pval, ind in zip(p[0:2], ind_ps[0:2]):
- p_mot.append(pval[1:])
- indices.append(ind[1:])
- means = np.concatenate((np.nanmean(m_mpr, axis=0),
- np.nanmean(m_fl, axis=0)), axis=None)
- colors = []
- leg_labels = []
- for n in names:
- colors.append(color_dict[n])
- leg_labels.append(name_dict[n])
- ax = plt.subplot(2,2,i+1)
- box1 = plt.boxplot(m_mpr, flierprops=small, widths=0.5)
- for patch, patch2, color in zip(box1['boxes'], box1['medians'], colors):
- patch.set(color=color, lw=1.5)
- patch2.set(color='k', lw=1.5)
- box2 = plt.boxplot(m_fl, positions=range(10,14), flierprops=small,
- widths=0.5)
- for patch, patch2, color in zip(box2['boxes'], box2['medians'], colors):
- patch.set(color=color, lw=1.5)
- patch2.set(color='k', lw=1.5)
- for j in range(len(means)):
- plt.errorbar(x[j], means[j], yerr=None, color=colors[j], fmt='.',
- capsize=3)
- if i == 2:
- for j in range(0,4):
- plt.errorbar(x[j], means[j], yerr=None, color=colors[j],
- fmt='.', capsize=3, label=leg_labels[j])
- legend = plt.legend( loc='lower left', ncol=2,
- bbox_to_anchor=(0.25, -0.4), fontsize=12,
- frameon=True)
- plt.ylabel(lab, fontsize=15)
- if show_stat_test == True:
- maxi = []
- for v in m_mpr.T:
- maxi.append(np.amax(v))
- Show_Stars(np.array(p_mot[0]), indices[0]-2, x, maxi,
- arange_dh='PAPER', col='black')
- for v in m_fl.T:
- maxi.append(np.amax(v))
- Show_Stars(np.array(p_mot[1]), indices[1]-2, x[8:], maxi,
- arange_dh='PAPER', col='black')
- lim = plt.gca().get_ylim()
- plt.ylim(lim[0],(lim[1]-lim[0])*1.01+lim[0])
- DrawLines(a,b,c,d,m_mpr, col='darkslategray')
- DrawLines(a_,b_,c_,d_,m_fl, col='darkslategray')
- ticklabels = ['T1_MPR\nSHAKE', 'T1_MPR\nNOD', 'T2_FLAIR\nNOD']
- ticks = [2.5, 6.5, 11.5]
- plt.xticks(labels=ticklabels, ticks=ticks, fontsize=12)
- ax.text(-0.18, 0.9, string.ascii_lowercase[num], transform=ax.transAxes,
- size=21, weight='bold')
- num += 1
- plt.yticks(fontsize=13)
- plt.tick_params('both', length=0)
- plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
- if i == 3:
- plt.yticks(ticks=[1, 2, 3, 4, 5])
- legend.get_frame().set_linewidth(2)
- plt.subplots_adjust(hspace=0.2, wspace=0.3)
- plt.savefig(out_dir+'Metrics_3D'+save+'.tiff', format='tiff',
- bbox_inches='tight', dpi=200)
- plt.savefig(out_dir+'Metrics_3D'+save+'.png', format='png',
- bbox_inches='tight', dpi=200)
- plt.show()
- # now TSE, STIR, T2* and TRACEW
- metrics = [ssims, psnrs, tgs, qss, np.array(qss[-1])]
- p_values = [p_ssims, p_psnrs, p_tgs, p_qss[0:4], np.array([p_qss[-1]])]
- labels = ['SSIM', 'PSNR', 'Tenengrad', 'Observer Scores', 'Quality Rank']
- color_dict = {'prospective MoCo no REAC': 'tab:blue',
- 'no MoCo no REAC':'tab:orange',
- 'prospective MoCo with REAC': 'tab:green',
- 'no MoCo with REAC':'tab:cyan'}
- name_dict = {'prospective MoCo no REAC': 'with PMC without REAC',
- 'no MoCo no REAC':'without PMC without REAC',
- 'prospective MoCo with REAC': 'with PMC with REAC',
- 'no MoCo with REAC':'without PMC with REAC'}
- small = dict(markersize=3)
- num = 0
- plt.figure(figsize=(13,8))
- for i, metric, p, lab in zip(range(0,5), metrics, p_values, labels):
- means = []
- names = []
- m_nod = []
- if i == 4:
- tmp = metric
- m_nod= [tmp[:,2:4]]
- means = [np.nanmean(tmp[:,2:4], axis=0)]
- names = [names_tes[j][2:4]]
- p_mot = [p[0,1]]
- indices = [ind_ps[-1][1]]
- elif i in [0,1,2,3]:
- for j in range(2, 6):
- end = 6
- if j in [4,5]:
- end = 4
- tmp = metric[j]
- m_nod.append(tmp[:,2:end])
- means.append(np.nanmean(tmp[:,2:end], axis=0))
- names.append(names_tes[j][2:end])
- p_mot = []
- indices = []
- for pval, ind in zip(p[2:6], ind_ps[2:6]):
- p_mot.append(pval[1:])
- indices.append(ind[1:])
- if i in [0,1,2]:
- ax = plt.subplot2grid((2,4), (i//2,i%2*2), colspan=2)
- if i == 3:
- ax = plt.subplot2grid((2,6), (1,3), colspan=2)
- if i == 4:
- ax = plt.subplot2grid((2,6), (1,5), colspan=1)
- N = 1
- lims = []
- for m, mean, p, index, name in zip(m_nod, means, p_mot, indices, names):
- colors = []
- leg_labels = []
- for n in name:
- colors.append(color_dict[n])
- leg_labels.append(name_dict[n])
- if i in [0,1,2]:
- positions = np.arange(N, N+len(m.T))
- box1 = plt.boxplot(m, positions=positions, flierprops=small,
- widths=0.5)
- for j in range(len(mean)):
- plt.errorbar(positions[j], mean[j], yerr=None, color=colors[j],
- fmt='.', capsize=3)
- if i == 2 and N == 1:
- for j in range(0,4):
- plt.errorbar(positions[j], mean[j], yerr=None,
- color=colors[j], fmt='.',
- capsize=3, label=leg_labels[j])
- legend = plt.legend( loc='lower left', ncol=2,
- bbox_to_anchor=(0.45, -0.4), fontsize=12,
- frameon=True)
- ticklabels = ['T2_TSE', 'T1_STIR', 'T2*', 'TRACEW']
- ticks = [2.5, 7.5, 11.5, 14.5]
- plt.xticks(labels=ticklabels, ticks=ticks, fontsize=12)
- if i == 3:
- positions = np.arange(N, N+len(m.T))
- box1 = plt.boxplot(m[0:8], positions=positions[0:8], flierprops=small,
- widths=0.5)
- for j in range(len(mean)):
- plt.errorbar(positions[j], mean[j], yerr=None, color=colors[j],
- fmt='.', capsize=3)
- ticklabels = ['T2_TSE', 'T1_STIR']
- ticks = [2.5, 7.5]
- plt.xticks(labels=ticklabels, ticks=ticks, fontsize=12)
- if i == 4:
- positions = np.arange(N, N+len(m.T))
- box1 = plt.boxplot(m, positions=positions, flierprops=small,
- widths=0.5)
- for j in range(len(mean)):
- plt.errorbar(positions[j], mean[j], yerr=None, color=colors[j],
- fmt='.', capsize=3)
- ticklabels = ['DWI']
- ticks = [1.5]
- plt.xticks(labels=ticklabels, ticks=ticks, fontsize=12)
- for patch, patch2, color in zip(box1['boxes'], box1['medians'], colors):
- patch.set(color=color, lw=1.5)
- patch2.set(color='k', lw=1.5)
- if show_stat_test == True:
- maxi = []
- for v in m.T:
- maxi.append(np.amax(v))
- if i in [0,1,2]:
- Show_Stars(np.array(p), index-2, positions, maxi,
- flexible_dh=True, col='black')
- if i == 3:
- Show_Stars(np.array(p), index-2, positions[0:8], maxi[0:8],
- flexible_dh=True, col='black')
- if i == 4:
- Show_Stars(np.array([p]), [index-2], positions, maxi,
- flexible_dh=True, col='black')
- lims.append(plt.gca().get_ylim())
- a = [0,2]
- b = [1,3]
- if N > 10 or i == 4:
- a = [0]
- b = [1]
- c = [positions[p] for p in a]
- d = [positions[p] for p in b]
- DrawLines(a,b,c,d,m, col='darkslategray')
- N = N+len(m.T)+1
- if show_stat_test:
- lims = np.array(lims)
- lim_min = np.amin(lims[:,0])
- lim_max = np.amax(lims[:,1])
- plt.ylim(lim_min,(lim_max-lim_min)*1.01+lim_min)
- plt.ylabel(lab, fontsize=15)
- plt.yticks(fontsize=13)
- plt.tick_params('both', length=0)
- plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
- if i == 4:
- ax.text(-0.51, 0.9, string.ascii_lowercase[num], transform=ax.transAxes,
- size=21, weight='bold')
- else:
- ax.text(-0.18, 0.9, string.ascii_lowercase[num], transform=ax.transAxes,
- size=21, weight='bold')
- num += 1
- if i == 3:
- plt.yticks(ticks=[1, 2, 3, 4, 5])
- if i == 4:
- plt.yticks(ticks=[1, 2, 3, 4])
- legend.get_frame().set_linewidth(2)
- plt.subplots_adjust(hspace=0.2, wspace=0.6)
- plt.savefig(out_dir+'Metrics_2D'+save+'.tiff', format='tiff',
- bbox_inches='tight', dpi=200)
- plt.savefig(out_dir+'Metrics_2D'+save+'.png', format='png',
- bbox_inches='tight', dpi=200)
- plt.show()
- ''' (5) Plot DWI analysis: '''
- if plot_DWI:
- # calculate histograms of ACS difference images:
- sub_out_dir = '../Results/Metrics_Results/'
- im_dir = '../BIDSdata_defaced/'
- in_dir = '../RegistrationTransforms/'
- bm_dir = '../Brainmasks/'
- subdir = []
- for i in range(1,10):
- subdir.append('Subject_0'+str(i)+'/')
- for i in range(10,20):
- subdir.append('Subject_'+str(i)+'/')
- for i in range(20,23):
- subdir.append('Subject_'+str(i)+'/')
- if calc_ADC_hist:
- all_mean, all_std, all_sum = [], [], []
- for sub in subdir:
- #print('Subject of interest is '+sub)
- # sort out subjects for which no DWI scans available:
- tmp = os.listdir(sub_out_dir+sub)
- tmp_ = ''
- if 'ADC' not in tmp_.join(tmp):
- continue
- differences = []
- descr = []
- still_off = glob.glob(im_dir+sub+'/TCLMOCO_OFF_STILL_EP2D_DIFF_EXTTRACKING_ADC*.nii')[0]
- still = nib.load(still_off).get_fdata().astype(np.uint16)
- bm = glob.glob(bm_dir+sub+'bm_mov_*ADC*.nii')[0]
- #glob.glob(in_dir+sub+'bm_mov_*ADC*.nii')[0]
- bm = nib.load(bm).get_fdata().astype(np.uint16)
- still = still*bm
- all_imgs = [x for x in glob.glob(im_dir+sub+'/*ADC*.nii') if x not in still_off]
- for im in all_imgs:
- img = nib.load(im).get_fdata().astype(np.uint16)
- img = img*bm
- diff = still.astype(np.float) - img.astype(np.float)
- differences.append(diff)
- descr.append(os.path.basename(im))
- differences, descr = np.array(differences), np.array(descr)
- ind = np.argsort(descr)
- differences = differences[ind]
- descr = descr[ind]
- sums, means, stds = [], [], []
- for i in range(0, len(descr)):
- diff = differences[i][bm!=0] # only look at voxels inside the brain!
- n, bins, tmp = plt.hist(diff, bins = 2000)
- plt.title(descr[i][12:25])
- sums.append(np.sum(np.abs(diff))/len(diff))
- mids = 0.5*(bins[1:]+bins[:-1])
- mean = np.average(mids, weights=n)
- std = np.sqrt(np.average((mids-mean)**2, weights=n))
- means.append(mean)
- stds.append(std)
- all_mean.append(means)
- all_std.append(stds)
- all_sum.append(sums)
- # look at results for all subjects:
- All_mean, All_std, All_sum = np.array(all_mean)[:,::-1], np.array(all_std)[:,::-1], np.array(all_sum)[:,::-1]
- save_arr = np.array([All_mean, All_std, All_sum])
- np.save(out_dir_metrics+'ADC_all_values_'+save, save_arr)
- # load the values for the ADC histograms and plot them:
- file = glob.glob(out_dir_metrics+'ADC_all_values_**.npy')
- if len(file)>0:
- # get the most recent file:
- #file = SortFiles(file)
- print(file[0])
- All_mean, All_std, All_sum = np.load(file[0])
- All_mean = np.array([All_mean[:,0], All_mean[:,2], All_mean[:,1]]).T
- All_std = np.array([All_std[:,0], All_std[:,2], All_std[:,1]]).T
- All_sum = np.array([All_sum[:,0], All_sum[:,2], All_sum[:,1]]).T
- names_diff = ['prospective MoCo', 'no MoCo', 'prospective MoCo']
- p_mean, rej_mean, ind, altern = PerformWilcoxonAllImg('Mean', All_mean, 'ADC',
- out_dir_metrics,
- save, option='diff')
- p_std, rej_std, ind, altern = PerformWilcoxonAllImg('Std', All_std, 'ADC',
- out_dir_metrics,
- save, option='diff')
- p_sum, rej_sum, ind, altern = PerformWilcoxonAllImg('Sum', All_sum, 'ADC',
- out_dir_metrics,
- save, option='diff')
- mean_mean = np.mean(All_mean, axis=0)
- mean_std = np.mean(All_std, axis=0)
- mean_sum = np.mean(All_sum, axis=0)
- color_dict = { 'prospective MoCo': 'tab:blue', 'no MoCo': 'tab:orange'}
- names = ['with PMC', 'without PMC', 'with PMC']
- colors_te = []
- for n in names_diff:
- colors_te.append(color_dict[n])
- x = np.arange(1,len(mean_mean)+1)
- plt.figure(figsize=(10,3))
- ax=plt.subplot(1,2,1)
- for i in range(len(x)):
- plt.errorbar(x[i], mean_mean[i], yerr=None, color=colors_te[i], fmt='.',
- capsize=3)
- small = dict(markersize=3)
- box1 = plt.boxplot(All_mean, flierprops=small)
- for patch, patch2, color in zip(box1['boxes'], box1['medians'], colors_te):
- patch.set(color=color, lw=1.7)
- patch2.set(color='k', lw=1.7)
- plt.xticks(labels=[], ticks=[])
- plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
- for y1, y2 in zip(All_mean[:,1], All_mean[:,2]):
- plt.plot([2,3], [y1, y2], 'darkslategray', lw=1)
- plt.annotate('Still', xy=(0.17, -0.1), xytext=(0.17, -0.18),
- xycoords='axes fraction', fontsize=12, ha='center', va='bottom',
- bbox=dict(boxstyle='square', fc='white', ec='grey', lw=1.5),
- arrowprops=dict(arrowstyle='-[, widthB=1.4, lengthB=0.7',
- lw=1.5, color='grey'))
- plt.annotate('Nod', xy=(0.67, -0.1), xytext=(0.67, -0.18),
- xycoords='axes fraction', fontsize=12, ha='center', va='bottom',
- bbox=dict(boxstyle='square', fc='white', ec='grey', lw=1.5),
- arrowprops=dict(arrowstyle='-[, widthB=3.0, lengthB=0.7',
- lw=1.5, color='grey'))
- Show_Stars(p_mean, ind, x, np.amax(All_mean, axis=0), arange_dh='diff',
- col='black')
- lim = plt.gca().get_ylim()
- plt.ylim(lim[0],(lim[1]-lim[0])*1.1+lim[0])
- plt.ylabel('Mean of histogram [$\\frac{\mu m^2}{s}$]')
- ax.text(-0.22, 0.9, string.ascii_lowercase[0], transform=ax.transAxes,
- size=21, weight='bold')
- ax=plt.subplot(1,2,2)
- for i in range(1):
- plt.errorbar(x[i], mean_std[i], yerr=None, color=colors_te[i], fmt='.',
- capsize=3)
- for i in range(1,len(x)):
- plt.errorbar(x[i], mean_std[i], yerr=None, label=names[i],
- color=colors_te[i], fmt='.', capsize=3)
- small = dict(markersize=3)
- box1 = plt.boxplot(All_std, flierprops=small)
- for patch, patch2, color in zip(box1['boxes'], box1['medians'], colors_te):
- patch.set(color=color, lw=1.7)
- patch2.set(color='k', lw=1.7)
- plt.xticks(labels=[], ticks=[])
- plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
- for y1, y2 in zip(All_std[:,1], All_std[:,2]):
- plt.plot([2,3], [y1, y2], 'darkslategray', lw=1)
- plt.annotate('Still', xy=(0.17, -0.1), xytext=(0.17, -0.18),
- xycoords='axes fraction', fontsize=12, ha='center', va='bottom',
- bbox=dict(boxstyle='square', fc='white', ec='grey', lw=1.5),
- arrowprops=dict(arrowstyle='-[, widthB=1.4, lengthB=0.7',
- lw=1.5, color='grey'))
- plt.annotate('Nod', xy=(0.67, -0.1), xytext=(0.67, -0.18),
- xycoords='axes fraction', fontsize=12, ha='center', va='bottom',
- bbox=dict(boxstyle='square', fc='white', ec='grey', lw=1.5),
- arrowprops=dict(arrowstyle='-[, widthB=3.0, lengthB=0.7',
- lw=1.5, color='grey'))
- Show_Stars(p_std, ind, x, np.amax(All_std, axis=0), arange_dh='diff',
- col='black')
- lim = plt.gca().get_ylim()
- plt.ylim(lim[0],(lim[1]-lim[0])*1.1+lim[0])
- plt.ylabel('Std of histogram [$\\frac{\mu m^2}{s}$]')
- legend = plt.legend(loc='upper center', ncol = 2,
- bbox_to_anchor=(-0.2, -0.25), frameon=True)
- ax.text(-0.22, 0.9, string.ascii_lowercase[1], transform=ax.transAxes,
- size=21, weight='bold')
- legend.get_frame().set_linewidth(2)
- plt.subplots_adjust(hspace=0.2, wspace=0.3)
- plt.savefig(out_dir+'ADC'+save+'.tiff', format='tiff', bbox_inches='tight',
- dpi=200)
- plt.savefig(out_dir+'ADC'+save+'.png', format='png', bbox_inches='tight',
- dpi=200)
- plt.show()
- # calculate mean value of ground truth scans:
- means = []
- for sub in subdir:
- if sub in ['HC_0'+str(i)+'/' for i in range(1,10)]:
- continue
- if sub in ['HC_'+str(i)+'/' for i in range(10,13)]:
- continue
- # sort out subjects for which no DWI scans available:
- tmp = os.listdir(sub_out_dir+sub)
- tmp_ = ''
- if 'ADC' not in tmp_.join(tmp):
- continue
- file = glob.glob(im_dir+sub+'/TCLMOCO_OFF_STILL_EP2D_DIFF_EXTTRACKING_ADC*.nii')[0]
- #glob.glob(im_dir+sub+'/*ADC*.nii')[0]
- img = nib.load(file).get_fdata().astype(np.uint16)
- bm_file = glob.glob(bm_dir+sub+'bm_mov_*ADC*.nii')[0]
- bm = nib.load(bm_file).get_fdata().astype(np.uint16)
- bm_fl = bm.flatten()
- dat = img.flatten()
- img_fl = dat[bm_fl>0]
- means.append(np.mean(img_fl))
- print('Mean Values of ground truth scans:', means)
- print('Overall mean value:', np.mean(means))
generate_plots_manuscript.py at commit ffd7086, under MIT · at the source
Overview
- Danish Research Centre for Magnetic Resonance, Department of Radiology and Nuclear Medicine, Copenhagen University Hospital - Amager and Hvidovre,Hvidovre, Denmark
- Neurobiology Research Unit, Copenhagen University Hospital - Rigshospitalet,Copenhagen, Denmark
- Department of Computer Science, University of Copenhagen,Copenhagen, Denmark
- Institute of Machine Learning in Biomedical Imaging, Helmholtz Munich, Neuherberg, Germany
- School of Computation, Information and Technology, Technical University of Munich,Munich, Germany
Abstract
The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.
Repositories
Its files are read in the Code ↔ Paper reader above, with 5 matches between paragraphs and lines of code.
melanieganz/mocoproject
ffd708616a24b5abe0531605e0e7a30bdb2df6cc, 10 May 2026Availability: 1 check, the latest on 29 September 2026: the link answers
- 29 September 2026: the link answers
33 files
- ChildrenHeadMotionMRI/
Matrix_Extraction.ipynb , Jupyter, 285 lines - ChildrenHeadMotionMRI/
Motion_Patterns.ipynb , Jupyter, 1,516 lines - ChildrenHeadMotionMRI/
functions.py , Python, 746 lines - ImageQualityMetrics/
AES.py , Python, 96 lines - ImageQualityMetrics/
CoEnt.py , Python, 192 lines - ImageQualityMetrics/
GradientEntropy.py , Python, 54 lines - ImageQualityMetrics/
ImageEntropy.py , Python, 44 lines - ImageQualityMetrics/
Image_quality_metrics.py , Python, 139 lines - ImageQualityMetrics/
Tenengrad.py , Python, 47 lines - ImageQualityMetrics/
utils.py , Python, 165 lines - MotionCorrectedClinicalM
RProtocol/ , Python, 96 linesQuality_Metrics/ AES.py - MotionCorrectedClinicalM
RProtocol/ , Python, 194 linesQuality_Metrics/ CoEnt.py - MotionCorrectedClinicalM
RProtocol/ , Python, 54 linesQuality_Metrics/ GradientEntropy.py - MotionCorrectedClinicalM
RProtocol/ , Python, 44 linesQuality_Metrics/ ImageEntropy.py - MotionCorrectedClinicalM
RProtocol/ , Python, 47 linesQuality_Metrics/ Tenengrad.py - MotionCorrectedClinicalM
RProtocol/ , Python, 165 linesQuality_Metrics/ utils.py - MotionCorrectedClinicalM
RProtocol/ , Python, 470 linesanalysis_cort_thickness. py - MotionCorrectedClinicalM
RProtocol/ , Python, 237 lines, 1 matchanalysis_img_quality.py - MotionCorrectedClinicalM
RProtocol/ , Python, 343 linesanalysis_motion_data.py - MotionCorrectedClinicalM
RProtocol/ , Python, 1,187 lines, 3 matchesgenerate_plots_manuscrip t.py - MotionCorrectedClinicalM
RProtocol/ , Python, 170 linesget_scan_end.py - MotionCorrectedClinicalM
RProtocol/ , Python, 214 linesimg_quality_metrics.py - MotionCorrectedClinicalM
RProtocol/ , Python, 676 linesmotion_estimates.py - MotionCorrectedClinicalM
RProtocol/ , Python, 206 lines, 1 matchrecon_register.py - MotionCorrectedClinicalM
RProtocol/ , Python, 236 linesstatistical_tests.py - MotionCorrectedClinicalM
RProtocol/ , Python, 312 linesutils.py - RealNoiseMRI/
Evaluate_SSIM.py , Python, 92 lines - RealNoiseMRI/
Rank_submissions.py , Python, 72 lines - RealNoiseMRI/
Save_reconstruction.py , Python, 105 lines - RealNoiseMRI/
Utils.py , Python, 250 lines - docker/
entrypoint.sh , Shell, 6 lines - LICENSE, License, 21 lines
- README.md, Text, 50 lines
OSF vzh4g
Availability: 1 check, the latest on 29 September 2026: the link answers (HTTP 200)
- 29 September 2026: the link answers (HTTP 200)
Code availability statement
The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it points to the authors' code: melanieganz/
mocoproject
Read it in the paper: doi.org/10.1038/s41597-026-07144-z.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 31 scripts, each with its path and the digest of its content;
- 5 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- doi:10.18112/
openneuro.ds004332.v1.3. , at OpenNeuro; found in the references0
Data availability statement
The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- no repository, dataset or request procedure was recognized in it
Read it in the paper: doi.org/10.1038/s41597-026-07144-z.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 29 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 5 authors, 3 keywords, 6 MeSH terms, 1 funder, 31 references.
Cite
This paper
Skak Madsen, K., Ruschke, T., Eichhorn, H., Rising, P., & Ganz, M. (2026). Brain MRI Dataset Featuring a Full Clinical Protocol With and Without Intentional Motion. Scientific data, 13(1), 943. https://
BibTeX
@article{skakmadsen2026b
author = {Skak Madsen, Kathrine and Ruschke, Tim and Eichhorn, Hannah and Rising, Puk and Ganz, Melanie},
title = {{Brain MRI Dataset Featuring a Full Clinical Protocol With and Without Intentional Motion}},
journal = {Scientific data},
year = {2026},
month = apr,
volume = {13},
number = {1},
pages = {943},
publisher = {Nature Publishing Group},
issn = {2052-4463},
doi = {10.1038/
url = {https://
pmid = {42026101},
pmcid = {PMC13315939}
}
RIS
TY - JOUR
AU - Skak Madsen, Kathrine
AU - Ruschke, Tim
AU - Eichhorn, Hannah
AU - Rising, Puk
AU - Ganz, Melanie
TI - Brain MRI Dataset Featuring a Full Clinical Protocol With and Without Intentional Motion
T2 - Scientific data
J2 - Sci Data
PY - 2026
DA - 2026/
VL - 13
IS - 1
SP - 943
SN - 2052-4463
PB - Nature Publishing Group
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"type": "article-journal",
"title": "Brain MRI Dataset Featuring a Full Clinical Protocol With and Without Intentional Motion",
"container-title": "Scientific data",
"author": [
{
"family": "Skak Madsen",
"given": "Kathrine"
},
{
"family": "Ruschke",
"given": "Tim"
},
{
"family": "Eichhorn",
"given": "Hannah"
},
{
"family": "Rising",
"given": "Puk"
},
{
"family": "Ganz",
"given": "Melanie"
}
],
"container-title-short":
"volume": "13",
"issue": "1",
"page": "943",
"DOI": "10.1038/
"PMID": "42026101",
"PMCID": "PMC13315939",
"ISSN": "2052-4463",
"publisher": "Nature Publishing Group",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
23
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1002/nbm.70368 [code]
- Intra-MRI Head Motion Tracking and Correction: A Quantitative In Vivo Evaluation Framework.Journal: NMR in biomedicineIn common: scikit-image, NiBabel, SciPy, 2 other tools, methods / tools, structural MRI / diffusion, 7 references
- [2] doi:10.1002/nbm.70286 [code]
- DEEP-DISORDER: Motion Correction in 3D MRI via Segment Reconstruction and Registration.Journal: NMR in biomedicineIn common: structural MRI / diffusion, 8 references
- [3] doi:10.1038/s41597-026-07377-y [code]
- An open-access multi-site fMRI dataset for investigating conscious visual perception.Journal: Scientific dataIn common: FreeSurfer, scikit-image, NiBabel, 4 other tools, 2 references
- [4] doi:10.1162/imag.a.1366 [code]
- MICAFlow: Fast and robust MRI preprocessing bridging research neuroimaging and clinical practice.Journal: Imaging neuroscience (Cambridge, Mass.)In common: FreeSurfer, NiBabel, SciPy, 2 other tools, methods / tools, structural MRI / diffusion, 3 references
- [5] doi:10.1162/imag.a.1262 [code]
- Frame-wise multi-echo distortion correction for superior functional MRI.Journal: Imaging neuroscience (Cambridge, Mass.)In common: pydicom, FreeSurfer, scikit-image, 4 other tools, 1 reference
- [6] doi:10.1002/alz.71649 [code]
- Postmortem brain MRI reveals differential associations of subcortical and limbic volumes with cortical thinning and neurodegenerative pathologies.Journal: Alzheimer's & dementia : the journal of the Alzheimer's AssociationIn common: FreeSurfer, scikit-image, NiBabel, 4 other tools, structural MRI / diffusion, 1 reference
- [7] doi:10.7554/elife.108408 [code]
- Frequency and laminar profile of feature-specific visual activity revealed by interleaved EEG-fMRI.Journal: eLifeIn common: FreeSurfer, scikit-image, NiBabel, 4 other tools, 1 reference
- [8] doi:10.7554/elife.107933 [code]
- Modality-agnostic decoding of vision and language from fMRI.Journal: eLifeIn common: FreeSurfer, scikit-image, NiBabel, 4 other tools, 1 reference
- [9] doi:10.1038/s41597-026-07350-9 [code]
- An open multi-center MEG-EEG dataset for studying conscious visual perception.Journal: Scientific dataIn common: FreeSurfer, scikit-image, NiBabel, 4 other tools, structural MRI / diffusion
- [10] doi:10.1038/s41597-026-06869-1 [code]
- Individual Brain Charting: fifth release of high-resolution fMRI data for cognitive mapping.Journal: Scientific dataIn common: FreeSurfer, scikit-image, NiBabel, 3 other tools, methods / tools, 1 reference
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 2 repositories of the authors' code, each at its verified commit and with its license, 31 scripts, and 5 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:3e18331e728acf34…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
