原理
幂函数的基本形式为:
s = c × r Γ s = c \times r ^ \Gamma s=c×rΓ
其中 c 和 Γ \Gamma Γ表示正常数,r表示输入的灰度值,当c=1时不同的 Γ \Gamma Γ值对应的s曲线如下图所示。
当 Γ < 1 \Gamma<1 Γ<1时,对图像的暗区有提亮的作用,当 Γ > 1 \Gamma>1 Γ>1对图像的高亮部分有抑制作用。
代码
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
def gamma_transform(image, th1, th2, gamma1, gamma2):
if gamma1 == gamma2:
image1 = np.power(image, gamma1)
else:
if image.ndim == 3:
c, r, d = image.shape
y = image[:,:,0]*0.299+image[:,:,1]*0.587+image[:,:,2]*0.114
image1 = np.zer