%基于相位恢复的全息图算法的研究:GS算法
%Read Image 读图
Image=double(imread('C:\Users\ruixuan\Pictures\lovewallpaper\9a1d5417.jpg')); %读图,并将图信息转换为双精度浮点型
[m,n,q]=size(Image); %返回三维数组"Image"中m,n,q的值,即几行几列几页,m= n= q=
PSIZE=size(Image); % 返回数组每一维的大小,即PSIZE=[m n q]
P=size(PSIZE); %返回数组每一维的大小,=3?
global Gimage;%定义全局变量
if (P(2)==2)
Gimage=Image;
else
Gimage=round((Image(:,:,1)+Image(:,:,2)+Image(:,:,3))/3);%将彩色图像转换成灰度图;round四舍五入,(:,:,1)取第1页所有行列
end
%Initialzation 初始化
Phase0=zeros(m,n); %m行n列全0矩阵
G0=Gimage/255; % 像素灰度值范围0~255,将灰度归一化?
RMS=255; %RMS,均方根误差
best_phase=zeros(PSIZE(1),PSIZE(2));
%iteration 迭代
for loop=1:20 %迭代20次
h0=ifft2(G0.*exp(i*Phase0)); %二维逆向快速傅里叶变换,将频域转换为空域
H0=angle(h0); %求相位角
g0=fft2(exp(i*H0)); %二维快速傅里叶变换,将空域转换为频域
Phase0=angle(g0); %求相位角
%Best phase
RImage=round(255*abs(g0)/max(max(abs(g0))));
Error=sqrt(sum(sum((RImage-Gimage).^2))/(PSIZE(1)*PSIZE(2)));%FT变换后的幅值信息(灰度)均方根误差
if (Error<RMS) %与原始图像灰度的均方根误差进行比较
best_phase=H0;
RMS=Error;
end
if (RMS<1)
break;
end
end
%Phase_only Hologram 纯相位全息图
Phase_Hologram=best_phase;
g=fft2(exp(i*Phase_Hologram));
RImage=round(255*abs(g)/max(max(abs(g))));
%部分参数计算
EImage=abs(RImage-Gimage);%误差图像
MAX=max(max(EImage));%最大误差
MEAN=sum(sum(RImage-Gimage))/(PSIZE(1)*PSIZE(2));%平均误差
%显示
figure
subplot(2,2,1),imshow(G0,[]),colormap(gray),title('原图');
subplot(2,2,2),imshow(Phase_Hologram,[]),colormap(gray),title('纯相位全息图');
subplot(2,2,3),imshow(RImage,[]),colormap(gray),title('恢复的图像');
subplot(2,2,4),imshow(EImage,[]),colormap(gray),title('误差图像');
GS222.zip_GS图_gs全息_全息_全息再现_全息再现算法
版权申诉
![star](https://csdnimg.cn/release/downloadcmsfe/public/img/star.98a08eaa.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
weixin_42653672
- 粉丝: 94
- 资源: 1万+