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

ants.motion_correction fails for micron-sized voxels #362

Open
poldrack opened this issue Apr 29, 2022 · 11 comments
Open

ants.motion_correction fails for micron-sized voxels #362

poldrack opened this issue Apr 29, 2022 · 11 comments

Comments

@poldrack
Copy link
Contributor

Describe the bug
ants.motion_correction() fails intermittently (over timepoints) on 2-photon imaging data with micron resolution when the resolution is correctly specified (either in microns or in millimeters). It works properly with the same data if the resolution is incorrectly specified as microns * 1000 (ie pretending that microns are actually millimeters). The failure varies from run to run with identical data, suggesting that it might be related to random initialization.

The problem is demonstrated here:

https://github.com/poldrack/brainsss/blob/main/ants_testing/MotionCorrectionIssue.ipynb

I'm happy to share the data if you'd like to use it for testing.

Expected behavior
I would expect the function to either automatically adapt to voxel size, or to raise an exception that the voxel size is out of bounds, with a suggestion for what command line parameters might be modified to fix the problem.

@ntustison
Copy link
Member

@poldrack --- I'll put this on my to-do list as well as the other issue. Currently trying to get an initial manuscript draft together and @stnava is also pretty busy at the moment. I'll first look to see if I can duplicate the behaviors in the core ANTs repository, since these issues should be addressed there as well, if necessary. However, if you've already done that, please let us know what you found.

@poldrack
Copy link
Contributor Author

I'll try running the same analyses using ANTs binaries and see if the same problems occur - lmk if you'd like me to post those results to the core ANTs repo or just continue the discussion here...

@ntustison
Copy link
Member

We can just continue the conversation here.

@poldrack
Copy link
Contributor Author

I had a quick pass at it and TBH the command line version is just not something I have time to make work right now - just way too complex without sufficiently clear documentation. happy to share the data if y'all want to try it out.

@cookpa
Copy link
Member

cookpa commented Apr 29, 2022

Sure, I'll take a look at a sample data set

@poldrack
Copy link
Contributor Author

great, email me at poldrack@gmail.com and I'll send a link

@ntustison
Copy link
Member

No worries, @poldrack and thanks, @cookpa . If you don't get to it by this weekend (as well as the registration dimensionality issue), I'll be sure to take a look.

@cookpa
Copy link
Member

cookpa commented Apr 29, 2022

antsMotionCorr does not run at all with the "size-mm_units-mm" files:

$ antsMotionCorr -d 3 -u 1 --use-histogram-matching 0 -m MI[ ants_example_data/series-tdtomato_size-mm_units-mm_mean.nii , ants_example_data/series-tdtomato_size-mm_units-mm.nii , 1, 32, Regular, 1 ] -t Rigid[ 0.1 ] -f 1x1 -s 1x0 -i 50x50 -o [ series-tdtomato_size-mm_units-mm_moco, series-tdtomato_size-mm_units-mm_mocoWarped.nii.gz ] --verbose
 verbose 
Registration using 1 total stages.

Stage 1
  fixed image: ants_example_data/series-tdtomato_size-mm_units-mm_mean.nii
  moving image: ants_example_data/series-tdtomato_size-mm_units-mm.nii
  number of levels = 2
  shrink factors per level: [1, 1]
  smoothing sigmas per level: [1, 0]
  using fixed reference image for all frames 
  use histogram matching 0
  regular sampling (percentage = 1)
  using the Mattes MI metric.

*** Running rigid registration ***0

Exception caught: 
itk::ExceptionObject (0x7fa779d11ad0)
Location: "unknown" 
File: /Users/pcook/tmp/NOT_BACKED_UP/antsMaster/build/staging/include/ITK-5.3/itkMattesMutualInformationImageToImageMetricv4.hxx
Line: 311
Description: ITK ERROR: MattesMutualInformationImageToImageMetricv4(0x7fa77b9ce650): All samples map outside moving image buffer. The images do not sufficiently overlap. They need to be initialized to have more overlap before this metric will work. For instance, you can align the image centers by translation.

I reproduced the error after converting the nii files to mha with c3d / c4d. So I think it's not related to the ITK NIFTI I/O issues for small voxels that we've discussed on the ANTs page.

But after replacing mm units with um in the MHA header, it runs. Likewise, using the "ants_example_data/series-tdtomato_size-um_units-mm" images in the above command runs as well.

@ntustison
Copy link
Member

My guess is that it's the gradient scale estimator. @poldrack , is it okay if @cookpa cc's me on the link to the data?

@cookpa
Copy link
Member

cookpa commented May 2, 2022

@ntustison Russ said I could share it, will forward you the link.

@poldrack
Copy link
Contributor Author

poldrack commented Oct 11, 2022 via email

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

No branches or pull requests

3 participants