Skip to content

Update functional.py #1323

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

Closed
wants to merge 1 commit into from
Closed

Update functional.py #1323

wants to merge 1 commit into from

Conversation

DonghweeYoon
Copy link

Correct the documentation
i is the y_coordinate, j is the x_coordinate

Correct the documentation
i is the y_coordinate, j is the x_coordinate
@codecov-io
Copy link

codecov-io commented Sep 11, 2019

Codecov Report

Merging #1323 into master will decrease coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1323      +/-   ##
==========================================
- Coverage   65.85%   65.82%   -0.04%     
==========================================
  Files          75       75              
  Lines        5782     5782              
  Branches      884      884              
==========================================
- Hits         3808     3806       -2     
  Misses       1710     1710              
- Partials      264      266       +2
Impacted Files Coverage Δ
torchvision/transforms/functional.py 71.09% <ø> (-0.29%) ⬇️
torchvision/transforms/transforms.py 80.94% <0%> (-0.2%) ⬇️

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 a91fe72...cf5a1d2. Read the comment docs.

@pmeier
Copy link
Collaborator

pmeier commented Sep 11, 2019

Actually, the current comment is correct. I'll try to explain:

The variable i describes the vertical or y direction and j the horizontal or x direction. You can deduce this from the fact that i is added to the height h, which would make no sense if i would represent a horizontal coordinate.

return img.crop((j, i, j + w, i + h))

The same is of course true for j.

From the pillow documentation for Image.crop()

box – The crop rectangle, as a (left, upper, right, lower)-tuple

Thus, our call is indeed correct since j is the left part and i the upper part in

i (int): i in (i,j) i.e coordinates of the upper left corner.
j (int): j in (i,j) i.e coordinates of the upper left corner.


However, I agree that the current documentation does not reflect this well. We should update it to avoid any misunderstandings in the future.

@DonghweeYoon
Copy link
Author

DonghweeYoon commented Sep 11, 2019 via email

@fmassa
Copy link
Member

fmassa commented Sep 11, 2019

One of the problems here is that Pillow uses a different convention than PyTorch for representing the sizes, (width, height instead of height, width), and this can bring some confusion.

We decided to keep the PyTorch convention, where we represent it as height, width, and thus the indices are passed as y, x (in plane coordinates), which are also represented as i, j.

If those indexing conventions are a bit confusing, check the numpy.meshgrid documentation for the indexing argument, which explains this in a bit more detail.

Can you update the PR to make the description a bit more clear?

@fmassa
Copy link
Member

fmassa commented Sep 30, 2019

Superseeded by #1388

@fmassa fmassa closed this Sep 30, 2019
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.

4 participants