Created
July 16, 2019 19:41
-
-
Save fladd/eb92f8d9e5ed2696655768cfc6e93248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import OrderedDict | |
| import nibabel as nib | |
| from brainvoyagertools import voi # Get it from https://github.com/fladd/brainvoyagertools | |
| v1 = voi.VOIsDefinition(framing_cube=256, reference_space="MNI") | |
| v2 = voi.VOIsDefinition(framing_cube=256, reference_space="MNI") | |
| #img = nib.load("Parcels_MNI_111_256_mni.nii.gz") | |
| img = nib.load("Parcels_MNI_111_mni.nii") | |
| data = img.get_fdata() | |
| d = OrderedDict() | |
| for i in range(img.shape[0]): | |
| print(i) | |
| for j in range(img.shape[1]): | |
| for k in range(img.shape[2]): | |
| try: | |
| #d[data[i][j][k]].append([j, k, i]) | |
| d[data[i][j][k]].append(nib.affines.apply_affine(img.affine, [i, j, k])) | |
| except: | |
| d[data[i][j][k]] = [] | |
| d[data[i][j][k]].append(nib.affines.apply_affine(img.affine, [i, j, k])) | |
| #d[data[i][j][k]].append([j, k, i]) | |
| for x in sorted(d): | |
| if x != 0: | |
| if x < 256: | |
| v1.add_voi(voi.VOI(int(x), d[x], colour=[0,0,255])) | |
| else: | |
| v2.add_voi(voi.VOI(int(x), d[x], colour=[0,0,255])) | |
| v1.save("Parcels_MNI_111_orig_1-255") | |
| v2.save("Parcels_MNI_111_orig_256-333") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment