casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageFFT.h
Go to the documentation of this file.
1 //# ImageFFT.h: FFT an image
2 //# Copyright (C) 1996,1997,1998,1999,2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: ImageFFT.h 20291 2008-03-21 07:19:34Z gervandiepen $
27 
28 #ifndef IMAGES_IMAGEFFT_H
29 #define IMAGES_IMAGEFFT_H
30 
31 #include <casa/aips.h>
33 
35 
36 namespace casacore {
37 
38 class CoordinateSystem;
39 class IPosition;
40 template<class T> class Vector;
41 }
42 
43 namespace casa {
44 
45 // <summary>
46 // FFT an image
47 // </summary>
48 
49 // <use visibility=export>
50 
51 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
52 // </reviewed>
53 
54 // <prerequisite>
55 // <li> <linkto class=casacore::LatticeFFT>LatticeFFT</linkto>
56 // <li> <linkto class=casacore::ImageInterface>ImageInterface</linkto>
57 // <li> <linkto class=casacore::TempImage>TempImage</linkto>
58 // </prerequisite>
59 
60 // <etymology>
61 // Take the fast Fourier Transform of an image.
62 // </etymology>
63 
64 // <synopsis>
65 // This class takes the FFT of an image. It can
66 // take the FFT of just the sky plane(s) of an image or
67 // the specified axes.
68 //
69 // When you specify axes, if any of them are a sky axis (casacore::DirectionCoordinate)
70 // you must give both sky axes.
71 //
72 // Masked pixels are given the value 0.0 before the FFT is taken and the
73 // mask is copied to the output. Note that it is the callers responsibility
74 // to give the output a mask if the input is masked. Otherwise the mask
75 // will not be copied to the output
76 //
77 // This class holds the FourierTransform internally in a
78 // <linkto class=casacore::TempImage>TempImage</linkto> object. This is
79 // in memory or on disk depending upon its size and the amount
80 // of memory in your computer. The algorithm used
81 // is that in <linkto class=casacore::TempLattice>TempLattice</linkto>.
82 //
83 // In generating the Fourier Coordinates, it is currently
84 // assumed that there is no coordinate rotation. This
85 // needs to be dealt with.
86 // </synopsis>
87 //
88 // <example>
89 // <srcblock>
90 //
91 // // Make a constant image
92 //
93 // casacore::IPosition shape(2, 10, 20);
94 // casacore::PagedImage<casacore::Float> im1(shape, casacore::CoordinateUtil::defaultCoords2D(), "im1");
95 // im1.set(1.0);
96 //
97 // // Create output images with masks if needed
98 //
99 // casacore::PagedImage<casacore::Float> r1(shape, casacore::CoordinateUtil::defaultCoords2D(), "real1");
100 // casacore::PagedImage<casacore::Float> i1(shape, casacore::CoordinateUtil::defaultCoords2D(), "imag1");
101 // if (im1.isMasked()) {
102 // casacore::LCPagedMask mask1 = casacore::LCPagedMask(casacore::RegionHandler::makeMask (r1, "mask0"));
103 // mask1.set(true);
104 // r1.defineRegion ("mask0", casacore::ImageRegion(mask1), casacore::RegionHandler::Masks);
105 // r1.setDefaultMask("mask0");
106 // casacore::LCPagedMask mask2 = casacore::LCPagedMask(casacore::RegionHandler::makeMask (i1, "mask0"));
107 // mask2.set(true);
108 // i1.defineRegion ("mask0", casacore::ImageRegion(mask1), casacore::RegionHandler::Masks);
109 // i1.setDefaultMask("mask0");
110 // }
111 // //
112 // // FFT
113 //
114 // ImageFFT fft;
115 // fft.fftsky(im1);
116 //
117 // // The coordinates and mask will be updated
118 //
119 // fft.getReal(r1);
120 // fft.getImag(i1);
121 // </srcblock>
122 // </example>
123 
124 
125 // <motivation>
126 // Taking the Fourier Transform of an image is a basic part of image analysis
127 // </motivation>
128 
129 // <todo asof="1999/09/23">
130 // <li> reverse transformations
131 // </todo>
132 
133 
134 template <class T> class ImageFFT {
135 public:
136 
137  using ComplexType
138  = std::complex<typename casacore::NumericTraits<T>::BaseType>;
139 
141 
142  ImageFFT ();
143 
144  ImageFFT(const ImageFFT& other);
145 
146  // Assignment (reference semantics)
147  ImageFFT& operator=(const ImageFFT& other);
148 
149  ~ImageFFT();
150 
151  // Do the FFT of the sky plane to the uv plane
152  // Masked pixels are set to zero before the FT
153  void fftsky(const casacore::ImageInterface<T>& in);
154 
155  // Do the FFT of the specified pixel axes (true to FT).
156  // The rest are iterated over.
157  // Masked pixels are set to zero before the FT
158  void fft (
159  const casacore::ImageInterface<T>& in,
161  );
162 
163  // Return the FFT (from the last call to fftsky or fft) in the
164  // desired form. The casacore::CoordinateSystem, MiscInfo, casacore::ImageInfo,
165  // history and units are copied/updated in the output image
166  // from the image that was FFTd. If the input image is masked,
167  // and the output image has a writable mask, the mask will
168  // be transferred. Any output mask should be initialized to
169  // true before calling these functions.
170  // <group>
172 
174 
176 
178 
180  // </group>
181 
182 private:
184  SPIIT _image = nullptr;
186 
187  // Check axes for multi-dim FFT
188  void checkAxes(
191  );
192 
193  // Copy the mask to the output
194  template <class U> static void _copyMask(
196  );
197 
198  // Copy MiscInfo, casacore::ImageInfo, casacore::Unit, logSInk to output
199  template <class U> void _copyMiscellaneous(
201  ) const;
202 
203  // common image copy stuff
204  template <class U> void _copyMost(casacore::ImageInterface<U>& out) const;
205 
206  // U must be a complex type (Complex, DComplex)
207  template <class U> static void _fftsky(
209  const casacore::ImageInterface<T>& in,
210  const casacore::Vector<casacore::Int>& pixelAxes
211  );
212 
213  // U must be a complex type (Complex, DComplex)
214  template <class U> static void _fft(
216  const casacore::ImageInterface<T>& in,
218  );
219 
220  // Find the sky axes in this CoordinateSystem
221  static casacore::Bool _findSky(
224  const casacore::CoordinateSystem& cSys, casacore::Bool throwIt
225  );
226 
227  // Overwrite the coordinate system with
228  // Fourier coordinates for sky axes only
229  static void _setSkyCoordinates (
231  const casacore::CoordinateSystem& csys,
233  );
234 
235  // Overwrite the coordinate system with Fourier coordinates for all
236  // designated axes
237  void _setCoordinates (
239  const casacore::CoordinateSystem& cSys,
242  );
243 };
244 
245 } //# NAMESPACE CASA - END
246 
247 #ifndef AIPS_NO_TEMPLATE_SRC
248 #include <imageanalysis/ImageAnalysis/ImageFFT.tcc>
249 #endif
250 
251 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
int Int
Definition: aipstype.h:50
std::vector< double > Vector
Definition: ds9context.h:24
static void _setSkyCoordinates(casacore::ImageInterface< ComplexType > &out, const casacore::CoordinateSystem &csys, const casacore::IPosition &shape, casacore::uInt dC)
Overwrite the coordinate system with Fourier coordinates for sky axes only.
static void _fft(casacore::ImageInterface< U > &out, const casacore::ImageInterface< T > &in, const casacore::Vector< casacore::Bool > &axes)
U must be a complex type (Complex, DComplex)
void getAmplitude(casacore::ImageInterface< RealType > &out) const
void _copyMost(casacore::ImageInterface< U > &out) const
common image copy stuff
static void _copyMask(casacore::ImageInterface< U > &out, const casacore::ImageInterface< T > &in)
Copy the mask to the output.
void fft(const casacore::ImageInterface< T > &in, const casacore::Vector< casacore::Bool > &axes)
Do the FFT of the specified pixel axes (true to FT).
#define SPIICT
Definition: ImageTypedefs.h:40
void getComplex(casacore::ImageInterface< ComplexType > &out) const
Return the FFT (from the last call to fftsky or fft) in the desired form.
void _copyMiscellaneous(casacore::ImageInterface< U > &out) const
Copy MiscInfo, casacore::ImageInfo, casacore::Unit, logSInk to output.
A base class for astronomical images.
#define SPIIT
Definition: ImageTypedefs.h:34
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
void checkAxes(const casacore::CoordinateSystem &cSys, casacore::uInt ndim, const casacore::Vector< casacore::Bool > &axes)
Check axes for multi-dim FFT.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
ImageFFT & operator=(const ImageFFT &other)
Assignment (reference semantics)
typename casacore::NumericTraits< T >::BaseType RealType
Definition: ImageFFT.h:140
static casacore::Bool _findSky(casacore::Int &dC, casacore::Vector< casacore::Int > &pixelAxes, casacore::Vector< casacore::Int > &worldAxes, const casacore::CoordinateSystem &cSys, casacore::Bool throwIt)
Find the sky axes in this CoordinateSystem.
FFT an image.
Definition: ImageFFT.h:134
void getPhase(casacore::ImageInterface< RealType > &out) const
const Bool False
Definition: aipstype.h:44
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
void getReal(casacore::ImageInterface< RealType > &out) const
SPIIT _image
Definition: ImageFFT.h:184
std::complex< typename casacore::NumericTraits< T >::BaseType > ComplexType
Definition: ImageFFT.h:138
static void _fftsky(casacore::ImageInterface< U > &out, const casacore::ImageInterface< T > &in, const casacore::Vector< casacore::Int > &pixelAxes)
U must be a complex type (Complex, DComplex)
casacore::Bool _done
Definition: ImageFFT.h:185
void getImaginary(casacore::ImageInterface< RealType > &out) const
Char BaseType
Numeric type.
void fftsky(const casacore::ImageInterface< T > &in)
Do the FFT of the sky plane to the uv plane Masked pixels are set to zero before the FT...
SPIICT _tempImagePtr
Definition: ImageFFT.h:183
void _setCoordinates(casacore::ImageInterface< ComplexType > &out, const casacore::CoordinateSystem &cSys, const casacore::Vector< casacore::Bool > &axes, const casacore::IPosition &shape)
Overwrite the coordinate system with Fourier coordinates for all designated axes. ...
Interconvert pixel and world coordinates.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42