灰度变化-伽马变换
一、基础
首先,这里讨论的是基于空间域的灰度变换基于的表达式为:
f(x,y):原有空间域的图像表达式 ,g(x,y):基于算子T在空间域上对f的处理结果
二、伽马变换
s
=
c
∗
r
γ
s = c*r^{ \gamma }
s=c∗rγ
图片素材
代码实现
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
def gamma_change(img, c, gamma):
img_return = c * np.power(img, gamma)
return img_return
img = cv.imread("img/gamma_change.png")
print(img)
fig = plt.figure(figsize=(20,20))
c = 0.046
g = [1,0.6,0.5,0.4,0.3,0.2]
img_gamma = []
for i in range(len(g)):
ax = fig.add_subplot(2,int(len(g)/2),i+1)
img_gamma = gamma_change(img,c,g[i])
ax.imshow(img_gamma,cmap='gray')
if g[i] == 1:
ax.set_title("Original")
else:
ax.set_title(f"$\gamma={g[i]}$")
plt.tight_layout()
plt.show()