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

suggestion for transforms.Scale() #130

Closed
yanghuanflc opened this issue Mar 28, 2017 · 2 comments
Closed

suggestion for transforms.Scale() #130

yanghuanflc opened this issue Mar 28, 2017 · 2 comments

Comments

@yanghuanflc
Copy link
Contributor

yanghuanflc commented Mar 28, 2017

I suggest to modified transforms.Scale() to accept two type of size input:
1, If isinstance(self.size, int), resize the image short side to self.size
2. Else, resize the image each side according to self.size

The code looks like this:

class Scale(object):
    def __init__(self, size, interpolation=Image.BILINEAR):
        self.size = size
        self.interpolation = interpolation

    def __call__(self, img):
        if isinstance(self.size, int):
            w, h = img.size
            if (w <= h and w == self.size) or (h <= w and h == self.size):
                return img
            if w < h:
                ow = self.size
                oh = int(self.size * h / w)
                return img.resize((ow, oh), self.interpolation)
            else:
                oh = self.size
                ow = int(self.size * w / h)
                return img.resize((ow, oh), self.interpolation)
        else:
            return img.resize(self.size, self.interpolation)
@soumith
Copy link
Member

soumith commented Mar 28, 2017

Seems like a reasonable solution. Can you send a PR to do this? Thanks.

@yanghuanflc
Copy link
Contributor Author

PR #133

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

No branches or pull requests

2 participants