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

Native surfaces and unfolded registration refactoring #345

Open
wants to merge 28 commits into
base: dev-v2.0.0
Choose a base branch
from

Conversation

akhanf
Copy link
Member

@akhanf akhanf commented Jan 8, 2025

Major updates here are:

native surface reconstruction

  • this method is much improved by using a different nan-masking strategy:
    • previously the nan mask was created from the non-GM voxels, but now, we specifically set the src/sink PD and AP labels to be nans (ie where we want the midthickness surface to terminate), and ensure the IO src/sink are labelled on a continuum with the coords (e.g. 0 src, 0-1 coords, 1.1 sink)
    • setting the sink to 1.1 now introduces a false boundary where the src and sink meet in the background, so we look for this boundary (getting adjacent labels using morphological operations) and set it to nan as well
  • we can't quite do this for the dentate just yet since we don't have labels defined for the analogous AP/PD src/sink regions, but this could be done using similar label adjacency rules I think (in another PR)
  • this is now the default and only method for surface generation
  • a new spec file has been created that contains the corobl native surfaces

surface-based atlases

  • transition to gifti-only atlases, where it includes the unfold surf.gii for unfold resampling, metrics for unfoldreg, and labels for propagating subfields
  • bbhist is generated anew by running this branch on bigbrain manual segmentations (still need to make one more update there to the subfields label gii)
  • multihist7 had legacy atlas files converted over to gifti using a snakefile (packaged in the zip, and also in the atlas-v2 folder)
  • other atlases are not supported right now

unfolded registration

  • is now used to warp subject native unfold mesh vertices to atlas native in 2d space, so they can be used for wb_command resampling
  • metrics used for registration are defined in the atlas
  • fixed/moving have been swapped, since we only really require one direction, so this makes it so the forward warp is required, instead of the inverse (doesn't matter for ANTS SyN, but this is helpful for greedy)
  • ANTS and greedy both implemented, but greedy used by default - the CC metric is generally better than NMI for deformable registration, and is likely the reason that the ANTS registraiton is not really warping that much..
  • padding is added, both to ensure the deformation field doesn't wrap, and for vertices that might lie outside - also future proofing for when we apply post-processing (eg heavy smoothing) on the unfold meshes
  • unfold surfaces are squashed to a plane (different plane for inner, mid, outer), so that surface to volume resampling doesn't contain wiggly volumes (or empty regions)
  • a new script for converting from 2d to 3d warps has been created (makes a itk 3d transform)
  • wb_command is used to transform the surf.gii

other updates

  • uses updated hippunfold_deps container (that is on docker hub, but still not merged into main there) - this includes updated workbench and ants (ants just needed an upgrade because the old binary release zip we were using was no longer available)..
  • create_warps.py has been updated to remove creation of the inverse warps
  • any rules for making transforms that are no longer used are just removed
  • the transforms have been left out of the final target files too, since they aren't really needed after surfaces are generated
  • the old workflow rules for unfolded registration have been taken out of gifti.smk and moved to a moved over to unfoldreg_v1.smk (which is not actually imported now - could be removed entirely perhaps)

Maybe TODO here (if not then in another PR):

  • config parameters for native_surf are at the top of the file currently, should move these to the config..
  • curvature maps could have a random sign flip (this happens in the bbhist atlas) - we should try to deal with this, maybe by detecting it and flipping normals (I haven't confirmed that flipping normals corrects this, but I would think it should..) - unfolded registration to the current bbhist might be suboptimal until that is corrected (can't recall if the CC metric cares about neg vs pos correlation..)

Things to do later in another PR

  • create CLI option for generating atlas data -- would need to have a new pybids input for the subfield manual segmentation - might want to rename the existing manualseg input to indicate that is for tissue seg..
  • split native_surf snakemake for readability - dividers are present in the file to suggest splits (in another PR we could reorganize rule files in general, maybe adding subfolders)..
  • dentate surface generation isn't working yet, needs to be addressed fully in another PR (generating the midthickness, and also defining PD src/sink heuristically)
  • unfold surfaces could be further postprocessed (some additional rules have been created but are not in use yet - had some issues with stubborn outlier vertices in the bbhist native->unfold reconstructed surfaces)
  • we still make use of the legacy standard densities, but would be good to generate new standard densities instead
  • once we have the new dev version of workbench, we can put all the data into a single cifti file and single spec file

TODO:
  - make alternative script for volumetric subfield labelling that
uses label_gifti intstead of label_nifti
  - the volumetric targets are all turned off for now until that is
done, since the cropref space relies on the subfields
  - add some smoothing for native surfaces (maybe another PR)
  - verify that the unfoldreg warping is being performed properly
(compare with images, or make a toy example)
     - try with a single subject atlas, where the atlas is defined on
it's own unfolded tesselation instead of unfoldiso - could make some
target rules to generate the files for this (e.g. the subject metrics
in unfold 2d slice, along with native and unfold meshes)
- only one atlas from CLI instead of multiples (was using atlas[0] some
places)
- remove final transforms (not used with nativesurf workflow)
- giftis only for atlas (needs updated multihist7 files - workflow to
generate these in resources/atlas-v2 for now)
- use unfoldedreg when the atlas has the metrics
   - option for dentate-based unfoldreg too (unused right now)

TODO:
 - update atlas files (use another location for testing)
 - check unfoldreg warps
 - make nativesurf the default
major fix for isosurfaces as was using wrong labels for nan (all
background) when I should instead be useing the src/sink for the other
coords (AP/PD). Also sets the sink label to 1.1 to eliminate the false
boundary, and then also use nans to ignore the false boundary thats
created where src and sink meet..

THis now produces hipp surfaces with no holes!
now produces nice sulcal/gyral maps with curvature
also testing out new hippunfold_deps container..
currently naming is as space-corobl, with no density wildcard.. could
consider adding den-native..
- greedy used as default unfoldreg method for now
- warping verified to be correct using some synthetic data locally
  (still unsure why the y-flip is needed when creating the itk warp, but
oh well)
- added containers for all rules
TODO: upload bbhist atlas prototype
- adds quotes around url to avoid issues with special characters
- note: bbhist linked here is a WIP (ie subfields gifti has some holes,
need to dilate labels into bg before sampling from native surf)
NOTE: multihist7 uses the legacy metric files (converted from previous
nifti to gifti, using the Snakefile in the zip), and ultimately should
be replaced by native giftis by running hippunfold v2 on those datasets
(once we have multi-atlas support)
also adds a dryrun test (since this was in github actions tests already)
@akhanf akhanf requested a review from jordandekraker January 8, 2025 19:30
akhanf added 2 commits January 8, 2025 14:44
we don't yet actually check to see if metrics exist before trying to run
unfolded reg
@akhanf akhanf marked this pull request as ready for review January 9, 2025 04:09
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.

1 participant