帮我将下列代码的注释标准化细化,用matlab代码表示:%% 系统参数
lambda = 532e-9; % 波长
dx = 2.9e-6; % CCD像素尺寸
z = 0.27; % 传播距离
[M, N] = deal(1024); % 图像尺寸
k = 2*pi/lambda; % 波数
%% 加载样品并生成全息图
img = im2double(imresize(rgb2gray(imread(‘BJUT.jpg’)), [M, N]));
phase = 2piimgaussfilt(img,3);
U0 = img .* exp(1i*phase); % 原始复振幅
% 菲涅尔衍射传递函数
fx = (-N/2:N/2-1)/(Ndx);
fy = (-M/2:M/2-1)/(Mdx);
[FX, FY] = meshgrid(fx, fy);
H = exp(1ikz) .* exp(-1ipilambdaz(FX.^2 + FY.^2));
% 生成全息图
U_prop = ifft2(fft2(U0) .* fftshift(H));
I_hologram = abs(U_prop).^2;
%% 重建算法集合
methods = {
struct(‘name’,‘Angular Spectrum’, ‘H’, conj(H)),…
struct(‘name’,‘Tikhonov Reg’, ‘H’, conj(H)./(abs(H).^2 + 0.01)),…
struct(‘name’,‘GS Iteration(20)’, ‘H’, conj(H), ‘iter’,20)
};
%% 执行重建与评估
results = cell(size(methods));
for m = 1:length(methods)
tic;
% 基础重建
U_recon = ifft2(fft2(I_hologram) .* fftshift(methods{m}.H));
% 迭代处理
if isfield(methods{m}, ‘iter’)
for iter = 1:methods{m}.iter
U_recon = ifft2(fft2(U0) .* fftshift(H)); % 正向传播
U_recon = img .* exp(1iangle(U_recon)); % 振幅约束
U_recon = ifft2(fft2(U_recon) . fftshift(conj(H))); % 反向传播
end
end
% 评估指标
metrics = evaluate_metrics(U0, U_recon);
metrics.Time = toc;
% 存储结果
results{m} = struct(‘name’,methods{m}.name,…
‘U’,U_recon,…
‘metrics’,metrics);
end
%% 多维评价函数 (新增相位评估)
function [metrics] = evaluate_metrics(orig, recon)
% 振幅指标
amp_orig = abs(orig)/max(abs(orig(:)));
amp_recon = abs(recon)/max(abs(recon(:)));
mse_amp = mean((amp_orig(:) - amp_recon(:)).^2);
psnr_amp = 10*log10(1/mse_amp);
ssim_amp = ssim(amp_recon, amp_orig);
% 相位指标
phase_orig = angle(orig);
phase_recon = angle(recon);
phase_diff = mod(phase_recon - phase_orig + pi, 2*pi) - pi;
mse_phase = mean(phase_diff(:).^2);
ssim_phase = ssim(mat2gray(phase_recon), mat2gray(phase_orig));
metrics = struct(…
‘PSNR’, psnr_amp,…
‘SSIM_Amp’, ssim_amp,…
‘MSE_Phase’, mse_phase,…
‘SSIM_Phase’, ssim_phase);
end
%% 可视化对比
figure(‘Position’,[100 100 1200 800])
% 原始数据
subplot(3,3,1); imshow(abs(U0),[]); title(‘原始振幅’);
subplot(3,3,2); imshow(angle(U0),[]); title(‘原始相位’);
subplot(3,3,3); imshow(I_hologram,[]); title(‘全息图’);
% 各方法重建结果
for m = 1:length(results)
subplot(3,3,3+m);
imshow(abs(results{m}.U),[]);
title({results{m}.name,…
[‘PSNR:’,num2str(results{m}.metrics.PSNR,2),‘dB’],…
[‘Time:’,num2str(results{m}.metrics.Time,2),‘s’]});
subplot(3,3,6+m);
imshow(angle(results{m}.U),[]);
title({[‘Phase MSE:’,num2str(results{m}.metrics.MSE_Phase,2)],…
[‘SSIM:’,num2str(results{m}.metrics.SSIM_Phase,2)]});
end
%% 指标表格输出
fprintf(‘\n=== 定量评估结果 ===\n’);
fprintf(‘%-20s\t%-8s\t%-8s\t%-10s\t%-8s\n’,…
‘Method’,‘PSNR’,‘SSIM(A)’,‘MSE(Phase)’,‘SSIM(P)’);
for m = 1:length(results)
fprintf(‘%-20s\t%-8.2f\t%-8.3f\t%-10.4f\t%-8.3f\n’,…
results{m}.name,…
results{m}.metrics.PSNR,…
results{m}.metrics.SSIM_Amp,…
results{m}.metrics.MSE_Phase,…
results{m}.metrics.SSIM_Phase);
end
最新发布