-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageTransformations.py
53 lines (35 loc) · 1.07 KB
/
ImageTransformations.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
import cv2
import math
# Logarithmic Transformations
def log_transform(col, max_pixel_value):
c = 255/(math.log(1+max_pixel_value))
new_col = c * math.log(1+col)
return new_col
def max_pixel(img):
max_pixel = 0
height, width, channels = img.shape
for i in range(height):
for j in range(width):
for k in range(channels):
if(max_pixel < img[i][j][k]):
max_pixel = img[i][j][k]
return max_pixel
# Power law transformation
def powertrans(c, gamma, r):
# = C*r^gamma
new_col = c*((r/c)**gamma)
return new_col
# Driver code
img = cv2.imread("sample.jpg")
height, width, channels = img.shape
max_pixel_value = max_pixel(img)
for i in range(height):
for j in range(width):
for k in range(channels):
#new_col = 255 - img[i][j][k]
#new_col = log_transform(img[i][j][k], max_pixel_value)
new_col = powertrans(255, 0.4, img[i][j][k])
img[i][j][k] = new_col
cv2.imshow('image',img)
cv2.waitKey()
cv2.destroyAllWindows()