-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_augmentor.py
executable file
·73 lines (64 loc) · 2.45 KB
/
data_augmentor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#coding:utf-8
#########################################################################
# File Name: data_augmentor.py
# Author:Lei Jiang
# mail: [email protected]
# Created Time: 2016年04月12日 星期二 15时42分46秒
# Copyright Nanjing Qing So information technology
#########################################################################
from PIL import Image
from PIL import ImageEnhance
import numpy as np
import matplotlib.pyplot as plt
class Data_augmentor(object):
def __init__(self):
pass
def change_brightness(self,img_path,factor):
'''change image brightness factor:0.0:black,1.0:original'''
img=Image.open(img_path)
img=img.convert('RGB')
img_enhance=ImageEnhance.Brightness(img)
res=img_enhance.enhance(factor)
method_name='bright'
return res, method_name
def change_contrast(self,img_path,factor):
'''change image contrast factor:0.0:solid grey image,1.0:original'''
img=Image.open(img_path)
img=img.convert('RGB')
img_enhance=ImageEnhance.Contrast(img)
res=img_enhance.enhance(factor)
method_name='contrast'
return res,method_name
def change_sharpness(self,img_path,factor):
'''change image sharpness factor:0.0 blured image,2.0 sharped image,1.0
original'''
img=Image.open(img_path)
img=img.convert('RGB')
img_enhance=ImageEnhance.Sharpness(img)
res=img_enhance.enhance(factor)
method_name='sharpness'
return res,method_name
def rotate_image(self,img_path,angle):
img=Image.open(img_path)
res=img.rotate(angle,Image.NEAREST,expand=1)
method_name='rotate'
return res,method_name
def change_color(self,img_path,factor):
'''change image color factor:0.0 black and white 1.0 original'''
img=Image.open(img_path)
img=img.convert('RGB')
img_enhance=ImageEnhance.Color(img)
res=img_enhance.enhance(factor)
method_name='color'
return res,method_name
if __name__=="__main__":
plt.subplot(121)
ori=plt.imread('/opt/datasets/same_car_image/ori_image/License_85/4404000000002940777727.jpg')
plt.imshow(ori)
##############################################
da=Data_augmentor()
res,_=da.change_sharpness('/opt/datasets/same_car_image/ori_image/License_85/4404000000002940777727.jpg',1.5)
res=np.array(res)
plt.subplot(122)
plt.imshow(res)
plt.show()