Skip to content

Commit 70750b6

Browse files
authored
Add files via upload
1 parent f01b49e commit 70750b6

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

blog16-BH/2016.png

43.1 KB
Loading

blog16-BH/2019.png

116 KB
Loading

blog16-BH/blog16-image02.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
import cv2
5+
6+
#绘制曲线
7+
def log_plot(c):
8+
x = np.arange(0, 256, 0.01)
9+
y = c * np.log(1 + x)
10+
plt.plot(x, y, 'r', linewidth=1)
11+
plt.rcParams['font.sans-serif']=['SimHei'] #正常显示中文标签
12+
plt.title(u'对数变换函数')
13+
plt.xlim(0, 255), plt.ylim(0, 255)
14+
plt.show()
15+
16+
#对数变换
17+
def log(c, img):
18+
output = c * np.log(1.0 + img)
19+
output = np.uint8(output + 0.5)
20+
return output
21+
22+
#读取原始图像
23+
img = cv2.imread('2016.png')
24+
25+
#绘制对数变换曲线
26+
log_plot(42)
27+
28+
#图像灰度对数变换
29+
output = log(42, img)
30+
31+
#显示图像
32+
cv2.imshow('Input', img)
33+
cv2.imshow('Output', output)
34+
cv2.waitKey(0)
35+
cv2.destroyAllWindows()

blog16-BH/blog16-image03.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
import cv2
5+
6+
#绘制曲线
7+
def gamma_plot(c, v):
8+
x = np.arange(0, 256, 0.01)
9+
y = c*x**v
10+
plt.plot(x, y, 'r', linewidth=1)
11+
plt.rcParams['font.sans-serif']=['SimHei'] #正常显示中文标签
12+
plt.title(u'伽马变换函数')
13+
plt.xlim([0, 255]), plt.ylim([0, 255])
14+
plt.show()
15+
16+
#伽玛变换
17+
def gamma(img, c, v):
18+
lut = np.zeros(256, dtype=np.float32)
19+
for i in range(256):
20+
lut[i] = c * i ** v
21+
output_img = cv2.LUT(img, lut) #像素灰度值的映射
22+
output_img = np.uint8(output_img+0.5)
23+
return output_img
24+
25+
#读取原始图像
26+
img = cv2.imread('2019.png')
27+
28+
#绘制伽玛变换曲线
29+
gamma_plot(0.00000005, 4.0)
30+
31+
#图像灰度伽玛变换
32+
output = gamma(img, 0.00000005, 4.0)
33+
34+
#显示图像
35+
cv2.imshow('Imput', img)
36+
cv2.imshow('Output', output)
37+
cv2.waitKey(0)
38+
cv2.destroyAllWindows()

blog16-BH/miao.jpg

19.7 KB
Loading

0 commit comments

Comments
 (0)