Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
a129b6b8
Commit
a129b6b8
authored
Sep 11, 2019
by
Philip Meier
Committed by
Francisco Massa
Sep 11, 2019
Browse files
Adds optional fill colour to rotate (#1280)
* Adds optional fill colour to rotate * bug fix
parent
a91fe722
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+7
-2
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+5
-2
No files found.
torchvision/transforms/functional.py
View file @
a129b6b8
...
@@ -686,7 +686,7 @@ def adjust_gamma(img, gamma, gain=1):
...
@@ -686,7 +686,7 @@ def adjust_gamma(img, gamma, gain=1):
return
img
return
img
def
rotate
(
img
,
angle
,
resample
=
False
,
expand
=
False
,
center
=
None
):
def
rotate
(
img
,
angle
,
resample
=
False
,
expand
=
False
,
center
=
None
,
fill
=
0
):
"""Rotate the image by angle.
"""Rotate the image by angle.
...
@@ -703,6 +703,8 @@ def rotate(img, angle, resample=False, expand=False, center=None):
...
@@ -703,6 +703,8 @@ def rotate(img, angle, resample=False, expand=False, center=None):
center (2-tuple, optional): Optional center of rotation.
center (2-tuple, optional): Optional center of rotation.
Origin is the upper left corner.
Origin is the upper left corner.
Default is the center of the image.
Default is the center of the image.
fill (3-tuple or int): RGB pixel fill value for area outside the rotated image.
If int, it is used for all channels respectively.
.. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters
.. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters
...
@@ -711,7 +713,10 @@ def rotate(img, angle, resample=False, expand=False, center=None):
...
@@ -711,7 +713,10 @@ def rotate(img, angle, resample=False, expand=False, center=None):
if
not
_is_pil_image
(
img
):
if
not
_is_pil_image
(
img
):
raise
TypeError
(
'img should be PIL Image. Got {}'
.
format
(
type
(
img
)))
raise
TypeError
(
'img should be PIL Image. Got {}'
.
format
(
type
(
img
)))
return
img
.
rotate
(
angle
,
resample
,
expand
,
center
)
if
isinstance
(
fill
,
int
):
fill
=
tuple
([
fill
]
*
3
)
return
img
.
rotate
(
angle
,
resample
,
expand
,
center
,
fillcolor
=
fill
)
def
_get_inverse_affine_matrix
(
center
,
angle
,
translate
,
scale
,
shear
):
def
_get_inverse_affine_matrix
(
center
,
angle
,
translate
,
scale
,
shear
):
...
...
torchvision/transforms/transforms.py
View file @
a129b6b8
...
@@ -946,12 +946,14 @@ class RandomRotation(object):
...
@@ -946,12 +946,14 @@ class RandomRotation(object):
center (2-tuple, optional): Optional center of rotation.
center (2-tuple, optional): Optional center of rotation.
Origin is the upper left corner.
Origin is the upper left corner.
Default is the center of the image.
Default is the center of the image.
fill (3-tuple or int): RGB pixel fill value for area outside the rotated image.
If int, it is used for all channels respectively.
.. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters
.. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters
"""
"""
def
__init__
(
self
,
degrees
,
resample
=
False
,
expand
=
False
,
center
=
None
):
def
__init__
(
self
,
degrees
,
resample
=
False
,
expand
=
False
,
center
=
None
,
fill
=
0
):
if
isinstance
(
degrees
,
numbers
.
Number
):
if
isinstance
(
degrees
,
numbers
.
Number
):
if
degrees
<
0
:
if
degrees
<
0
:
raise
ValueError
(
"If degrees is a single number, it must be positive."
)
raise
ValueError
(
"If degrees is a single number, it must be positive."
)
...
@@ -964,6 +966,7 @@ class RandomRotation(object):
...
@@ -964,6 +966,7 @@ class RandomRotation(object):
self
.
resample
=
resample
self
.
resample
=
resample
self
.
expand
=
expand
self
.
expand
=
expand
self
.
center
=
center
self
.
center
=
center
self
.
fill
=
fill
@
staticmethod
@
staticmethod
def
get_params
(
degrees
):
def
get_params
(
degrees
):
...
@@ -987,7 +990,7 @@ class RandomRotation(object):
...
@@ -987,7 +990,7 @@ class RandomRotation(object):
angle
=
self
.
get_params
(
self
.
degrees
)
angle
=
self
.
get_params
(
self
.
degrees
)
return
F
.
rotate
(
img
,
angle
,
self
.
resample
,
self
.
expand
,
self
.
center
)
return
F
.
rotate
(
img
,
angle
,
self
.
resample
,
self
.
expand
,
self
.
center
,
self
.
fill
)
def
__repr__
(
self
):
def
__repr__
(
self
):
format_string
=
self
.
__class__
.
__name__
+
'(degrees={0}'
.
format
(
self
.
degrees
)
format_string
=
self
.
__class__
.
__name__
+
'(degrees={0}'
.
format
(
self
.
degrees
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment