-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Update transforms.py #213
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
Update transforms.py #213
Conversation
Adding different types of padding: symmetric, edge, reflect
alykhantejani
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left some inline comments, as a general comment though - do we want to add separate transforms for these (MirrorPad, SymetricPad etc.)?
| assert (type in ["constant","edge","symmetric","reflect"]) | ||
| self.type = type | ||
|
|
||
| def __expand_reflect(slef,image, border=0): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| assert isinstance(fill, numbers.Number) or isinstance(fill, str) or isinstance(fill, tuple) | ||
| self.padding = padding | ||
| self.fill = fill | ||
| assert (type in ["constant","edge","symmetric","reflect"]) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| scale = Scale(self.size, interpolation=self.interpolation) | ||
| crop = CenterCrop(self.size) | ||
| return crop(scale(img)) | ||
|
|
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| import types | ||
| import collections | ||
|
|
||
| import functools |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| """ | ||
|
|
||
| def __init__(self, padding, fill=0): | ||
| def __init__(self, padding, fill=0,type="constant"): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
Also, we should add some tests for these new pad variants. |
fmassa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and sorry for the delay in replying.
I agree with @alykhantejani comments, and also made some more. Could you look into addressing those issues?
| :return: An image. | ||
| """ | ||
| img = np.asarray(image) | ||
| img = np.pad(img, pad_width=border, mode="reflect") |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| """ | ||
| img = np.asarray(image) | ||
| img = np.pad(img, pad_width=border, mode="reflect") | ||
| return Image.fromarray(np.uint8(img)) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| return ImageOps.expand(img, border=self.padding, fill=self.fill) | ||
| if self.type == "constant": | ||
| return ImageOps.expand(img, border=self.padding, fill=self.fill) | ||
| elif self.type == "symmetric": |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
Superseded by #460 |
Adding different types of padding: symmetric, edge, reflect