Skip to content

Instantly share code, notes, and snippets.

@erramuzpe
Created February 5, 2018 15:59
Show Gist options
  • Save erramuzpe/c0b60738cdf7cf9fbae329f2195d51fe to your computer and use it in GitHub Desktop.
Save erramuzpe/c0b60738cdf7cf9fbae329f2195d51fe to your computer and use it in GitHub Desktop.
AAL atlas. Remove cerebellum ROIs and order left-right non consecutively
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 5 16:37:53 2018
@author: asier
"""
import numpy as np
import nibabel as nib
atlas_old = '/home/asier/Desktop/aal/AAL.nii'
atlas_new = '/home/asier/Desktop/aal/AALnew.nii'
atlas_old_img = nib.load(atlas_old)
atlas_old_data = nib.load(atlas_old).get_data()
atlas_old_data_rois = np.unique(atlas_old_data)
for i, roi in enumerate(atlas_old_data_rois):
if i ==0:
pass
else:
if i <= 90:
atlas_old_data[np.where(atlas_old_data==roi)]=i
else:
atlas_old_data[np.where(atlas_old_data==roi)]=0
atlas_new_data = np.zeros(atlas_old_data.shape)
counter = 1
for roi in range(1,91):
if (roi % 2) == 1:
atlas_new_data[np.where(atlas_old_data==roi)]=counter
else:
atlas_new_data[np.where(atlas_old_data==roi)]=counter+45
counter += 1
atlas_new_data_img_corrected = nib.Nifti1Image(atlas_new_data,
affine=atlas_old_img.affine)
nib.save(atlas_new_data_img_corrected,
atlas_new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment