python openCV 同态滤波实现

python openCV 同态滤波实现

def homofilter(I):
plt.subplot(1,2,1),plt.imshow(I),plt.title(‘原始图像’)
I = np.double(cv2.cvtColor(I,cv2.COLOR_RGB2GRAY))
m,n = I.shape
rL = 0.5
rH = 2
c =2
d0 = 20
I1 = np.log(I+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]/(d0**2))))+rL
print(‘D’,D)
print(‘H’,H)
I2 = np.fft.ifft2(H*FI)
I3 = np.real(np.exp(I2))
plt.subplot(1,2,2),plt.imshow(I3),plt.title(‘同态滤波增强后的图像’)
plt.show()

plt.rcParams[‘font.sans-serif’]=[‘SimHei’]
plt.rcParams[‘axes.unicode_minus’] = False
img = cv2.imread(‘capture.png’)
(r,g,b)=cv2.split(img) #颜色通道调整
img = cv2.merge([b,g,r])
homofilter(img)

效果:
python openCV 同态滤波实现_第1张图片

你可能感兴趣的:(图像处理)