casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageFFT.h
Go to the documentation of this file.
00001 //# ImageFFT.h: FFT an image
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: ImageFFT.h 20291 2008-03-21 07:19:34Z gervandiepen $
00027 
00028 #ifndef IMAGES_IMAGEFFT_H
00029 #define IMAGES_IMAGEFFT_H
00030 
00031 #include <casa/aips.h>
00032 #include <images/Images/ImageInterface.h>
00033 
00034 namespace casa { //# NAMESPACE CASA - BEGIN
00035 
00036 class CoordinateSystem;
00037 class IPosition;
00038 template<class T> class Vector;
00039 
00040 // <summary>
00041 // FFT an image
00042 // </summary>
00043 
00044 // <use visibility=export>
00045 
00046 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <linkto class=LatticeFFT>LatticeFFT</linkto> 
00051 //   <li> <linkto class=ImageInterface>ImageInterface</linkto> 
00052 //   <li> <linkto class=TempImage>TempImage</linkto> 
00053 // </prerequisite>
00054 
00055 // <etymology>
00056 // Take the fast Fourier Transform of an image.
00057 // </etymology>
00058 
00059 // <synopsis>
00060 // This class takes the FFT of an image.  It can
00061 // take the FFT of just the sky plane(s) of an image or
00062 // the specified axes.
00063 //
00064 // When you specify axes, if any of them are a sky axis (DirectionCoordinate)
00065 // you must give both sky axes.
00066 //
00067 // Masked pixels are given the value 0.0 before the FFT is taken and the
00068 // mask is copied to the output.  Note that it is the callers responsibility
00069 // to give the output a mask if the input is masked.  Otherwise the mask
00070 // will not be copied to the output
00071 //
00072 // This class holds the FourierTransform internally in a 
00073 // <linkto class=TempImage>TempImage</linkto> object.  This is
00074 // in memory or on disk depending upon its size and the amount
00075 // of memory in your computer.    The algorithm used
00076 // is that in <linkto class=TempLattice>TempLattice</linkto>.
00077 //
00078 // In generating the Fourier Coordinates, it is currently
00079 // assumed that there is no coordinate rotation.  This 
00080 // needs to be dealt with.
00081 // </synopsis>
00082 //
00083 // <example>
00084 // <srcblock>
00085 //
00086 // // Make a constant image
00087 //
00088 //      IPosition shape(2, 10, 20);
00089 //      PagedImage<Float> im1(shape, CoordinateUtil::defaultCoords2D(), "im1");
00090 //      im1.set(1.0);
00091 //
00092 // // Create output images with masks if needed
00093 //
00094 //      PagedImage<Float> r1(shape, CoordinateUtil::defaultCoords2D(), "real1");
00095 //      PagedImage<Float> i1(shape, CoordinateUtil::defaultCoords2D(), "imag1");
00096 //      if (im1.isMasked()) {
00097 //         LCPagedMask mask1 = LCPagedMask(RegionHandler::makeMask (r1, "mask0"));
00098 //         mask1.set(True);
00099 //         r1.defineRegion ("mask0", ImageRegion(mask1), RegionHandler::Masks);
00100 //         r1.setDefaultMask("mask0");
00101 //         LCPagedMask mask2 = LCPagedMask(RegionHandler::makeMask (i1, "mask0"));
00102 //         mask2.set(True);
00103 //         i1.defineRegion ("mask0", ImageRegion(mask1), RegionHandler::Masks);
00104 //         i1.setDefaultMask("mask0");
00105 //      }
00106 // //
00107 // // FFT
00108 //
00109 //      ImageFFT fft;
00110 //      fft.fftsky(im1);
00111 //
00112 // // The coordinates and mask will be updated
00113 //
00114 //      fft.getReal(r1);
00115 //      fft.getImag(i1);
00116 // </srcblock>
00117 // </example>
00118 
00119 
00120 // <motivation>
00121 // Taking the Fourier Transform of an image is a basic part of image analysis
00122 // </motivation>
00123 
00124 // <todo asof="1999/09/23">
00125 //   <li> reverse transformations
00126 // </todo>
00127 
00128 
00129 class ImageFFT 
00130 {
00131 public:
00132 
00133 // Default constructor
00134    ImageFFT ();
00135 
00136 // Copy constructor (reference semantics)
00137    ImageFFT(const ImageFFT& other);
00138 
00139 // Assignment (reference semantics)
00140    ImageFFT& operator=(const ImageFFT& other);
00141 
00142 // Destructor
00143    ~ImageFFT();
00144 
00145 // Do the FFT of the sky plane to the uv plane
00146 // Masked pixels are set to zero before the FT
00147    void fftsky (const ImageInterface<Float>& in);
00148 
00149 // Do the FFT of the specified pixel axes (True to FT).  
00150 // The rest are iterated over.
00151 // Masked pixels are set to zero before the FT
00152    void fft (const ImageInterface<Float>& in, 
00153              const Vector<Bool>& axes);
00154 
00155 // Do the FFT of the specified pixel axes (True to FT).  
00156 // The rest are iterated over
00157 // Masked pixels are set to zero before the FT
00158    void fft (const ImageInterface<Complex>& in, 
00159              const Vector<Bool>& axes);
00160 
00161 // Return the FFT (from the last call to fftsky or fft) in the 
00162 // desired form.    The CoordinateSystem, MiscInfo, ImageInfo,
00163 // history and units are copied/updated in the output image
00164 // from the image that was FFTd.   If the input image is masked,
00165 // and the output image has a writable mask, the mask will
00166 // be transferred. Any output mask should be initialized to
00167 // True before calling these functions.
00168 // <group>
00169    void getComplex (ImageInterface<Complex>& out) const;
00170    void getReal (ImageInterface<Float>& out) const;
00171    void getImaginary (ImageInterface<Float>& out) const;
00172    void getAmplitude (ImageInterface<Float>& out) const;
00173    void getPhase (ImageInterface<Float>& out) const;
00174 // </group>
00175 
00176 private:
00177 
00178    ImageInterface<Complex>* itsTempImagePtr;
00179    ImageInterface<Float>* itsInImagePtrFloat;
00180    ImageInterface<Complex>* itsInImagePtrComplex;
00181    Bool itsDone;
00182 
00183 // Check axes for multi-dim FFT
00184    void checkAxes(const CoordinateSystem& cSys, uInt ndim, 
00185                   const Vector<Bool>& axes);
00186 
00187 // Copy the  mask to the output
00188    void copyMask (ImageInterface<Float>& out) const;
00189    void copyMask (ImageInterface<Complex>& out) const;
00190    void copyMask (ImageInterface<Float>& out,
00191                   const ImageInterface<Float>& in) const;
00192    void copyMask (ImageInterface<Float>& out,
00193                   const ImageInterface<Complex>& in) const;
00194    void copyMask (ImageInterface<Complex>& out,
00195                   const ImageInterface<Float>& in) const;
00196    void copyMask (ImageInterface<Complex>& out,
00197                   const ImageInterface<Complex>& in) const;
00198 
00199 // Copy MiscInfo, ImageInfo, Unit, logSInk to output
00200 // <group>
00201    void copyMiscellaneous (ImageInterface<Float>& out) const;
00202    void copyMiscellaneous (ImageInterface<Complex>& out) const;
00203 // </group>
00204 
00205 // FFT the sky
00206    void fftsky2 (ImageInterface<Complex>& out,
00207                  const ImageInterface<Float>& in,
00208                  const Vector<Int>& pixelAxes);
00209 
00210 // FFT (Float) given axes
00211    void fft2(ImageInterface<Complex>& out,
00212              const ImageInterface<Float>& in,
00213              const Vector<Bool>& axes);
00214 
00215 // FFT (Complex) given axes
00216    void fft3(ImageInterface<Complex>& out,
00217              const ImageInterface<Complex>& in,
00218              const Vector<Bool>& axes);
00219 
00220 // Find the sky axes in this CoordinateSystem
00221    Bool findSky(LogIO& os, Int& dC, Vector<Int>& pixelAxes,
00222                 Vector<Int>& worldAxes, const CoordinateSystem& cSys,
00223                 Bool throwIt);
00224 
00225 // Overwrite the coordinate system with Fourier coordinates for sky axes only
00226    void setSkyCoordinates (LogIO& os, ImageInterface<Complex>& out,
00227                            const ImageInterface<Float>& in,
00228                            uInt dC);
00229 
00230 // Overwrite the coordinate system with Fourier coordinates for all desginated axes
00231    void setCoordinates (LogIO& os,
00232                         ImageInterface<Complex>& out,
00233                         const CoordinateSystem& cSys,
00234                         const Vector<Bool>& axes,
00235                         const IPosition& shape);
00236 };
00237 
00238 } //# NAMESPACE CASA - END
00239 
00240 #endif