-
Notifications
You must be signed in to change notification settings - Fork 0
/
contrastLinear.py
59 lines (47 loc) · 1.45 KB
/
contrastLinear.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
import numpy
import os
import cv2
from PIL import Image
def normalizeRed(intensity):
iI = intensity
minI = 60
maxI = 215
minO = 0
maxO = 255
iO = (iI - minI) * (((maxO - minO) / (maxI - minI)) + minO)
return iO
def normalizeGreen(intensity):
iI = intensity
minI = 50
maxI = 215
minO = 0
maxO = 255
iO = (iI - minI) * (((maxO - minO) / (maxI - minI)) + minO)
return iO
def normalizeBlue(intensity):
iI = intensity
minI = 50
maxI = 215
minO = 0
maxO = 255
iO = (iI - minI) * (((maxO - minO) / (maxI - minI)) + minO)
return iO
def increaseContrast (image):
pil_im = Image.fromarray(image)
multiBands = pil_im.split()
normalizedRedBand = multiBands[2].point(normalizeRed)
normalizedGreenBand = multiBands[1].point(normalizeGreen)
normalizedBlueBand = multiBands[0].point(normalizeBlue)
new_pil_im = Image.merge("RGB", (normalizedRedBand, normalizedGreenBand, normalizedBlueBand))
im2 = cv2.cvtColor(numpy.array(new_pil_im), cv2.COLOR_RGB2BGR)
return im2
if (os.path.isdir('./Resources/images/contrast2')==False):
#kreiraj folder
os.mkdir('./Resources/images/contrast2')
for i in range(853):
# Učitavanje slike
img = cv2.imread('./Resources/images/denoise_sharpen/maksssksksss' + str(i) + '.png')
dst = increaseContrast(img)
print(i)
# Pohranjivanje slike
cv2.imwrite('./Resources/images/contrast2/maksssksksss' + str(i) + '.png', dst)