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 Resize transform #642

Merged
merged 2 commits into from
Sep 2, 2021
Merged

Add Resize transform #642

merged 2 commits into from
Sep 2, 2021

Conversation

fepegar
Copy link
Owner

@fepegar fepegar commented Sep 1, 2021

Resolves #45.
Related to #193, #205, #215.

Description
This transform is useful for situations in which we don't mind changing the aspect ratio of the object and want to keep the field of view constant. This happens often in computer vision applications. For example, I am using this transform on videos.

In [1]: !curl -o person.jpg https://thispersondoesnotexist.com/image
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  398k  100  398k    0     0  1726k      0 --:--:-- --:--:-- --:--:-- 1726k

In [4]: im = tio.ScalarImage('person.jpg')

In [5]: im.plot()

person

In [6]: im.shape
Out[6]: (3, 1024, 1024, 1)

In [7]: im = tio.Crop((100, 0, 0))(im)  # simulate a rectangular image

In [8]: im.shape
Out[8]: (3, 824, 1024, 1)

In [9]: im.plot()

person1

In [13]: resize = tio.Resize((224, 224, 1))

In [14]: resized = resize(im)

In [15]: resized.shape
Out[15]: (3, 224, 224, 1)

In [16]: resized.plot()

person2

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 Sep 1, 2021

Codecov Report

Merging #642 (2a9c091) into master (8eddf8a) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #642      +/-   ##
==========================================
+ Coverage   96.83%   96.86%   +0.02%     
==========================================
  Files         126      128       +2     
  Lines        6572     6627      +55     
==========================================
+ Hits         6364     6419      +55     
  Misses        208      208              
Impacted Files Coverage Δ
...io/transforms/preprocessing/spatial/crop_or_pad.py 96.49% <ø> (ø)
tests/transforms/preprocessing/test_resize.py 100.00% <100.00%> (ø)
tests/transforms/test_transforms.py 100.00% <100.00%> (ø)
torchio/transforms/__init__.py 100.00% <100.00%> (ø)
torchio/transforms/preprocessing/__init__.py 100.00% <100.00%> (ø)
torchio/transforms/preprocessing/spatial/resize.py 100.00% <100.00%> (ø)

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 8eddf8a...2a9c091. Read the comment docs.

@fepegar fepegar merged commit 860ded4 into master Sep 2, 2021
@fepegar fepegar deleted the add-resize branch September 2, 2021 09:48
@fepegar fepegar mentioned this pull request Oct 18, 2021
9 tasks
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.

Add Resize transform
1 participant