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
Improve moco for interleaved data #2664
Conversation
e7051c7
to
569999d
Compare
Heads up, this might run into #2642. It doesn't edit |
569999d
to
5f30abe
Compare
You are right! I meant by "Tested on sub-glen." that all parts of code work and script finish without errors. I'll test/validate performance of this PR on some systemic data asap. |
ok let me know when the PR is at its final stage for me to review |
I have tested this PR on a synthetic 4D dummy interleaved data generated by create_test_data.py. Code how to generate synthetic interleaved 4D data:
|
what if you try to increase the amount of motion in your simulation? how much motion is there now? |
i've looked at the simulated data uploaded in #2664 (comment), motion is very small (sub-mm) in most of the middle slices: so i suggest you increase motion to be able to better validate the performance of your algorithm @valosekj also: i suggest you upload gif anim-- more convenient that downloading zip, opening fsleyes, etc. |
Generated image has 1mm isotropic resolution (or should have, because, to be precise - https://github.com/neuropoly/spinalcordtoolbox/blob/67c679deadd8af0c2eb7445041b0c61628d8bbfa/spinalcordtoolbox/testing/create_test_data.py#L217 Slice-wise shift is in range between 0.5-3mm (or again - unknown units?). Unfortunately now set as fixed value (I should change it to be input arg): (for context; middle slices have lower shift that outer ones due to polynomial function - see this image) I'll increase motion and will update gif, thanks 👍 |
that's not necessarily the case, e.g. with 2nd-order you could have largest shift in the middle (depending on how you define you constant 0-term offset) |
hm, currently, the order of polynomial is equal to number of slices ( Lower degree results into worse fit (i.e. slicewise regularized fit (orange) does not properly fit/simulate interleaved acquisition mode (blue dots)): |
@valosekj what exactly are the graphs #2664 (comment) supposed to represent? if the blue dots are the pixel shift in the Y direction across slices, for both odd and even slices, then why are you trying to fit both odd and even slices at the same time? shouldn't the simulated data be constructed by fitting one polynomial function to the odd slices, and another one to the even slices? |
Yes, blue dots represent the pixel shift in A-P (Y) direction across slices (S-I direction (Z)) for one certain volume from 4D dataset. For clarity, I added numbers to individual dots indicating slice numbers in figure below.
You mean something like is plotted in the figure below? Then, however, individual pixel shift (blue dots) have to vary for odd and even slices. Otherwise, the fit would be linear (a.). I plotted two scenarios of variation for odd and even slices: constant variation (b.) or random variation (controlled by a factor changing in some interval) (c.). |
I generated some dummy 4D interleaved data using two polynomials (one fitting even slices and another one fitting odd slices) based on the previous comment. Voxel shift/motion varies randomly in interval from 0.5 to 3.5 for all examples below. Higher order of polynomials causes larger variation in S-I direction. So, I think that slowly-varying changes in the B0 field are better captured by polynomials of lower order (e.g. 3rd). @jcohenadad what do you think? |
@valosekj i'm having hard time understanding the overall workflow. To me, the synthetic data could be made by:
So, i don't really see the need for "fitting" polynomial functions here. |
The current implementation of I implemented polynomial function only for interleaved option, but not globally for Instead of this, I can probably use |
👍
👍 |
@valosekj are you still working on that PR? |
@jcohenadad very sorry, when I worked on #2835 I somehow forgot to finish and merge this PR.
I am not sure now, if I should try to rebase this PR or start from scratch with moved scripts. |
the scripts only moved, so you should be able to resolve conflicts easily. What I would do (i know that's not the proper git way), would be to
@kousu @joshuacwnewton might have other/better advices |
Thanks, I have tried it but I have had troubles with unresolved conflicts and unsuccessful rebase. |
Closed due to out-of-date with master and unresolved conflicts. Replaced by #3172 |
Added
-interleaved
option tosct_dmri_moco.py
, if it is selected, newly created function inmoco.py
for splitting input data to even and odd datasets is called. This function splits data and callsmoco_wrapper
function two times, then merge datasets back together.This current solution is created to influence original code as least as possible and needs improvements.
I tried current workaround on testing data
sub-issue2637
with commands from http://forum.spinalcordmri.org/t/sct-dmri-moco-doesnt-seem-to-correct-motion/358/6 (average DWI, segment SC, create mask, run moco).Compare to results from original moco, I can see improvements in sagittal plane in slice-by-slice misalignment.
Fixes #2637