EtienneCmb / visbrain

A multi-purpose GPU-accelerated open-source suite for brain data visualization
http://visbrain.org
Other
242 stars 65 forks source link

weird overlap in bilateral '.gii' import. #58

Closed iPsych closed 4 years ago

iPsych commented 4 years ago

download (1)

For same data, below code directly loading *.pial of freesurfer works fine.

lh_pial=lh.pial
rh_pial=rh.pial
files = [lh_pial, rh_pial]
b1 = BrainObj(files)

However, when try to load gii file as faces and vertexes, then merge like below

lh_pial=test_L.gii
rh_pial=test_R.gii
(vert_l, faces_l) = read_gii(lh_surf_mesh)
(vert_r, faces_r) = read_gii(rh_surf_mesh)

vert=np.vstack([vert_l, vert_r])
faces=np.vstack([faces_l, faces_r])
b2 = BrainObj('Custom', vertices=vert, faces=faces)

The result is broken 3D shape as attached. Is there any specific step required before make brain Obj?

EtienneCmb commented 4 years ago

Hi @iPsych ,

I think here you need to increment the faces_r with the number of faces in the faces_l because the number of vertices changed since it's concatenated over left and right hemispheres. Can you try something like this please :

(vert_l, faces_l) = read_gii(lh_surf_mesh)
(vert_r, faces_r) = read_gii(rh_surf_mesh)
faces_r += faces_l.shape[0]
faces = np.vstack([faces_l, faces_r])
iPsych commented 4 years ago

Hi, @EtienneCmb, It seems, the error happens as below. I think some number mismatch between lh and rh cause it.

IndexError: index 258612 is out of bounds for axis 0 with size 258108

EtienneCmb commented 4 years ago

And with this ?

faces_r += faces_l.max() + 1
iPsych commented 4 years ago

Perfect! it works : )

iPsych commented 4 years ago

@EtienneCmb, After successful mesh loading, annotation with parcellize comment also show strange result. I guess it is somehow related faces # just changed above? when annotation file loaded single hemisphere, just yellow brain or yellow brain with one region shows in purple.

b_obj.parcellize(lh_annot, hemisphere='left')

b_obj.parcellize(rh_annot, hemisphere='right')

Screen Shot 2020-02-03 at 10 20 15 PM

EtienneCmb commented 4 years ago

Hi @iPsych ,

Indeed, it might comes from the faces concatenation. A possible workaround could be to specify the indices that belongs to the left and to the right hemispheres (checkout the doc of the input lr_index) :

vert = np.vstack([vert_l, vert_r])
# left = True / right = False
lr_index = np.array([True] * vert_l.shape[0] + [False] * vert_r.shape[0])
# define your BrainObj
b2 = BrainObj('Custom', vertices=vert, faces=faces, lr_index=lr_index)
# try again the parcellize
[...]
iPsych commented 4 years ago

I already put the code as below, and seems to do the same function.

r _index = np.ones((vert_l.shape[0],), dtype=bool)
r_index = np.zeros((vert_r.shape[0],), dtype=bool)
lr_index = np.r_[l_index, r_index]

Tested both

b_obj.parcellize(lh_annot)
b_obj.parcellize(rh_annot)

and

b_obj.parcellize(lh_annot, hemisphere='left')
b_obj.parcellize(rh_annot, hemisphere='right')

but the only difference was the warning.

WARNING | left hemisphere(s) inferred from filename WARNING | right hemisphere(s) inferred from filename

It seems the code load annotation properly, but cannot map it properly. If I re-call the parcelize code as below, both hemisphere shows the proper segmented regions, but with changed color.

b_obj.parcellize(lh_annot, hemisphere='left')
b_obj.parcellize(rh_annot, hemisphere='right')
b_obj.parcellize(rh_annot, hemisphere='right')
EtienneCmb commented 4 years ago

Ok, indeed, there's probably an issue for selecting the correct left and right indices used for the parcellization.

The original purpose of your issue changed, could you please close this issue and reopen a new one, specifically for the parcelization issue?

iPsych commented 4 years ago

Issue closed and new issue opened.