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 kwarg to not check spatial consistency #735

Merged
merged 1 commit into from
Nov 11, 2021

Conversation

fepegar
Copy link
Owner

@fepegar fepegar commented Nov 11, 2021

Related to #734.

Description
The new kwarg allows to avoid checks for spatial consistency across images within a subject. This is useful when we are certain that the images are in the same physical space but different voxel space or different orientation. See the @Spenhouet's issue for more information:

The recommended usage in this case is

RandomAffine(center='origin', check_shape=False)

Checklist

  • I have read the CONTRIBUTING docs and have a developer setup (especially important are pre-commitand pytest)
  • Non-breaking change (would not break existing functionality)
  • Breaking change (would cause existing functionality to change)
  • Tests added or modified to cover the changes
  • Integration tests passed locally by running pytest
  • In-line docstrings updated
  • Documentation updated, tested running make html inside the docs/ folder
  • This pull request is ready to be reviewed
  • If the PR is ready and there are multiple commits, I have squashed them and force-pushed

@codecov
Copy link

codecov bot commented Nov 11, 2021

Codecov Report

Merging #735 (16c0722) into main (b28cdc0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #735   +/-   ##
=======================================
  Coverage   93.80%   93.80%           
=======================================
  Files          72       72           
  Lines        4440     4442    +2     
=======================================
+ Hits         4165     4167    +2     
  Misses        275      275           
Impacted Files Coverage Δ
...o/transforms/augmentation/spatial/random_affine.py 96.34% <100.00%> (+0.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b28cdc0...16c0722. Read the comment docs.

@fepegar
Copy link
Owner Author

fepegar commented Nov 11, 2021

@Spenhouet could you please take a look? I used this code on your data and it worked fine:

from pathlib import Path
import torchio as tio

ims_dir = Path('/tmp/example_images')
subject = tio.Subject(
    im=tio.ScalarImage(ims_dir / 't1.nii.gz'),
    lm=tio.LabelMap(ims_dir / 'thalamic_reorient.nrrd'),
)
transform = tio.RandomAffine(center='origin', check_shape=False)
transformed_subject = transform(subject)
transformed_subject.im.save('/tmp/t1_tr.nii.gz')
transformed_subject.lm.save('/tmp/t1_thalamus_seg.nii.gz')

thalamic_reorient.nrrd is the thalamus label map reoriented into some random orientation, to make sure the transform is robust to different orientations.

@Spenhouet
Copy link

@fepegar I tested it with more labels with different resolution and shape.
It works nicely! Thanks a lot!

@fepegar fepegar merged commit e13a60e into main Nov 11, 2021
@fepegar fepegar deleted the 734-add-kwarg-affine-check-shape branch November 11, 2021 17:43
@fepegar
Copy link
Owner Author

fepegar commented Nov 11, 2021

No worries! Do you mind if I add you to the list of contributors?

@fepegar
Copy link
Owner Author

fepegar commented Nov 11, 2021

I'll take the upvote as a yes!

@all-contributors please add @Spenhouet for ideas

@allcontributors
Copy link
Contributor

@fepegar

I've put up a pull request to add @Spenhouet! 🎉

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.

2 participants