09a) Digital Filtering

advertisement
ECEN 4616/5616
2/4/2013
Digital Filtering
We have shown (Notes: “Scalar Diffraction”, pg4-6, 1/30/13) how adding a cubic phase,
exp ia x 3  y 3 produces PSFs and MTFs that are largely invariant through a wide range
of misfocus. It remains to be seen how the images produced with such distorted PSFs
can be recovered to something resembling a normal in-focus image.
 

The imaging process can be described in a number of ways:
1. Most Basic: The optical system takes every point on the object and substitutes the
characteristic PSF for that point in the image. This description of the image as a
sum of PSFs works even when the PSFs are not the same over the image.
2. Constant PSFs: When the PSFs are essentially the same over the entire image, the
summation can be expressed as a convolution:
o  h  i,
where o is the object, h the psf, and i the resultant image.
It is only possible to define a single reconstruction filter for the second case – the case of
varying psfs must be handled in a more tedious manner.
Assuming the second condition (constant psfs over the image), the Convolution Theorem
in Fourier Transforms allows us to re-write the equation in terms of the Fourier
Transforms of the data as:
O H  I
The goal is to recover O. A naïve solution to the problem would be:
I
O
H
This solution is unlikely to work well, as the OTF, H, surely goes to zero at the
diffraction limit, so the solution would blow up. Even if we avoid going to the diffraction
limit, this equation is equivalent to multiplying each spatial frequency in the Image with a
factor that brings it up to one. These factors will get very large as the spatial frequencies
become larger (and their modulation lower), and any noise in the image will be greatly
enhanced.
A better solution is to find the Least-Squares solution for the matrix, G, which solves the
H
equation O  G  I . This solution is: G 
.
2
H
This solution still has the problem of  when H  0, so we will modify it by adding a
small parameter to restrain the value of G:
H
G
2
H 
pg. 1
ECEN 4616/5616
If  
2
2/4/2013
, where  2 is the variance of the noise, and P(O) is the spatial frequency
PO 
spectrum of the object, the resultant filter is the “Weiner Filter”, which is “optimum” in
the sense of having the minimum least-squared error in estimating the object.
The problem with the Weiner filter is that we often don’t know the variance of the noise,
and even less often the power spectrum of the object. In practice, therefore, we will just
use a “small” number and vary it until we like the results.
An additional problem with this approach is it is trying to estimate the “Object” – but the
Object has been passed through a low-pass filter (the optical system) and much
information about it has been suppressed or lost. We can solve this problem by
multiplying G by a band-limiting function, whose maximum spatial frequency is not to
exceed the maximum spatial frequency that can be passed by the system. This leads to
the filter:
H
G W
,
2
H 
where W is some matrix of spatial frequency amplitudes which has a cutoff at or before
the cutoff of the optical system. The amplitude of W for specific spatial frequencies can
exceed the corresponding amplitude of the optical system’s OTF, however, if some image
“enhancement” is desired. However, spatial frequencies not transmitted by the optical
system cannot be recovered.
Thus, the band-limited estimate of the object is recovered by:
O  GI ,
where G is calculated as above. By the Convolution Theorem, this operation can also be
done as a convolution between the inverse Fourier Transforms of the frequency-space
functions, i.e.:
o  g i
The following is an example of filtering a PSF from a system with a cubic phase
distortion at the pupil – the cubic phase allows the system to have a much larger Depth of
Focus than an unmodified system, and the filter operation converts the resultant images
back into diffraction-limited ones.
pg. 2
ECEN 4616/5616
2/4/2013
pg. 3
ECEN 4616/5616
2/4/2013
The Matlab code that did the filtering is in Appendix A.
pg. 4
ECEN 4616/5616
2/4/2013
Appendix A
%FILE: DigitalFilterDemo.m
%Creates and tests a digital filter for converting
% a cubic-phase PSF to a diffraction-limited PSF
%
%Create a digital representation of the cubic PSF:
% (We really don't care what the underlying optics
% are here -- the idea is to make a shape-changing filter)
N = 101; %Size of array;
rs = 25; %Size of digital filter (arbitrary)
Psize = .5; %Relative size of pupil in the array (radius)
x = linspace(-1,1,N);
[X,Y] = meshgrid(x,x);
R = sqrt(X.^2 + Y.^2);
%R is now an array with values equal to the distance
% from the center of the N x N array:
%Create a circular, uniform pupil, filling 1/5 the array:
P = zeros(N,N);
P(R<=Psize) = 1;
%Find the diffraction limited PSF and it's OTF:
DFpsf = fftshift(fft2(ifftshift(P)));
DFpsf = DFpsf.*conj(DFpsf);
%Normalize the psf:
DFpsf = DFpsf/sum(sum(DFpsf));
DFotf = fftshift(fft2(ifftshift(DFpsf)));
%Normalize the OTF:
DFotf = DFotf/max(max(abs(DFotf)));
%
figure(1)
subplot(1,2,1)
imagesc(DFpsf),axis image
set(gca,'XTickLabel',[],'YTickLabel',[])
%mesh(DFpsf)
colormap(gray)
title('Diffraction-Limited PSF')
subplot(1,2,2)
imagesc(abs(DFotf)),axis image
set(gca,'XTickLabel',[],'YTickLabel',[])
%mesh(abs(DFotf));
title('Diffraction-Limited MTF')
%
%Add cubic phase to the pupil:
Ac = 2/(Psize^3); %Waves of cubic phase at edge of pupil
C = Ac*(X.^3 + Y.^3);
Pc = P.*exp(i*2*pi*C);
Pc(R>Psize) = 0; %Clip amplitude and phase to actual pupil size.
%
%Find the PSF and OTF for the cubic-phase pupil:
Cpsf = fftshift(fft2(ifftshift(Pc)));
Cpsf = Cpsf.*conj(Cpsf);
%Normalize the PSF:
Cpsf = Cpsf/sum(sum(Cpsf));
Cotf = fftshift(fft2(ifftshift(Cpsf)));
%Normalize Cotf:
Cotf = Cotf/max(max(abs(Cotf)));
%
pg. 5
ECEN 4616/5616
2/4/2013
figure(2)
subplot(1,2,1)
imagesc(Cpsf),axis image
set(gca,'XTickLabel',[],'YTickLabel',[])
%mesh(Cpsf)
colormap(gray)
title('Cubic-Phase PSF')
subplot(1,2,2)
imagesc(abs(Cotf)),axis image
set(gca,'XTickLabel',[],'YTickLabel',[])
%mesh(abs(Cotf));
title('Cubic-Phase MTF')
%
%Make a digital filter to convert the Cubic PSF to a
% diffraction-limited PSF.
%
%************Make Cubic Filter***********************
%Make Filter for Cubic PSF:
%Calculate components for pseudo Weiner Filter:
%NOTE: Cotf can be a weighted sum of OTFs if the filter has to
%
reconstruct a number of similar PSFs.
H = conj(Cotf);
Hsq = Cotf .* conj(Cotf);
%Make Frequency Filter: (Note we are using the Diff-lim OTF
% as a limiting bandwith.)
W = DFotf; %Bandwidth limit of filter
wp = 0.001; %"Weiner parameter" => avoids divide by zero
F = (W .* H) ./ (Hsq + wp);
%F is now the frequency domain filter:
%Long Space Filter:
%IMPORTANT NOTE: The frequency arrays, W,H,Hsq,& F are shifted so
%
that the DC component is in the center. This is fine for
%
display purposes, and even for the filter arithmetic above,
%
but it is NOT OK for the FFT function, which insists on having
%
the DC component at the start of the array. Hence you MUST
%
make sure the array is ordered that way before using any FFT
%
algorithm:
F2 = fftshift(F);
f = real(ifftshift(ifft2(F2)));
%Adjust filter for unity gain:
f_long = f/sum(sum(f));
lng = sum(sum(f.^2)); %Noise gain of long filter
%Truncated Space Filter:
E = (N-rs)*0.5;
E1 = floor(E);
E2 = ceil(E);
rs = [E1:N-E2];
f_short =f(rs,rs);
%
%Display the filters:
figure(3)
subplot(1,2,1)
mesh(f_long)
colormap(gray)
title('Full-Size Space Filter')
subplot(1,2,2)
mesh(f_short)
pg. 6
ECEN 4616/5616
2/4/2013
title('Truncated Space Filter')
%
%Apply the filters to the cubic psf:
f_l_psf = conv2(Cpsf,f_long,'same');
f_s_psf = conv2(Cpsf,f_short,'same');
%
%Display the results:
figure(4)
subplot(1,2,1)
imagesc(f_l_psf),axis image, colormap(gray)
set(gca,'XTickLabel',[],'YTickLabel',[])
title('Filtered PSF (long filter')
subplot(1,2,2)
imagesc(f_s_psf),axis image
set(gca,'XTickLabel',[],'YTickLabel',[])
title('Filtered PSF (short filter')
pg. 7
Download