tomfrankkirk / toblerone

Surface-based analysis tools
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

ERROR: Both surfaces must have same triangles array #1

Closed diaosilei closed 2 years ago

diaosilei commented 2 years ago

When I use the command toblerone.pvestimation.cortex(LWS=LWS, LPS=LPS, RWS=RWS, RPS=RPS, ref=ref, struct2ref=struct2ref, struct=struct, flirt=True) to do the PVE, an error (Both surfaces must have same triangles array) occured. And I found this error was generated by the code (line 747 and line 748) in toblerone/classes/surfaces.py. The root reason is the faces of LWS are different with the faces of LPS. Is there any need to keep their faces same?

tomfrankkirk commented 2 years ago

Hi,

This is expected behaviour as some of the algorithms need triangle correspondence between both surfaces. There may however be a way around this. Could you give me some more information please? What tool did you use to generate the surfaces, and do they represent the cortex? I ask because all the surface reconstruction tools I know of (FreeSurfer, Caret) do produce surfaces with triangle correspondence. How many triangles are there on the LWS and LPS surfaces?

diaosilei commented 2 years ago

Hi,

This is expected behaviour as some of the algorithms need triangle correspondence between both surfaces. There may however be a way around this. Could you give me some more information please? What tool did you use to generate the surfaces, and do they represent the cortex? I ask because all the surface reconstruction tools I know of (FreeSurfer, Caret) do produce surfaces with triangle correspondence. How many triangles are there on the LWS and LPS surfaces?

Thanks for reply. The data I used is from the third released dHCP dataset. I think they represent the cortex. I do not which tools was used to produce the surfaces. The number of triangles in LWS and LPS is 160646. Here is the code I use https://github.com/ralidimitrova/neo_cortexDev/blob/main/pvc/run_toblerone.py.

tomfrankkirk commented 2 years ago

This is unexpected - if both the LWS and LPS have the same number of triangles, then I would expect they do actually have triangle correspondence.

Two questions. Can you try running pvestimation.cortex with just the RPS and RWS only? Does it give the same error?

Can you send me the LWS and LPS (or RWS and RPS if they also give the error) on here so that I can download them and take a look?

diaosilei commented 2 years ago

Thanks. The LWS and LPS do have the same number of triangles, but there are 515 different triangles in them. I tried to running pvestimation.cortex with just the RPS and RWS only, and the same error occured. The attachment contains the two files including LWS and LPS. attachment.zip

tomfrankkirk commented 2 years ago

Received, thanks. Will take a look and get back to you (may be a day or two).

Looking at the dHCP pipelines paper, last paragraph before section 3.1, it says the following:

Following adult frameworks, proposed for FreeSurfer (Fischl et al., 1999b), and refined by the Human Connectome Project (Glasser et al., 2013), all computed surfaces of each subject (white, pial, midthickness, inflated, spherical) have one-to-one point correspondence between vertices. This ensures that for each individual brain the same vertex index represents the same relative point on the anatomy for all these surfaces. In other words, two corresponding points on the white and pial surface would approximate the endpoints of where a column of neurons through the cortex would travel. This simplifies downstream processing, and facilitates straightforward visualisation of features across multiple surface views.

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6783314/

I'm understanding this as saying they really should have triangle correspondence too. Can you re-create this issue on another subject, and are you sure the surfaces have not been corrupted or mixed up in any way?

tomfrankkirk commented 2 years ago

Have also sent a message to someone involved in setting up the pipelines so will see what they say.

tomfrankkirk commented 2 years ago

Update - a reply I got back:

The surfaces absolutely should have vertex correspondence! We discovered in August 2021 that there was a vertex correspondence problem coming from the structural pipeline being run by the Imperial team. My understanding was that this had been fixed and the surfaces re-released, but perhaps not. I have just sent an email to the PIs asking if this was actually done. I will get back to you as soon as I hear back.

diaosilei commented 2 years ago

Received, thanks. Will take a look and get back to you (may be a day or two).

Looking at the dHCP pipelines paper, last paragraph before section 3.1, it says the following:

Following adult frameworks, proposed for FreeSurfer (Fischl et al., 1999b), and refined by the Human Connectome Project (Glasser et al., 2013), all computed surfaces of each subject (white, pial, midthickness, inflated, spherical) have one-to-one point correspondence between vertices. This ensures that for each individual brain the same vertex index represents the same relative point on the anatomy for all these surfaces. In other words, two corresponding points on the white and pial surface would approximate the endpoints of where a column of neurons through the cortex would travel. This simplifies downstream processing, and facilitates straightforward visualisation of features across multiple surface views.

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6783314/

I'm understanding this as saying they really should have triangle correspondence too. Can you re-create this issue on another subject, and are you sure the surfaces have not been corrupted or mixed up in any way?

Thanks very much. I am sure the surfaces have not been corrupted or mixed in any way. I have just noticed that the triangles of white surface and pial surface are all the same except for the corpus callosum part. So can I just remove the the code (line 747 and line 748, also seen below) in toblerone/classes/surfaces.py to solve this error?

if (self.inSurf.tris != self.outSurf.tris).any(): raise ValueError("Both surfaces must have same triangles array") Because I think the corpus callosum part may not influence the result of PVC?

diaosilei commented 2 years ago

Update - a reply I got back:

The surfaces absolutely should have vertex correspondence! We discovered in August 2021 that there was a vertex correspondence problem coming from the structural pipeline being run by the Imperial team. My understanding was that this had been fixed and the surfaces re-released, but perhaps not. I have just sent an email to the PIs asking if this was actually done. I will get back to you as soon as I hear back.

Thanks again. And what do you mean re-create this issue on another subject?

tomfrankkirk commented 2 years ago

If you try a subject besides sub-CC00065XX08, what happens?

tomfrankkirk commented 2 years ago

Thanks very much. I am sure the surfaces have not been corrupted or mixed in any way. I have just noticed that the triangles of white surface and pial surface are all the same except for the corpus callosum part. So can I just remove the the code (line 747 and line 748, also seen below) in toblerone/classes/surfaces.py to solve this error?

Strictly speaking, yes you can disable the check, but I wouldn't recommend it. It may or may not cause issues further down the line (I don't know off the top of my head), and what's more, the issues may not be obvious.

Entirely up to you, but my suggestion would be to find out what's happening with the input surfaces - as the email makes clear, they really should have triangle correspondence, so are likely to be flawed in some way.

diaosilei commented 2 years ago

If you try a subject besides sub-CC00065XX08, what happens?

This error would occur again

diaosilei commented 2 years ago

Thanks very much. I am sure the surfaces have not been corrupted or mixed in any way. I have just noticed that the triangles of white surface and pial surface are all the same except for the corpus callosum part. So can I just remove the the code (line 747 and line 748, also seen below) in toblerone/classes/surfaces.py to solve this error?

Strictly speaking, yes you can disable the check, but I wouldn't recommend it. It may or may not cause issues further down the line (I don't know off the top of my head), and what's more, the issues may not be obvious.

Entirely up to you, but my suggestion would be to find out what's happening with the input surfaces - as the email makes clear, they really should have triangle correspondence, so are likely to be flawed in some way.

Yes the two surfaces do have triangle correspondence except for the corpus callosum part. But the vertices located in corpus callosum have the same coordinates, so if I modify the triangles of corpus callosum, the two surfaces will be same, and the error will be solved.

tomfrankkirk commented 2 years ago

Ok, please let me know how you get on.

diaosilei commented 2 years ago

Ok, please let me know how you get on.

OK. But recently I got some work to do for the first. When I am done, I will sorting out my code, then give it to you by email or github whatever. Again, thanks for your time and help.

tomfrankkirk commented 2 years ago

Question from my contact - do you know when the surfaces were downloaded? They may be out of date, as the problem came to light last August.

diaosilei commented 2 years ago

As I remember, the data was downloaded last September. Was your contact Emma from KCL? I ask this because I received an email to ask me the same question.

diaosilei commented 2 years ago

Ok, please let me know how you get on. This is the script I used to modify the surfaces to the same. I also send this script to the Emma from KCL. modify_surface_error.zip

diaosilei commented 2 years ago

Question from my contact - do you know when the surfaces were downloaded? They may be out of date, as the problem came to light last August.

Thanks for your all help. I have solved my problem by modify the vertex ids of the white and pial surfaces consistent. If you get another question to ask me, please feel free to contact me by zhaoll2021@lzu.edu.cn.

tomfrankkirk commented 2 years ago

No not Emma - Sean Fitzgibbon, who is Oxford based for now.

Glad to hear its fixed. Good luck with the research and please do report any other issues you spot; I hope you find the software useful.