傅里叶全息变换

 1 # -*- coding:utf-8 -*-
 2 import numpy as np
 3 import matplotlib.pyplot as plt
 4 import cv2
 5 import random,cmath
 6 
 7 '''设置反馈系数、迭代次数'''
 8 alpha=0.1
 9 iteration=int(input('请输入迭代次数'))
10 
11 NRMSD=np.zeros([1,iteration],float)
12 
13 '''读取图像数组,并归一化'''
14 imgGray=cv2.imread('C:\\Users\hanli\Desktop\study\Einstein.tif',0)
15 [r,c]=imgGray.shape
16 Iorg=imgGray/imgGray.max()
17 
18 Iorg=np.fft.ifftshift(Iorg)
19 Iang=2*cmath.pi*random.random()
20 I=Iorg*cmath.exp(1j*Iang)
21 for i in range(iteration):
22     h=np.fft.ifft2(I)
23     hphi=np.angle(h)
24     for m in range(r):
25         for n in range(c):
26             h[m,n]=cmath.exp(1j*hphi[m,n])
27     I=np.fft.fft2(h)
28     Iabs=abs(I)
29     Iabs=(Iabs-Iabs.min())/(Iabs.max()-Iabs.min())
30     Iang=np.angle(I)
31     resid=Iorg-Iabs
32     Inew=Iorg+resid*alpha
33     Iexp=np.ones((r,c),dtype=complex)
34     for m in range(r):
35         for n in range(c):
36             Iexp[m,n]=cmath.exp(1j*Iang[m,n])
37     I=Inew*Iexp
38 
39 I=np.fft.fft2(h)
40 plt.subplot(121)
41 plt.imshow(hphi,cmap='gray')
42 plt.subplot(122)
43 plt.imshow(abs(np.fft.fftshift(I)),cmap='gray')
44 plt.show()

上图是迭代60次的结果

转载于:https://www.cnblogs.com/haliQ/p/6637092.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值