Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic EEG localization and labelling using Revopoint 3D #716

Open
wants to merge 130 commits into
base: master
Choose a base branch
from

Conversation

chinmaychinara91
Copy link
Collaborator

@chinmaychinara91 chinmaychinara91 commented Jun 28, 2024

Tutorial: https://neuroimage.usc.edu/brainstorm/Tutorials/TutDigitize3dScanner#Digitize_using_Revopoint_Digitize_GUI_in_Brainstorm

Test Data: Can be downloaded from here.

Goal is to allow automatic localization and labelling of EEG caps using 3D scanned mesh of a person wearing the cap (captured using Revopoint 3D). This represents a new low-cost, fast, easy-to-use approach for digitizing heads and electrodes as compared to the traditional digitizer.

NOTE: Currently tested well with two configurations of EEG caps: d40c719 c49ebc6

Proposed GUI within Brainstorm
LEGACY MODE
Screenshot 2024-09-27 113338

2024 MODE
Screenshot 2024-09-27 113125

  • Load OBJ file into brainstorm (mesh with vertices, faces and color)
  • Add color field to brainstorm surface structure
  • Color should be updated when mesh downsampled in BST as well
  • Refactor the Digitize menu to add Revopoint
  • Refactor the Digitizer GUI for Revopoint tasks
  • Menu to load default available caps in BST as Montages in Revopoint GUI
  • Handle surface color update for Views menu option on 3D figure (Clone figure, etc.)
  • Test nothing breaks for the already available Digitizer functionalities:
    • Simulation mode
    • With Polhemus connected
  • 19th Aug 2024: Make it work on both the "legacy" and 2024 Digitize panel (New Digitize panel #682)

@tmedani @ajoshiusc @yashvakilna

…llar/toolbox)

required for warping and interpolating points on EEG cap
- it is always going to be a meshed OBJ so 'FileType' parameter is unnecessary
- renamed 'tri' as 'faces'
- renamed 'pos' as 'vertices'
- ANT 65 is a modeifed version of ANT Waveguard 64
- Acticap 66 is a modified version of Acticap 65
to be used for registration to MRI
Needs work on a more generic approach to handle different EEG caps
- Limit display of 'Auto' and 'Random' buttons for Revopoint only
- Correct display order of EEG labels based on the initialization labels required as per the EEG cap
- Removed unwanted code for sketch points (was used for debugging)
- Creating montages from EEG cap layout mat files (only for Revopoint)
@chinmaychinara91 chinmaychinara91 marked this pull request as ready for review July 22, 2024 22:27
@chinmaychinara91
Copy link
Collaborator Author

chinmaychinara91 commented Sep 24, 2024

@rcassani

I have made all the changes based on the comments and discussions above and on Slack. Let me know if you find any errors on your side.

To summarize:

  1. User can now just right click on the imported texture surface > Digitize (3D Scanner) to start the digitization.
  2. Regarding There is not a clear workflow for the case where the subject has its own anatomy,
    the user can right click on the subject > Import surfaces and import the textured surface. Then right click on the imported textured surface > Digitize (3D Scanner) to start the digitization. follow step 1 above.
  3. User now gets to choose what to do when starting 3D Scanner digitization (Use existing surface or Add a new surface).
  4. Better way of sampling without having to use reducepath.
  5. auto_3dscanner now handles all the automatic detection and labelling of 3D Scanner acquired mesh. For new caps, we just need to change the getEegCapLandmarkLabels function and that should be it.
  6. Did some rigorous testing and was able to come up with a single range for imfindcircles with the caps we have available. Check 3403c9e.
  7. Updated the cap templates for Colin27 and ICBM152. Check c49ebc6.
  8. The textured surface in database is updated with Digitize.Transf transformation once the fiducials are digitized.
  9. Had forgot about this https://forum.revopoint3d.com/t/revopoint-generated-mesh-coordinate-system/25662. The Revopoint vertices are in 'mm'. Did some digging here https://www.fieldtriptoolbox.org/tutorial/electrode/ and I think we need this approach b1124bf if we want to support any generic head surface acquired through other devices. Check 06df252 cedc8af (fieldtrip dependency removed).
  10. Needed to do some ordering changes in the way the initialization points were captured for scalability. Updated the tutorial with the instructions.
  11. For 86e8d83, the data to test with can be found in the Test data link in description.
  • ft_obj: test data provided by fieldtrip here
  • 3d_software_obj: random freely available head scans online

Tutorial updated partially. Should be good for your testing. Will do a final update of tutorial after it is ready to merge.

@chinmaychinara91 chinmaychinara91 marked this pull request as ready for review September 24, 2024 21:41
- updated the code reference from where this was inspired
- for some obj, obtained from 3D software like Maya and Blender, when parsed using  'readtable', the vertex coordinates start from the 3rd column
- `refine` is a FT function to improve resolution. Using this creates a processing and loading delay which can be avoided as the scans would already be in a good resolution.
@chinmaychinara91
Copy link
Collaborator Author

chinmaychinara91 commented Sep 25, 2024

For importing an OBJ into brainstorm:

  1. The in_tess_wftobj function in actually a slightly modified submodule of https://www.fieldtriptoolbox.org/reference/fileio/ft_read_headshape. Should we use the fieldtrip function directly or since the license allows us, just continue to do it as it is right now (and just put a reference to the fieldtrip function).
  2. We also use the https://www.fieldtriptoolbox.org/reference/forward/ft_convert_units function to determine the units of the vertices based on the shape of the head. This is a good function to have.

Both these functions are available as part of spm12 plugin (/external/fieldtrip) and also the fieldtrip plugin. How do we go about this ?

@tmedani

@rcassani
Copy link
Member

In short, it does not makes too much sense to request the user to install FieldTrip as plugin and Load it to perform trivial operations and things that already in the Brainstorm source code. Moreover, not all functions in FieldTrip are available in the compiled version of Brainstorm.


  1. The in_tess_wftobj function in actually a slightly modified submodule of https://www.fieldtriptoolbox.org/reference/fileio/ft_read_headshape. Should we use the fieldtrip function directly or since the license allows us, just continue to do it as it is right now (and just put a reference to the fieldtrip function).
  • The waveform .obj files are simple text files that can be parsed quickly, take a look to a Brainstorm function such as in_tess_off.m. Do you have any trouble reading this format of file? Do we want to install full FieldTrip for this?
  1. We also use the https://www.fieldtriptoolbox.org/reference/forward/ft_convert_units function to determine the units of the vertices based on the shape of the head. This is a good function to have.
  • Same thing as the point above. Do we want to install full FieldTrip for this?

  • A conversion of surface from Brainstorm > FieldTrip > Brainstorm would be needed.

  • Choosing the right scaling for distance units is shown in the Brainstorm tutorials. This is done with a function that is already in Brainstorm, channel_fixunits

@chinmaychinara91
Copy link
Collaborator Author

chinmaychinara91 commented Sep 25, 2024

@rcassani thanks for pointing out the resources. That makes things much simpler. I don't think we will need FT now.

@chinmaychinara91 chinmaychinara91 marked this pull request as draft October 9, 2024 03:48
@chinmaychinara91 chinmaychinara91 marked this pull request as ready for review October 10, 2024 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants