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

New label transformations #402

Merged
merged 7 commits into from
Dec 29, 2020
Merged

New label transformations #402

merged 7 commits into from
Dec 29, 2020

Conversation

efirdc
Copy link
Contributor

@efirdc efirdc commented Dec 28, 2020

Implements #400.

Description
This implements new label transformations RemapLabels, SequentialLabels, RemoveLabels. Documentation and basic tests are included as well. Please let me know if anything should be improved or changed.

Some extra methods were added to TorchioTestCase for easier testing of these new transformations.

  • get_subject_with_labels(self, labels): returns a subject with a LabelMap which has the desired set of labels.
  • get_unique_labels(self, label_map): returns the set of unique labels in a LabelMap, not including 0.

A small fix to Subject.apply_inverse_transform. Just applied .clear_history() to the subject after the inverse transformation.

Moved everything related to TypeBounds, and TypeMaskingMethod up to the Transform class so they can be reused in the label transformations.

Demonstration

Original labels:

Apply tio.RemoveLabels([1, 2, 17, 23, 24])

Apply tio.RemapLabels({4:3, 6:5, 10:9, 20:19, 22:21}, masking_method="Right")

Apply tio.SequentialLabels()

Apply subject = subject.apply_inverse_transform()

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 Dec 28, 2020

Codecov Report

Merging #402 (4c1be6e) into master (b9ac52d) will decrease coverage by 0.14%.
The diff coverage is 87.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #402      +/-   ##
==========================================
- Coverage   92.42%   92.28%   -0.15%     
==========================================
  Files         117      124       +7     
  Lines        5942     6103     +161     
==========================================
+ Hits         5492     5632     +140     
- Misses        450      471      +21     
Impacted Files Coverage Δ
torchio/transforms/augmentation/composition.py 89.02% <50.00%> (+1.37%) ⬆️
torchio/transforms/transform.py 86.12% <70.00%> (-7.89%) ⬇️
tests/utils.py 95.72% <93.33%> (-0.40%) ⬇️
tests/transforms/label/test_remap_labels.py 100.00% <100.00%> (ø)
tests/transforms/label/test_remove_labels.py 100.00% <100.00%> (ø)
tests/transforms/label/test_sequential_labels.py 100.00% <100.00%> (ø)
tests/transforms/test_transforms.py 100.00% <100.00%> (ø)
torchio/data/subject.py 96.15% <100.00%> (+1.62%) ⬆️
torchio/transforms/__init__.py 100.00% <100.00%> (ø)
torchio/transforms/preprocessing/__init__.py 100.00% <100.00%> (ø)
... and 15 more

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 b9ac52d...4c1be6e. Read the comment docs.

Copy link
Owner

@fepegar fepegar left a comment

Choose a reason for hiding this comment

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

Nice! I really appreciate the effort into the docs and the examples.

Why did you move the bounds stuff into Transform? I haven't seen it in the new transforms.

@efirdc
Copy link
Contributor Author

efirdc commented Dec 29, 2020

No worries, glad to contribute.

The bounds code was moved to Transform so that TypeBounds can be supported as a masking method. You can see where that happens on line 402 of transform.py

@fepegar
Copy link
Owner

fepegar commented Dec 29, 2020

Ok, thanks. I've added some minor edits, will squash and merge once the tests are done.

tests/utils.py Show resolved Hide resolved
@fepegar fepegar merged commit 6aebda0 into fepegar:master Dec 29, 2020
@fepegar
Copy link
Owner

fepegar commented Dec 29, 2020

Available in v0.18.13. Thanks again for your contribution!

@efirdc
Copy link
Contributor Author

efirdc commented Dec 29, 2020

Great! Thanks for your edits and continued support of this project.

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.

None yet

2 participants