Asked by Vanessa
on 6 Jun 2017

Hi all,

I need to estimate the PSF of an optical system. I have all the parameters and have been following an excellent code that was mentioned in the 'Spherical aberration and Chromatic aberration' question ( https://de.mathworks.com/matlabcentral/answers/36064-spherical-aberration-and-chromatic-aberration ). I am trying to model the PSF of an optical system and then apply it to an image to see how blurry the image would be.

Everything works great but the only problem is the pixel sampling. With the code I am having trouble with the psf_sampling. My psf_sampling is larger (10e-6) and every time I run the code I get the following error:

'Sampling is not sufficient to reconstruct the entire wavefront.'

Please help me with this, much appreciated.

Kind regards,

Vanessa

%%Define parameters

clear all;close all;

psf_sampling = 0.5e-6;%focal plane sampling in meters

lambda = 0.6328e-6;%wavelength in meters

N = 256;

aperture_diameter = 0.0254;%meters; 1 inch

focal_length = 5*aperture_diameter;%meters

RMS_SA = 0.25;%RMS spherical aberration content in waves

%%Calculate pupil plane sampling

delta_fx = 1/(psf_sampling*N);

x_pupil = (-fix(N/2):fix((N-1)/2)) * delta_fx * lambda * focal_length;

[X_pupil,Y_pupil] = meshgrid(x_pupil);

R_pupil = sqrt(X_pupil.^2 + Y_pupil.^2);

R_norm = R_pupil/(aperture_diameter/2);%Pupil normalized to aperture diameter

assert(max(R_norm(:))>=sqrt(2),'Sampling is not sufficient to reconstruct the entire wavefront.');

%%Create wavefront

W = RMS_SA * sqrt(5) * (6*R_norm.^4 - 6*R_norm.^2 + 1);%Spherical Aberration wavefront

W(R_norm>1) = 0;

E = exp(1i*2*pi*W);%Complex amplitude

E(R_norm>1) = 0;%Impose aperture size

figure;imagesc(angle(E)/(2*pi));colorbar;title('Wavefront Phase (waves)');

%%Create point-spread function

psf = abs(fftshift(fft2(ifftshift(E)))).^2;

psf = psf/sum(psf(:));%Normalize to unity energy

x_psf = (-fix(N/2):fix((N-1)/2)) * psf_sampling;

figure;imagesc(x_psf*1e6,x_psf*1e6,psf);

title(sprintf('PSF with %.4f waves RMS of Spherical Aberration', RMS_SA));

xlabel(sprintf('Position (\\mum)'));

ylabel(sprintf('Position (\\mum)'));

Answer by Image Analyst
on 6 Jun 2017

Image Analyst
on 7 Jun 2017

Vanessa
on 8 Jun 2017

Hi Image Analyst,

I have tried everything and no luck, but thank you for your replies, I am truly grateful and if by chance you figure something out, please let me know.

Eric
on 20 Jun 2017

Sign in to comment.

Answer by Eric
on 20 Jun 2017

Sorry, I was out on vacation for a couple weeks, then I posted to

https://www.mathworks.com/matlabcentral/answers/36064-spherical-aberration-and-chromatic- aberration

Here's that response:

The assert statement is checking that the sampling allows reconstruction of the entire wavefront. If this assertion fails, then the pupil sampling is such that you cannot reconstruct the entirety of the wavefront area. This can happen if the pixel pitch is relatively large. Assuming you don’t want to adjust the aperture diameter, you need to increase the values in R_norm.

For instance, if I set the psf_sampling to 10e-6 meters, the code from the page results in max(R_norm(:)) of 0.4475.

A simple fix is to calculate the PSF at a finer resolution and then bin that PSF to the desired low-resolution. So for the case where you want a PSF sampling of 10 microns, you could calculate the PSF at a sampling of 2.0 microns. Calculate the psf as shown in the script. Then do the following:

kernel = ones(5,5)/5^2;

psf_lowres_all = conv2(psf, kernel, 'same');

psf_lowres = psf_lowres_all(3:5:end,3:5:end);

In this case you’re doing convolution to spatially sum 5x5 neighborhoods of the high-resolution PSF (5 is the correct value because it’s the ratio of the desired low-resolution pixel spacing to the calculated spacing). This convolution produces 25 possible low-resolution PSFs, each at a different registration of the optical PSF to the pixel grid. In the last line I’ve selected the one in the middle. In the indexing you skip by 5 because you want to get sums of adjacent blocks (i.e., not sliding blocks). You can change the indexing to select another possible low-resolution PSF. For instance, you could also use

psf_lowres = psf_lowres_all(1:5:end,4:5:end);

to select another PSF.

You’ll notice when this is done that the wavefront calculation area is zero-padded to be larger than the specified system aperture. You can check this by plotting abs(E).

Eric
on 20 Jun 2017

By the way, the system you specified has a Q of 0.5, where Q is lambda*f_number/pixel_pitch. This is a fairly common value for imaging systems. The code I wrote will work with a Q of 1 or higher, but you still might worry about aliasing. I would still use a psf_sampling of 2 microns to get the PSF at 5X resolution and then downsample from there.

A good reference on Q, though he doesn't use that term, is the following paper: R. D. Fiete, "Image quality and lambda FN/p for remote sensing systems," Optical Engineering 38, 1229-1240 (1999). This includes a nice discussion of why most imaging systems are designed with Q values less than 2 (a system is Nyquist sampled when Q=2, super-sampled when Q>2).

Eric
on 20 Jun 2017

One more suggestion:

If possible, I would do the entire image simulation in the high-resolution space and then downsample the blurred image.

That is, if you're working with simulated imagery, simulate the imagery at the 2 micron sampling as well (or any value less than 2.5 such that the Q of your system is 2 or higher). Convolve the high-resolution image with the high-resolution PSF. Then do the convolution with the kernel function and extraction of a representative image. This isn't always possible (e.g., the image you're blurring is measured), but if it is possible it most accurately represents information at aliased spatial frequencies.

Vanessa
on 20 Jun 2017

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.