Hi there,
I am working on a phase retrieval project and have been trying to use the DprGAMP.m
function from the D-AMP_Toolbox for reconstructing complex-valued images from their magnitude measurements. According to my understanding of phase retrieval, the goal is to recover the original complex signal, but the function seems to return only real-valued images.
I have prepared a complex test signal as x_0 = img2 .* exp(1i * pi * img1)
, using test images img1
and img2
. The reconstruction should retrieve the phase information from this signal. However, when I pass the magnitude measurements abs(M(x_0))
into the DprGAMP.m
function, the result is an array of NaN
values, which suggests that something is not working as expected.
Here's the MATLAB code I'm using, which is a modified version of the demo provided in the toolbox:
clear all;
clc;
close all;
addpath(genpath('..'));
%Parameters
denoiser='BM3D';%Available options are NLM, Gauss, Bilateral, BLS-GSM, BM3D, fast-BM3D, and BM3D-SAPCA
filename='barbara.png';
SamplingRate=.6;
iters=100;
imsize=128;
Beta_damp=.1;
wvar=.1;
ImIn1=im2double(imread("Set12/02.png"));
ImIn2=double(imread("Set12/01.png"));
img1=abs(imresize(ImIn1,imsize/size(ImIn1,1)));
img2=abs(imresize(ImIn2,imsize/size(ImIn2,1)));
x_0 = img2 .* exp(1i*pi*img1);
[height, width]=size(x_0);
n=length(x_0(:));
m=round(n*SamplingRate);
x_init=255*rand(n,1);
%Generate Coded Diffraction Pattern Handle
signvec = exp(1i*2*pi*rand(n,1));
inds=[1;randsample(n-1,m-1)+1];
I=speye(n);
SubsampM=I(inds,:);
M=@(x) SubsampM*reshape(fft2(reshape(bsxfun(@times,signvec,x(:)),[height,width])),[n,1])*(1/sqrt(n))*sqrt(n/m);
Mt=@(x) bsxfun(@times,conj(signvec),reshape(ifft2(reshape(SubsampM'*x(:),[height,width])),[n,1]))*sqrt(n)*sqrt(n/m);
M_norm2=n;
%Compute magnitudes of compressive samples of the signal
% w=sqrt(wvar)*(randn(m,1)+1i*randn(m,1));
y=abs(M(x_0(:)));
%Recover Signal using D-prGAMP algorithm
PNSR_func=@(x) PSNR(x_0(:),abs(x(:)));
[x_hat, PSNR_hist] = DprGAMP(y,iters,width,height,denoiser,M,Mt,M_norm2,Beta_damp,wvar,x_init,PNSR_func);
%D-prGAMP Recovery Performance
display([num2str(SamplingRate*100),'% Sampling ', denoiser, '-prGAMP Coded Diffraction Pattern Reconstruction PSNR=',num2str(PSNR_hist(end))])
%Plot Recovered Signals
subplot(1,3,1);
imshow(abs(x_0),[]);title('True Amplification');colorbar;
subplot(1,3,2);
imshow(angle(x_0),[]);title('True Phase');colorbar;
subplot(1,3,3);
imshow(x_hat,[]);title('Output');colorbar;
When I run this code, here's what I get as the output:
![](https://raw.githubusercontent.com/Charle4/Image-Hosting-Service/main/picgo/202403192314416.png)
NaN
Output with Complex Input:
![](https://raw.githubusercontent.com/Charle4/Image-Hosting-Service/main/picgo/202403192314419.png)
For comparison, when I use a real-valued image as input, like in the toolbox demo (x_0 = img2;
), the function works fine, and I get a reasonable reconstruction:
![](https://raw.githubusercontent.com/Charle4/Image-Hosting-Service/main/picgo/202403192329422.png)
Is the DprGAMP.m
function designed to work with complex signals for phase retrieval, and if so, could you provide any guidance on why it might be failing with a complex input? If the function is not intended for complex-valued signals, I'd appreciate any pointers on how to modify it or if there's an alternative approach within the toolbox for handling complex signals.
Your guidance would be greatly appreciated, as it would significantly aid my understanding and application of phase retrieval techniques.
Thank you for developing such a comprehensive toolbox and for your support in resolving this query.