python 图像处理的同态滤波复现
作者:互联网
基于网友的方案,手动改的方案。传送门链接
'''
同态滤波
'''
def homofilter(img):
I = np.float32(img)
I3 = I
m, n, chanels = I.shape
rL = 0.5
rH = 2
c = 2
d0 = 20
for chanel in range(chanels):
I1 = np.log(I[:, :, chanel] + 1)
FI = np.fft.fft2(I1)
n1 = np.floor(m / 2)
n2 = np.floor(n / 2)
D = np.zeros((m, n))
H = np.zeros((m, n))
for i in range(m):
for j in range(n):
D[i, j] = ((i - n1) ** 2 + (j - n2) ** 2)
H[i, j] = (rH - rL) * (np.exp(c * (-D[i, j] ** 2 / (d0 ** 2)))) + rL
I2 = np.fft.ifft2(H * FI)
I3[:, :, chanel] = np.real(np.exp(I2))
max_index = np.unravel_index(I3.argmax(), I3.shape)
maxV = I3[max_index[0], max_index[1], max_index[2]]
min_index = np.unravel_index(I3.argmin(), I3.shape)
minV = I3[min_index[0], min_index[1], min_index[2]]
print(I3.shape)
for chanel in range(chanels):
for i in range(m):
for j in range(n):
I3[i, j, chanel] = 255 * (I3[i, j, chanel] - minV) / (maxV - minV)
return np.int32(I3)
##实现效果
同态滤波之后,颜色有点变得离谱。大神路过有建议的话,麻烦评论一下,我会关注的5555
可能有些问题,大家积极评论,我积极改进。更新正文内容。
标签:index,同态滤波,python,I3,shape,range,图像处理,np,chanel 来源: https://blog.csdn.net/QuickservedNoodle/article/details/120420255