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

orthogonalize AP/PD src/sink edges #377

Merged
merged 7 commits into from
Feb 24, 2025
Merged

orthogonalize AP/PD src/sink edges #377

merged 7 commits into from
Feb 24, 2025

Conversation

jordandekraker
Copy link
Collaborator

This approach continues with the distance transform logic introduced by #371, and closes #373.

We want to ensure that all edge vertices are assigned to an AP or PD source or sink (4 possible labels), without overlapping or missing any vertices (I will call this orthogonal edge conditions). Otherwise we can end up with "corners" that are entire missing from the unfolded space, or other funny distortions in the unfolding.

Here, we introduce a new script to fix this up:

  • we move the application of signed distance transforms out of the laplace-beltrami solver rule and into its own rule, where we jointly solve AP and PD edges
  • instead of iteratively increasing distances to add vertices, we treat the distances as probabilities for one of these 4 labels and take the maxprob
  • in some cases we will still not have min_terminal_vertices>5. In these cases, we gradually increase the distance scaling factor from that label until min_terminal_vertices is reached.
  • we get to keep parallelization of laplace-betrami. AP and PD edges do have to be processed jointly though, to ensure they are orthogonal. We also get to toss out a bunch of complicated functions

we also now apply largest connected component to finding boundary vertices to prevent issues with holes

TODO:

  • we could still ensure conncomp in addition to min_terminal_vertices, but i don't think its necessary
  • parameter to adjust distance scaling factor stepsize?

@jordandekraker jordandekraker changed the title orthogonalize AP/PD srs/cink edges orthogonalize AP/PD src/sink edges Feb 18, 2025
@akhanf
Copy link
Member

akhanf commented Feb 19, 2025

nice, will give it a try!

@jordandekraker
Copy link
Collaborator Author

sorry still WIP - some formatting bugs to fix! hopefully push an update in a few hours

@jordandekraker
Copy link
Collaborator Author

should be working now, and I also managed to speed up the laplace-beltrami solver by replacing a for loop with a vectorized approach (I noticed from the logger that just setting the boundary conditions was taking a while)

Adds a check and raises an exception if any of src/sink is zero.
Also writes a proper label gifti (was missing the label table), and
refactored that in a write function. NOTE: still need to set the
structure label..
@akhanf
Copy link
Member

akhanf commented Feb 22, 2025

might need a bit more tweaks for robustness to ensure the counts are at least 1 vertex, as this fails now for the ds002168 dataset that I had working correctly before.. Haven't had a chance to look at that fix yet, but made some cosmetic changes just now..

@akhanf
Copy link
Member

akhanf commented Feb 24, 2025

OK just had a chance to look at this again for my failed test case (dentate for ds002168)

Looks like just needed more iterations than the capped 10.. I'll do a bit more clean-up then I thnk should be ready to merge.

@jordandekraker
Copy link
Collaborator Author

OK one thing I also just pushed: we can make the distance scaling additive rather than multiplicative in order to match what we were doing before with iterations of dilation
Either solution should be fine, but yeah we probably just need a few more iterations. I can't seem to wetrun test because there seems to be an issue with my nnunet conda env

@akhanf
Copy link
Member

akhanf commented Feb 24, 2025

Actually I still have an issue now with the resulting labels being multiple connected components, so may have to add in connected components for robustness..
Yes I actually had a nnunet issue when trying to run on the weekend too, and reusing my previous runs to avoid recomputing -- not sure if something changed there, could post an issue for @Dhananjhay to look into?

@Dhananjhay
Copy link
Collaborator

Dhananjhay commented Feb 24, 2025

Yes, I'm aware of the issue and I've been trying to debug it. We are using nunnet's official conda package and it's pinned in the env configuration file, i.e., hippunfold/workflow/envs/nnunet.yaml so I doubt it's something we changed. I wanted to cross check the issue by running the pipeline with --use-singularity flag but weirdly enough, I get this error everytime:

CreateCondaEnvironmentException:
Conda must be version 24.7.1 or later, found version 4.10.3. Please update conda to the latest version. Note that you can also install conda into the snakemake environment without modifying your main conda installation.

I'll open an issue.

- turns out the additive approach is better (looks like our commits
crossed, but we had the same implementation)..
- adds logs
- adds structure labels for workbench
@akhanf
Copy link
Member

akhanf commented Feb 24, 2025

OK this cleans things up a bit more and now is working well on my test dataset -- it needed the additive approach (I didn't see your commit until I was done, but looks like we did the same thing)..

I'll merge this in to move things along..

@akhanf akhanf merged commit cba5796 into dev-v2.0.0 Feb 24, 2025
6 checks passed
@akhanf akhanf deleted the LPedges branch February 24, 2025 19:43
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.

3 participants