Open KirstieJane opened 7 years ago
import matplotlib.pylab as plt
import nibabel as nib
import numpy as np
fsaverage_500aparc_renum_f = '../../../../../Maastricht_FS6_ordered/SUB_DATA/fsaverageSubP/parcellation/500.aparc_renum.nii'
img_fsaverage500aparc_renum = nib.load(fsaverage_500aparc_renum_f)
data_fsaverage500aparc_renum = img_fsaverage500aparc_renum.get_data()
for i in range(300,380):
print(i, len(data_fsaverage500aparc_renum[data_fsaverage500aparc_renum==i]))
fsaverage_500aparc_f = '../../../../../Maastricht_FS6_ordered/SUB_DATA/fsaverageSubP/parcellation/500.aparc.nii'
img_fsaverage500aparc = nib.load(fsaverage_500aparc_f)
data_fsaverage500aparc = img_fsaverage500aparc.get_data()
for i in range(349,350):
print(i, len(data_fsaverage500aparc_renum[data_fsaverage500aparc_renum==i]))
for i in range(2150,2160):
print(i, len(data_fsaverage500aparc[data_fsaverage500aparc==i]))
for i in range(339,350):
print(i, len(data_fsaverage500aparc_renum[data_fsaverage500aparc_renum==i]))
for i in range(20):
print(i, len(data_fsaverage500aparc_renum[data_fsaverage500aparc_renum==i]))
for i in range(20):
print(i, len(data_fsaverage500aparc[data_fsaverage500aparc==i]))
labels, ctab, names = nib.freesurfer.read_annot('../label/lh.500.aparc.annot')
names
for i in range(20):
print(i, len(data_fsaverage500aparc[data_fsaverage500aparc==i]))
for i in range(41,45):
print(i, len(data_fsaverage500aparc[data_fsaverage500aparc==i]))
for i in range(41,45):
print(i, len(data_fsaverage500aparc[data_fsaverage500aparc==i]))
data_fsaverage500aparc
np.unique(data_fsaverage500aparc)
len(np.unique(data_fsaverage500aparc))
for new, old in enumerate(np.unique(data_fsaverage500aparc)):
print (new, old)
for new, old in enumerate(np.unique(data_fsaverage500aparc)):
print ('OLD: {} to NEW: {}'.format(old, new))
new_data = np.copy(old_data)
new_data = np.copy(data_fsaverage500aparc)
new_data = np.zeros_like(data_fsaverage500aparc)
for new, old in enumerate(np.unique(data_fsaverage500aparc)):
new_data[data_fsaverage500aparc==old] = new
for new, old in enumerate(np.unique(data_fsaverage500aparc)):
print(new); new_data[data_fsaverage500aparc==old] = new
nib.save?
img_new = img_fsaverage50
img_new = np.copy(img_fsaverage500aparc)
img_new.data = new_data
img_new.tofile('KWtesting.nii.gz')
img_new.to_filename('KWtesting.nii.gz')
img = img_fsaverage500aparc
img_new.to_filename('KWtesting.nii.gz')
img.data = data_new
img.data = new_data
img.to_filename('KWtesting.nii.gz')
ls
new_data
np.mean(new_data)
nib.Nifti1Image?
nib.Nifti1Image(new_data, img.affine)
new_img = nib.Nifti1Image(new_data, img.affine)
new_img.to_filename('KWtesting.nii.gz')
history
mri_label2vol --seg parcellation/500.aparc.nii.gz --temp mri/rawavg.mgz --o parcellation/500.aparc.indiv.nii.gz --regheader parcellation/500.aparc.nii.gz