-
Notifications
You must be signed in to change notification settings - Fork 0
/
PIL_preprocess
57 lines (39 loc) · 1.41 KB
/
PIL_preprocess
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
#contrast,brightness,sharpness modification
def modify_contrast(val,modimg):
'''
input:
val: int, A floating point value controlling the enhancement. Factor 1.0 always
returns a copy of the original image, lower factors mean less color
(brightness, contrast, etc), and higher values more.
modimg: image object(PIL) that we want to process
output:
modimg: a numpy array representing the image
'''
filtercontrast = ImageEnhance.Contrast(modimg)
modimg = filtercontrast.enhance(val)
modimg = np.array(modimg) # convert into a numpy array
return modimg
def modify_brightness(val,modimg):
'''
input:
val: int, A floating point value controlling the enhancement.
modimg: image object(PIL) that we want to process
output:
modimg: a numpy array representing the image
'''
filterbright = ImageEnhance.Brightness(modimg)
modimg = filterbright.enhance(val)
modimg = np.array(modimg) # convert into a numpy array
return modimg
def modify_sharpness(val, modimg):
'''
input:
val: int, A floating point value controlling the enhancement.
modimg: image object(PIL) that we want to process
output:
modimg: a numpy array representing the image
'''
filtersharp = ImageEnhance.Sharpness(modimg)
modimg = filtersharp.enhance(val)
#modimg = np.array(modimg) # convert into a numpy array
return modimg