IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11722


Ignore:
Timestamp:
Feb 8, 2007, 3:19:43 PM (19 years ago)
Author:
Paul Price
Message:

Updating APIs for FFT and image convolution to match newly implemented version.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r11598 r11722  
    1 %%% $Id: psLibSDRS.tex,v 1.440 2007-02-03 00:13:08 eugene Exp $
     1%%% $Id: psLibSDRS.tex,v 1.441 2007-02-09 01:19:43 price Exp $
    22\documentclass[panstarrs,spec]{panstarrs}
    33
     
    64356435
    64366436We require the ability to calculate the (fast) Fourier transforms of
    6437 floating-point one-dimensional vectors and two-dimensional images.  We
    6438 expect that these will be implemented through wrapping an external
    6439 library.  We define the following APIs to support FFT operations on vectors:
    6440 
    6441 \begin{prototype}
    6442 psVector *psVectorFFT(psVector *out, const psVector *in, psFFTFlags direction);
    6443 psVector *psVectorReal(psVector *out, const psVector *in);
    6444 psVector *psVectorImaginary(psVector *out, const psVector *in);
    6445 psVector *psVectorComplex(psVector *out, const psVector *real, const psVector *imag);
    6446 psVector *psVectorConjugate(psVector *out, const psVector *in);
     6437floating-point one-dimensional vectors and two-dimensional images.
     6438These will be implemented through wrapping an external library.  We
     6439expect that we shall only want to deal with purely real vectors and
     6440images, rather than complex; this can save operations when performing
     6441the FFT (roughly a factor of 2).  We define the following APIs to
     6442support FFT operations on vectors:
     6443
     6444\begin{prototype}
     6445bool psVectorForwardFFT(psVector **real psVector **imag, const psVector *in);
     6446bool psVectorBackwardFFT(psVector **out, const psVector *real, const psVector *imag, int origNum);
    64476447psVector *psVectorPowerSpectrum(psVector *out, const psVector *in);
    6448 \end{prototype}
    6449 
    6450 The forward and reverse FFT is calculated using \code{psVectorFFT},
    6451 which takes as input the vector of interest (\code{in}) and the
    6452 direction (\code{direction}), which is specified by an enumerated type
    6453 defined below.  The input vector may be of type \code{psF32} or
    6454 \code{psC32}, the result is always \code{psC32}.  If the input vector
    6455 is \code{psF32}, the direction must be forward.  Neither the forward
    6456 or inverse transforms must multiply by $1/N$ (or $1/N^{1/2}$), and so
    6457 it falls to the responsibility of the user to multiply a vector that
    6458 has been forward- and reverse-transformed by $1/N$.
    6459 
    6460 Conversions between complex and real vectors requires the functions
    6461 \code{psVectorReal}, which returns the real part (\code{psF32}) of the
    6462 complex vector \code{in}, \code{psVectorImaginary}, which returns the
    6463 the magnitude of the imaginary part (\code{psF32}) of the complex
    6464 vector \code{in}, and \code{psVectorComplex}, which constructs a
    6465 complex vector (\code{psC32}) from the real and imaginary components
    6466 \code{real} and \code{imag}, both of type \code{psF32}.
    6467 
    6468 We also specify the additional utility functions
    6469 \code{psVectorConjugate} and \code{psVectorPowerSpectrum} which
    6470 construct the complex conjugate (\code{psC32}) and the magnitude
    6471 (\code{psF32}) vectors of the input complex vector (\code{psC32}).
    6472 
    6473 The direction of an FFT performed by \code{psVectorFFT} is specified
    6474 by an enumerated type, \code{psFFTFlags}:
    6475 
    6476 \begin{datatype}
    6477 /** Specify direction of FFT, and if the result is real or not */
    6478 typedef enum {
    6479     PS_FFT_FORWARD = 1,                 ///< psImageFFT/psVectorFFT should perform a forward FFT.
    6480     PS_FFT_REVERSE = 2,                 ///< psImageFFT/psVectorFFT should perform a reverse FFT.
    6481     PS_FFT_REAL_RESULT = 4              ///< psImageFFT/psVectorFFT should return a real image. This is valid
    6482                                         ///< for only reverse FFT, i.e., the psImageFFT/psVectorFFT flag
    6483                                         ///< parameter should appear as PS_FFT_REVERSE+PS_FFT_REAL_RESULT.
    6484 } psFFTFlags;
    6485 \end{datatype}
    6486 
    6487 The entry \code{PS_FFT_REAL_RESULT} means that the output of an
    6488 inverse FFT is to be purely real.  An example of its use is:
    6489 \begin{verbatim}
    6490 out = psImageFFT(in, PS_FFT_REVERSE | PS_FFT_REAL_RESULT);
    6491 \end{verbatim}
    6492 
    6493 The output from a FFT must be of the same size as the input, and the
    6494 size of the power spectrum equal to $N/2 + 1$, where $N$ is the number
    6495 of elements in the input.  In the future, if this adversely affects
    6496 performance, this will be revised so that the redundant information
    6497 will be neglected.
     6448bool psVectorComplexMultiply(psVector **outReal, psVector **outImag,
     6449                             const psVector *in1Real, const psVector *in1Imag,
     6450                             const psVector *in2Real, const psVector *in2Imag);
     6451\end{prototype}
     6452
     6453We might have chosen to use the \code{complex} types that C99
     6454provides, but unfortunately this isn't implemented on all the systems
     6455that we would have desired.  Instead, we use separate vectors
     6456to carry the real and imaginary parts.
     6457
     6458The forward FFT (exponent $-1$) is calculated using
     6459\code{psVectorForwardFFT}, which takes as input the vector of interest
     6460(\code{in}) of type F32, returning the \code{real} and
     6461\code{imaginary} parts in separate vectors, which are allocated if
     6462required.
     6463
     6464The backward FFT (exponent $+1$) is calculated using
     6465\code{psVectorBackwardFFT}, which takes as input the \code{real} and
     6466\code{imaginary} parts, each of type F32, and returns the purely real
     6467\code{out} vector, which is allocated if required.  Due to the
     6468ambiguity in the size of the original vector when the purely real
     6469optimisation is made, this function also requires the number of
     6470elements, \code{origNum} in the original vector before FFT-ing with
     6471\code{psVectorForwardFFT}.
     6472
     6473Note that the FFTs are not normalised, and so it falls to the
     6474responsibility of the user to multiply a vector that has been forward-
     6475and reverse-transformed by $1/N$.
     6476
     6477\code{psVectorPowerSpectrum} calculates the power spectrum (magnitude
     6478of the fourier transform) from the \code{in} vector (of type F32.
     6479
     6480Finally, for convenience, the function \code{psVectorComplexMultiply}
     6481is provided to multiply two vectors of complex numbers which are
     6482specified by their real and imaginary parts, and returning the real
     6483and imaginary parts separately.
    64986484
    64996485In analogy with the vector FFT operations, we also define matching
    65006486image operations as follows:
    65016487\begin{prototype}
    6502 psImage *psImageFFT(psImage *out, const psImage *image, psFFTFlags direction);
    6503 psImage *psImageReal(psImage *out, const psImage *in);
    6504 psImage *psImageImaginary(psImage *out, const psImage *in);
    6505 psImage *psImageComplex(psImage *out, const psImage *real, const psImage *imag);
    6506 psImage *psImageConjugate(psImage *out, const psImage *in);
     6488bool psImageForwardFFT(psImage **real psImage **imag, const psImage *in);
     6489bool psImageBackwardFFT(psImage **out, const psImage *real, const psImage *imag, int origCols);
    65076490psImage *psImagePowerSpectrum(psImage *out, const psImage *in);
    6508 \end{prototype}
     6491bool psImageComplexMultiply(psImage **outReal, psImage **outImag,
     6492                             const psImage *in1Real, const psImage *in1Imag,
     6493                             const psImage *in2Real, const psImage *in2Imag);
     6494\end{prototype}
     6495
     6496The only subtle difference is in \code{psImageBackwardFFT}, where the
     6497number of columns in the original image (before applying
     6498\code{psImageForwardFFT}) is required due to the ambiguity arising
     6499from the optimisation made for purely real data.  Note that the number
     6500of rows need not be provided, because the FFT-ed image is shrunk in
     6501the columns but not the rows.
    65096502
    65106503%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    66126605\subsubsection{Convolve an image with the kernel}
    66136606
    6614 Given an input image and the convolution kernel,
    6615 \code{psImageConvolve} shall convolve the input image,
    6616 \code{in}, with the kernel, \code{kernel} and return the convolved
    6617 image, \code{out}.  The API shall be the following:
    6618 \begin{prototype}
    6619 psImage *psImageConvolve(psImage *out, const psImage *in,
    6620                          const psKernel *kernel, bool direct);
    6621 \end{prototype}
    6622 
    6623 Two methods shall be available for the convolution: if \code{direct}
    6624 is \code{true}, then the convolution shall be performed in real space
    6625 (appropriate for small kernels); otherwise, the convolution shall be
    6626 performed using Fast Fourier Transforms (FFTs; appropriate for larger
    6627 kernels).  The latter option involves padding the input image, copying
    6628 the kernel into an image of the same size as the padded input image,
    6629 performing an FFT on each, multiplying the FFTs, and performing an
    6630 inverse FFT before trimming the image back to the original size.
     6607Two methods are available for the convolution: direct and FFT.  Given
     6608an input image and the convolution kernel,
     6609\code{psImageConvolveDirect} and \code{psImageConvolveFFT} shall
     6610convolve the input image, \code{in}, with the kernel, \code{kernel}
     6611and return the convolved image, \code{out}.  The APIs shall be the
     6612following:
     6613\begin{prototype}
     6614psImage *psImageConvolveDirect(psImage *out, const psImage *in,
     6615                              const psKernel *kernel);
     6616psImage *psImageConvolveFFT(psImage *out, const psImage *in,
     6617                            const psKernel *kernel);
     6618\end{prototype}
     6619
     6620\code{psImageConvolveDirect} shall perform the convolution in real
     6621space (appropriate for small kernels); \code{psImageConvolveFFT} shall
     6622perform the convolution using Fast Fourier Transforms (FFTs;
     6623appropriate for larger kernels).  The latter option involves padding
     6624the input image, copying the kernel into an image of the same size as
     6625the padded input image, performing an FFT on each, multiplying the
     6626FFTs, and performing an inverse FFT before trimming the image back to
     6627the original size.
    66316628
    66326629In the event that \code{out} is \code{NULL}, a new \code{psImage}
Note: See TracChangeset for help on using the changeset viewer.