基于波前编码成像系统模拟及图像复原

基于波前编码成像系统模拟及图像复原的MATLAB实现

一、系统建模与参数设置

%% 系统参数设置
clear; clc; close all;

% 光学系统参数
lambda = 500e-9; % 波长(m)
k = 2*pi/lambda; % 波数
D = 1e-3; % 孔径直径(m)
N = 512; % 采样点数
x = linspace(-D/2,D/2,N); % 空间坐标
[X,Y] = meshgrid(x,x); % 网格坐标

% 波前编码参数
phase_depth = 0.5; % 相位调制深度(rad)
coding_type = 'Zernike'; % 编码类型:Zernike/Custom

% 图像参数
img = imread('cameraman.tif'); % 原始图像
img_gray = im2double(rgb2gray(img)); % 灰度图像

二、波前编码模拟

1. 相位板生成

function phase = generate_phase_mask(coding_type, N, phase_depth)
    switch coding_type
        case 'Zernike'
            % 生成Zernike相位板(4阶球差)
            [x,y] = meshgrid(linspace(-1,1,N),linspace(-1,1,N));
            rho = sqrt(x.^2 + y.^2);
            phase = phase_depth * (2*rho.^4 - 1); % Z4项
            phase(rho>1) = 0; % 超出孔径置零
        case 'Custom'
            % 自定义相位分布(示例:正弦光栅)
            phase = phase_depth * sin(2*pi*X/D);
        otherwise
            error('Unsupported coding type');
    end
end

% 生成相位板
phase_mask = generate_phase_mask(coding_type,N,phase_depth);

2. 光瞳函数建模

% 光瞳函数(圆形孔径)
pupil = double(X.^2 + Y.^2 <= (D/2)^2);

% 编码后光瞳函数
encoded_pupil = pupil .* exp(1i*phase_mask);

三、成像过程模拟

%% 傅里叶光学成像模拟
% 傅里叶变换
fx = (-N/2:N/2-1)/N;
[Fx,Fy] = meshgrid(fx,fx);
H = exp(-1i*k*(X.^2 + Y.^2)/(2*lambda)); % 透镜相位因子

% 光场传播
field = fftshift(fft2(encoded_pupil .* H));
image_plane = abs(fftshift(fft2(field)))^2; % 强度分布

% 添加噪声
noise_level = 0.01;
noisy_image = image_plane + noise_level*randn(size(image_plane));

四、图像复原算法

1. 维纳滤波复原

% 计算点扩散函数(PSF)
psf = fftshift(fft2(encoded_pupil));
psf = psf ./ max(psf(:)); % 归一化

% 维纳滤波参数
K = 0.01; % 噪声功率谱密度估计

% 执行复原
[restored, ~] = deconvwnr(noisy_image, psf, K);

2. 相位恢复算法(Gerchberg-Saxton)

function phase_recovered = GS_algorithm(intensity, iterations)
    [N,M] = size(intensity);
    phase = ones(N,M); % 初始相位猜测
    for iter = 1:iterations
        % 傅里叶变换
        field = fftshift(fft2(intensity.*exp(1i*phase)));
        % 更新振幅
        amplitude = sqrt(intensity);
        % 逆傅里叶变换
        new_intensity = fftshift(ifft2(field .* conj(amplitude)));
        % 更新相位
        phase = new_intensity ./ max(abs(new_intensity),eps);
    end
    phase_recovered = angle(field);
end

% 执行Gerchberg-Saxton算法
recovered_phase = GS_algorithm(noisy_image, 100);

参考源码 这是针对波前编码成像系统模拟,以及图像复原模拟代码 www.youwenfan.com/contentcna/66021.html

五、结果可视化与评估

%% 结果展示
figure;

% 原始图像
subplot(2,2,1);
imshow(img_gray);
title('原始图像');
xlabel('(a)');

% 编码后图像
subplot(2,2,2);
imshow(noisy_image,[]);
title('编码成像(含噪声)');
xlabel('(b)');

% 维纳滤波复原
subplot(2,2,3);
imshow(restored);
title('维纳滤波复原');
xlabel('(c)');

% Gerchberg-Saxton复原
subplot(2,2,4);
recovered_img = ifft2(fft2(restored) .* exp(-1i*recovered_phase));
imshow(abs(recovered_img),[]);
title('相位恢复复原');
xlabel('(d)');

%% 性能评估
psnr_wiener = psnr(restored,img_gray);
psnr_gs = psnr(abs(recovered_img),img_gray);
ssim_wiener = ssim(restored,img_gray);
ssim_gs = ssim(abs(recovered_img),img_gray);

fprintf('维纳滤波: PSNR=%.2f dB, SSIM=%.4f\n', psnr_wiener, ssim_wiener);
fprintf('相位恢复: PSNR=%.2f dB, SSIM=%.4f\n', psnr_gs, ssim_gs);

该方法通过结合傅里叶光学建模与先进复原算法,实现了波前编码系统的完整仿真。实际应用中需根据具体光学系统参数调整相位编码方案,并建议采用深度学习与传统算法的混合架构以提升复原性能。

posted @ 2025-07-24 11:47  alloutlove  阅读(20)  评论(0)    收藏  举报