-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimplefunctions
99 lines (64 loc) · 2.3 KB
/
Simplefunctions
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import numpy as np
import cv2
def mod_con_bri(alpha,beta,img):
adjusted = cv2.convertScaleAbs(img, alpha=alpha, beta=beta)
return adjusted
def mod_sharp(modimg):
#---Sharpening filter----
#kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
kernel = np.array([[0,-1,0], [-1,5,-1], [0,-1,0]])
img = cv2.filter2D(modimg, -1, kernel)
return img
#specfies to read image file in colour
imag = cv2.imread('fulltest.tif', 1)
#values for contrast and brightness
alpha = 1.6
beta = 20
adjusted = mod_con_bri(alpha, beta, imag)
newimg = mod_sharp(adjusted)
cv2.imshow("Opening img...",imag)
cv2.imshow("Brightness&Contrast",adjusted)
cv2.imshow("Sharpening",newimg)
cv2.waitKey()
cv2.destroyAllWindows()
# modify_contrast(2.0,img)
#Backup
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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