Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindarmour
提交
aaa96db2
M
mindarmour
项目概览
MindSpore
/
mindarmour
通知
4
Star
2
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindarmour
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
aaa96db2
编写于
7月 29, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
7月 29, 2020
浏览文件
操作
浏览文件
下载
差异文件
!65 update image transform
Merge pull request !65 from ZhidanLiu/master
上级
dff8f9b2
f1b07391
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
23 deletion
+23
-23
mindarmour/utils/image_transform.py
mindarmour/utils/image_transform.py
+23
-23
未找到文件。
mindarmour/utils/image_transform.py
浏览文件 @
aaa96db2
...
...
@@ -52,13 +52,13 @@ class Contrast(ImageTransform):
def
random_param
(
self
):
""" Random generate parameters. """
self
.
factor
=
random
.
uniform
(
-
10
,
10
)
self
.
factor
=
random
.
uniform
(
-
5
,
5
)
def
transform
(
self
):
img
=
Image
.
fromarray
(
self
.
image
,
self
.
mode
)
img
=
Image
.
fromarray
(
np
.
uint8
(
self
.
image
*
255
)
,
self
.
mode
)
img_contrast
=
ImageEnhance
.
Contrast
(
img
)
trans_image
=
img_contrast
.
enhance
(
self
.
factor
)
trans_image
=
np
.
array
(
trans_image
)
trans_image
=
np
.
array
(
trans_image
)
/
255
return
trans_image
...
...
@@ -79,13 +79,13 @@ class Brightness(ImageTransform):
def
random_param
(
self
):
""" Random generate parameters. """
self
.
factor
=
random
.
uniform
(
-
10
,
10
)
self
.
factor
=
random
.
uniform
(
0
,
5
)
def
transform
(
self
):
img
=
Image
.
fromarray
(
self
.
image
,
self
.
mode
)
img
=
Image
.
fromarray
(
np
.
uint8
(
self
.
image
*
255
)
,
self
.
mode
)
img_contrast
=
ImageEnhance
.
Brightness
(
img
)
trans_image
=
img_contrast
.
enhance
(
self
.
factor
)
trans_image
=
np
.
array
(
trans_image
)
trans_image
=
np
.
array
(
trans_image
)
/
255
return
trans_image
...
...
@@ -106,13 +106,13 @@ class Blur(ImageTransform):
def
random_param
(
self
):
""" Random generate parameters. """
self
.
radius
=
random
.
uniform
(
-
1
0
,
10
)
self
.
radius
=
random
.
uniform
(
-
1
.5
,
1.5
)
def
transform
(
self
):
""" Transform the image. """
img
=
Image
.
fromarray
(
self
.
image
,
self
.
mode
)
img
=
Image
.
fromarray
(
np
.
uint8
(
self
.
image
*
255
)
,
self
.
mode
)
trans_image
=
img
.
filter
(
ImageFilter
.
GaussianBlur
(
radius
=
self
.
radius
))
trans_image
=
np
.
array
(
trans_image
)
trans_image
=
np
.
array
(
trans_image
)
/
255
return
trans_image
...
...
@@ -133,14 +133,14 @@ class Noise(ImageTransform):
def
random_param
(
self
):
""" random generate parameters """
self
.
factor
=
random
.
uniform
(
-
1
,
1
)
self
.
factor
=
random
.
uniform
(
0.7
,
1
)
def
transform
(
self
):
""" Random generate parameters. """
noise
=
np
.
random
.
uniform
(
low
=-
1
,
high
=
1
,
size
=
self
.
image
.
shape
)
trans_image
=
np
.
copy
(
self
.
image
)
trans_image
[
noise
<
-
self
.
factor
]
=
0
trans_image
[
noise
>
self
.
factor
]
=
255
trans_image
[
noise
>
self
.
factor
]
=
1
trans_image
=
np
.
array
(
trans_image
)
return
trans_image
...
...
@@ -163,15 +163,15 @@ class Translate(ImageTransform):
def
random_param
(
self
):
""" Random generate parameters. """
image_shape
=
np
.
shape
(
self
.
image
)
self
.
x_bias
=
random
.
uniform
(
0
,
image_shape
[
0
]
)
self
.
y_bias
=
random
.
uniform
(
0
,
image_shape
[
1
]
)
self
.
x_bias
=
random
.
uniform
(
-
image_shape
[
0
]
/
3
,
image_shape
[
0
]
/
3
)
self
.
y_bias
=
random
.
uniform
(
-
image_shape
[
1
]
/
3
,
image_shape
[
1
]
/
3
)
def
transform
(
self
):
""" Transform the image. """
img
=
Image
.
fromarray
(
self
.
image
,
self
.
mode
)
img
=
Image
.
fromarray
(
np
.
uint8
(
self
.
image
*
255
)
,
self
.
mode
)
trans_image
=
img
.
transform
(
img
.
size
,
Image
.
AFFINE
,
(
1
,
0
,
self
.
x_bias
,
0
,
1
,
self
.
y_bias
))
trans_image
=
np
.
array
(
trans_image
)
trans_image
=
np
.
array
(
trans_image
)
/
255
return
trans_image
...
...
@@ -192,15 +192,15 @@ class Scale(ImageTransform):
def
random_param
(
self
):
""" Random generate parameters. """
self
.
factor_x
=
random
.
uniform
(
0
,
1
)
self
.
factor_y
=
random
.
uniform
(
0
,
1
)
self
.
factor_x
=
random
.
uniform
(
0
.7
,
2
)
self
.
factor_y
=
random
.
uniform
(
0
.7
,
2
)
def
transform
(
self
):
""" Transform the image. """
img
=
Image
.
fromarray
(
self
.
image
,
self
.
mode
)
img
=
Image
.
fromarray
(
np
.
uint8
(
self
.
image
*
255
)
,
self
.
mode
)
trans_image
=
img
.
transform
(
img
.
size
,
Image
.
AFFINE
,
(
self
.
factor_x
,
0
,
0
,
0
,
self
.
factor_y
,
0
))
trans_image
=
np
.
array
(
trans_image
)
trans_image
=
np
.
array
(
trans_image
)
/
255
return
trans_image
...
...
@@ -225,7 +225,7 @@ class Shear(ImageTransform):
def
transform
(
self
):
""" Transform the image. """
img
=
Image
.
fromarray
(
self
.
image
,
self
.
mode
)
img
=
Image
.
fromarray
(
np
.
uint8
(
self
.
image
*
255
)
,
self
.
mode
)
if
np
.
random
.
random
()
>
0.5
:
level
=
-
self
.
factor
else
:
...
...
@@ -236,7 +236,7 @@ class Shear(ImageTransform):
else
:
trans_image
=
img
.
transform
(
img
.
size
,
Image
.
AFFINE
,
(
1
,
0
,
0
,
level
,
1
,
0
))
trans_image
=
np
.
array
(
trans_image
,
dtype
=
np
.
float
)
trans_image
=
np
.
array
(
trans_image
,
dtype
=
np
.
float
)
/
255
return
trans_image
...
...
@@ -261,7 +261,7 @@ class Rotate(ImageTransform):
def
transform
(
self
):
""" Transform the image. """
img
=
Image
.
fromarray
(
self
.
image
,
self
.
mode
)
img
=
Image
.
fromarray
(
np
.
uint8
(
self
.
image
*
255
)
,
self
.
mode
)
trans_image
=
img
.
rotate
(
self
.
angle
)
trans_image
=
np
.
array
(
trans_image
)
trans_image
=
np
.
array
(
trans_image
)
/
255
return
trans_image
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录