Skip to content

Resizing scale different from expected #225

Description

@AleximusOrloff

As I see in code, both src and dst sizes reduced by 1.
https://github.com/torch/image/blob/master/generic/image.c#L84
It could be due to Lua's 1-based sizes, but actually it means that image scaled by (dst-1)/(src-1)
It results in loosing half a pixel on each side

im=torch.Tensor(3,3):zero()
im[2][2]=1
print(im)
0 0 0
0 1 0
0 0 0
[torch.DoubleTensor of size 3x3]

im4=image.scale(im,6,6,'bilinear')
print(im4)
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.1600 0.3200 0.3200 0.1600 0.0000
0.0000 0.3200 0.6400 0.6400 0.3200 0.0000
0.0000 0.3200 0.6400 0.6400 0.3200 0.0000
0.0000 0.1600 0.3200 0.3200 0.1600 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[torch.DoubleTensor of size 6x6]
print(im4:sum())
5.7599997425079

s seen sum = 5.76, instead of expected 4
real scale ratio = 2.4 instead of 2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions