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

Add polynomial function to dummy_segmentation #2684

Merged
merged 5 commits into from May 14, 2020

Conversation

valosekj
Copy link
Member

@valosekj valosekj commented May 2, 2020

This PR aims to address #2678 (creation of synthetic interleaved DWI data).
So far, I added polynomial function to dummy_segmentation to simulate slicewise motion:
Snímek obrazovky 2020-05-02 v 11 11 59

TODO:

  • allow creation of 4D dataset - possible solution: create function which will call dummy_segmentation n-times with various factor of polynomial function and then merge individual 3D data into 4D dataset

@valosekj
Copy link
Member Author

valosekj commented May 8, 2020

dummy_4d function allows to create 4D data with different slicewise shift across individual volumes and can be tested for example by following code:

from spinalcordtoolbox.testing.create_test_data import dummy_4d
DEBUG = True  # Set to True to save 4D nii image
seg_4D = dummy_4d(vol_num=10, size_arr=(64, 64, 20), pixdim=(1,1,1),radius_RL=13.0,
 radius_AP=5.0, shape='ellipse', interleaved=True, debug=DEBUG)


# Loop across individual volumes of 4D data
for volume in range(0,vol_num):
factor = uniform(0.5, 3.0) # shift in voxels
Copy link
Member Author

@valosekj valosekj May 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This factor could probably take into account breath frequency and repetition time in some way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could, but i would not worry too much (as TR can also vary by several seconds)

@jcohenadad jcohenadad self-requested a review May 9, 2020 01:21
Copy link
Member

@jcohenadad jcohenadad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

z = np.arange(0, nz)
p = poly1d(polyfit(z, y, deg=nz))
# loop across slices and add object
for iz in range(nz):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code duplication with lines 138-142. you could create a nested function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code slightly differs in second parentheses. Isn't current workaround better for clarity than nested function?

@valosekj
Copy link
Member Author

I generated some dummy 4D data with proposed dummy_segmentation_4d using following commands:

from spinalcordtoolbox.testing.create_test_data import dummy_segmentation_4d
DEBUG = True  # Set to True to save 4D nii image
seg_4D = dummy_segmentation_4d(vol_num=10, size_arr=(64, 64, 49), pixdim=(1,1,1),radius_RL=13.0,
 radius_AP=5.0, shape='ellipse', interleaved=True, debug=DEBUG)

Whole 4D data looks:

dummy_interleaved_4d

Slice-wise shift is noticeable mainly at beginning and end of SI axis. This corresponds with polynomial function fit visualization for one volume:

figure_1

So, my question is - is this fit suitable? Or should it be modified to better fit middle points/slices?

I also tried to run sct_dmri_moco with interleaved option (#2664) on this dummy data. Output image is same as input, so I have to do some investigation why.

@jcohenadad
Copy link
Member

awesome work @valosekj 🚀 yes, i think these simulated motions are fairly realistic (in terms of amplitude and location). In any case, this gives us a solid basis for improving the realism in the future (could be dedicated to another PR).

@valosekj valosekj marked this pull request as ready for review May 13, 2020 19:55
@valosekj valosekj linked an issue May 13, 2020 that may be closed by this pull request
@jcohenadad jcohenadad merged commit 5aff01e into master May 14, 2020
@jcohenadad jcohenadad deleted the jv/2678-interleaved-synthetic-data branch May 14, 2020 01:28
@jcohenadad jcohenadad added the tests context: unit, integration, or functional tests label Jun 11, 2020
@jcohenadad jcohenadad added this to the 4.3 milestone Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests context: unit, integration, or functional tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate interleaved DWI synthetic data
2 participants