-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_law.py
79 lines (59 loc) · 2.05 KB
/
power_law.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
74
75
76
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 19 20:07:29 2022
@author: Anil 076MSICE003
"""
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import math
#creating a function to negate the image
def powerLaw(image,constant,gamma):
image = image.resize((400,400), Image.LANCZOS)
#converting to numpy array
numpy_image = np.array(image)
r = numpy_image.shape[0]
c = numpy_image.shape[1]
temp = np.zeros(shape=(r,c))
for i in range(r):
for j in range(c):
temp[i][j] = constant * (numpy_image[i][j] ** gamma) #Correcting gamma s=cr^γ
power = Image.fromarray(temp)
return power
# reading image and converting to gray scale
loaded_img = Image.open('einstein.jpg').convert('L')
image = loaded_img.resize((400,400), Image.LANCZOS)
power_img = powerLaw(loaded_img,1,10)
"""
s=cr^γ
This symbol γ is called gamma, due to which this transformation
is also known as gamma transformation.
Variation in the value of γ varies the enhancement of the images.
Different display devices / monitors have their own gamma correction,
that’s why they display their image at different intensity.
This type of transformation is used for enhancing images for different type
of display devices. The gamma of different display devices is different.
For example Gamma of CRT lies in between of 1.8 to 2.5, that means the image displayed
on CRT is dark.
"""
#displaying the images
fig = plt.figure(figsize = (7,25))
fig.add_subplot(5,1,1)
plt.imshow(image, cmap = 'gray')
plt.title('Original image')
fig.add_subplot(5,1,2)
power_img1 = powerLaw(loaded_img,1,1.20)
plt.imshow(power_img1, cmap='gray')
plt.title('Gamma = 1.2')
fig.add_subplot(5,1,3)
power_img2 = powerLaw(loaded_img,1,1.25)
plt.imshow(power_img2, cmap='gray')
plt.title('Ganma = 1.25')
fig.add_subplot(5,1,4)
power_img3 = powerLaw(loaded_img,1,1.30)
plt.imshow(power_img3, cmap='gray')
plt.title('Gamma = 1.3')
fig.add_subplot(5,1,5)
power_img4 = powerLaw(loaded_img,1,1.35)
plt.imshow(power_img4, cmap='gray')
plt.title('Gamma = 1.35')