casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Image2DConvolver.h
Go to the documentation of this file.
00001 //# Image2DConvolver.h: 2D convolution of an image
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
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: Image2DConvolver.h 20229 2008-01-29 15:19:06Z gervandiepen $
00027 
00028 #ifndef IMAGES_IMAGE2DCONVOLVER_H
00029 #define IMAGES_IMAGE2DCONVOLVER_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Logging/LogIO.h>
00035 #include <casa/Arrays/Array.h>
00036 #include <scimath/Mathematics/VectorKernel.h>
00037 #include <casa/Quanta/Quantum.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //# Forward Declarations
00042 template <class T> class ImageInterface;
00043 template <class T> class Matrix;
00044 template <class T> class Vector;
00045 class String;
00046 class IPosition;
00047 class CoordinateSystem;
00048 class ImageInfo;
00049 class Unit;
00050 class GaussianBeam;
00051 
00052 
00053 // <summary>
00054 // This class does 2D convolution of an image by a functional form
00055 // </summary>
00056 
00057 // <use visibility=export>
00058 
00059 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00060 // </reviewed>
00061 
00062 // <prerequisite>
00063 //   <li> <linkto class="ImageInterface">ImageInterface</linkto>
00064 //   <li> <linkto class="Convolver">Convolver</linkto>
00065 // </prerequisite>
00066 
00067 // <etymology>
00068 // This class handles 2D convolution of images 
00069 // </etymology>
00070 
00071 // <synopsis>
00072 // This class convolves an image by a specified 2D function.
00073 // </synopsis>
00074 
00075 // <example>
00076 // <srcBlock>
00077 // </srcBlock>
00078 // </example>
00079 
00080 // <motivation>
00081 // Convolution is a standard image processing requirement.  The
00082 // class object has no state.
00083 // The convolution is done via FFT.  Thus input pixels which
00084 // are masked are set to 0 before the convolution.  The mask
00085 // is transferred to the output image.  No additional scaling
00086 // of the output image values is done.
00087 // 
00088 // </motivation>
00089 
00090 // <todo asof="2001/08/28">
00091 //   <li> 
00092 // </todo>
00093  
00094 
00095 template <class T> class Image2DConvolver
00096 {
00097 public:
00098 
00099         // Convolve.   If the output image needs a mask and doesn't have one,
00100         // it will be given one if possible.  The miscInfo, imageInfo,
00101         // units and logger will be copied from the input to the output
00102         // unless you indicate not to (copyMiscellaneous).
00103         static void convolve(
00104                 LogIO& os, ImageInterface<T>& imageOut,
00105                 const ImageInterface<T>& imageIn,
00106                 const VectorKernel::KernelTypes kernelType,
00107                 const IPosition& pixelAxes,
00108                 const Vector<Quantity>& parameters,
00109                 const Bool autoScale, const Double scale,
00110                 const Bool copyMiscellaneous=True,
00111                 const Bool targetres=False
00112         );
00113 
00114 private:
00115 
00116         // This class contains all static methods. Do not allow it to
00117         // be instantiated.
00118         // Constructor
00119         Image2DConvolver ();
00120 
00121         // Copy constructor.  Uses reference semantics.
00122         Image2DConvolver(const Image2DConvolver<T> &other);
00123 
00124         // Destructor
00125         ~Image2DConvolver();
00126 
00127         // Assignment operator. Uses reference semantics.
00128         Image2DConvolver &operator=(const Image2DConvolver<T> &other);
00129 
00130 
00131         static void _checkKernelParameters(
00132                 LogIO& os, VectorKernel::KernelTypes kernelType,
00133                 const Vector<Quantum<Double> >& parameters
00134         );
00135 
00136         static void _dealWithRestoringBeam (
00137                 LogIO& os, String& brightnessUnitOut, GaussianBeam& beamOut,
00138                 Array<T>& kernelArray, const T kernelVolume,
00139                 const VectorKernel::KernelTypes kernelType,
00140                 const Vector<Quantity>& parameters,
00141                 const IPosition& axes, const CoordinateSystem& cSys,
00142                 const GaussianBeam& beamIn, const Unit& brightnessUnit,
00143                 const Bool autoscale, const Double scale, const Bool emitMessage
00144         );
00145 
00146         static T _fillKernel (
00147                 Matrix<T>& kernelMatrix,
00148                 VectorKernel::KernelTypes kernelType,
00149                 const IPosition& kernelShape,
00150                 const IPosition& axes,
00151                 const Vector<Double>& parameters
00152         );
00153 
00154         static void fillGaussian(
00155                 T& maxVal, T& volume, Matrix<T>& pixels,
00156                 T height, T xCentre, T yCentre,
00157                 T majorAxis, T ratio, T positionAngle
00158         );
00159 
00160         static T _makeKernel(
00161                 LogIO& os, Array<T>& kernel,
00162                 VectorKernel::KernelTypes kernelType,
00163                 const Vector<Quantity>& parameters,
00164                 const IPosition& axes,
00165                 const ImageInterface<T>& inImage
00166         );
00167 
00168         static IPosition shapeOfKernel(
00169                 const VectorKernel::KernelTypes kernelType,
00170                 const Vector<Double>& parameters,
00171                 const uInt ndim, const IPosition& axes
00172         );
00173 
00174         static uInt sizeOfGaussian(const Double width, const Double nSigma);
00175 
00176         static Vector<Quantity> _getConvolvingBeamForTargetResolution(
00177                 LogIO& os, const Vector<Quantity>& targetBeamParms,
00178                 const GaussianBeam& inputBeam
00179         );
00180 };
00181 
00182 
00183 
00184 } //# NAMESPACE CASA - END
00185 
00186 #ifndef CASACORE_NO_AUTO_TEMPLATES
00187 #include <imageanalysis/ImageAnalysis/Image2DConvolver.tcc>
00188 #endif //# CASACORE_NO_AUTO_TEMPLATES
00189 #endif
00190 
00191 
00192