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 #include <imageanalysis/ImageAnalysis/ImageTask.h>
00032 
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 {
00040 
00041 template <class T> class ImageInterface;
00042 template <class T> class Matrix;
00043 template <class T> class Vector;
00044 class String;
00045 class IPosition;
00046 class CoordinateSystem;
00047 class ImageInfo;
00048 class Unit;
00049 class GaussianBeam;
00050 
00051 // <summary>
00052 // This class does 2D convolution of an image by a functional form
00053 // </summary>
00054 
00055 // <use visibility=export>
00056 
00057 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00058 // </reviewed>
00059 
00060 // <prerequisite>
00061 //   <li> <linkto class="ImageInterface">ImageInterface</linkto>
00062 //   <li> <linkto class="Convolver">Convolver</linkto>
00063 // </prerequisite>
00064 
00065 // <etymology>
00066 // This class handles 2D convolution of images 
00067 // </etymology>
00068 
00069 // <synopsis>
00070 // This class convolves an image by a specified 2D function.
00071 // </synopsis>
00072 
00073 // <example>
00074 // <srcBlock>
00075 // </srcBlock>
00076 // </example>
00077 
00078 // <motivation>
00079 // Convolution is a standard image processing requirement.  The
00080 // class object has no state.
00081 // The convolution is done via FFT.  Thus input pixels which
00082 // are masked are set to 0 before the convolution.  The mask
00083 // is transferred to the output image.  No additional scaling
00084 // of the output image values is done.
00085 // 
00086 // </motivation>
00087 
00088 // <todo asof="2001/08/28">
00089 //   <li> 
00090 // </todo>
00091 
00092 template <class T> class Image2DConvolver : public ImageTask<T> {
00093 public:
00094 
00095         const static String CLASS_NAME;
00096 
00097         Image2DConvolver() = delete;
00098 
00099         Image2DConvolver(
00100                 const SPCIIT image, const Record *const &regionPtr,
00101             const String& mask, const String& outname, const Bool overwrite
00102         );
00103         
00104     Image2DConvolver(const Image2DConvolver<T> &other) = delete;
00105 
00106         ~Image2DConvolver() {}
00107 
00108         Image2DConvolver &operator=(const Image2DConvolver<T> &other) = delete;
00109 
00110         SPIIT convolve();
00111 
00112         // type is a string that starts with "g" (gaussian), "b" (boxcar), or "h" (hanning),
00113         // and is case insensitive
00114         void setKernel(
00115                 const String& type, const Quantity& major, const Quantity& minor,
00116                 const Quantity& pa
00117         );
00118 
00119         void setScale(Double d) { _scale = d; }
00120 
00121         void setAxes(const std::pair<uInt, uInt>& axes);
00122 
00123         void setTargetRes(Bool b) { _targetres = b; }
00124 
00125         String getClass() const { return CLASS_NAME; }
00126 
00127         // if True, do not log certain warning messages which would normally
00128         // be logged during convolution
00129         void setSuppressWarnings(Bool b) { _suppressWarnings = b; }
00130 
00131 protected:
00132 
00133         CasacRegionManager::StokesControl _getStokesControl() const {
00134                 return CasacRegionManager::USE_ALL_STOKES;
00135         }
00136 
00137     vector<Coordinate::Type> _getNecessaryCoordinates() const {
00138         return vector<Coordinate::Type>();
00139     }
00140 
00141     inline Bool _supportsMultipleRegions() const {return True;}
00142 
00143 private:
00144     VectorKernel::KernelTypes _type;
00145     Double _scale;
00146     Quantity _major, _minor, _pa;
00147     IPosition _axes;
00148     Bool _targetres, _suppressWarnings;
00149 
00150         void _checkKernelParameters(
00151                 VectorKernel::KernelTypes kernelType,
00152                 const Vector<Quantity>& parameters
00153         ) const;
00154 
00155         void _convolve(
00156                 LogIO& os, SPIIT imageOut, const ImageInterface<T>& imageIn,
00157                 VectorKernel::KernelTypes kernelType
00158         ) const;
00159 
00160         // returns the value by which pixel values will be scaled
00161         T _dealWithRestoringBeam (
00162                 LogIO& os, String& brightnessUnitOut, GaussianBeam& beamOut,
00163                 const Array<T>& kernelArray, const T kernelVolume,
00164                 const VectorKernel::KernelTypes kernelType,
00165                 const Vector<Quantity>& parameters,
00166                 const CoordinateSystem& cSys,
00167                 const GaussianBeam& beamIn, const Unit& brightnessUnit,
00168                 Bool emitMessage
00169         ) const;
00170 
00171         T _fillKernel (
00172                 Matrix<T>& kernelMatrix,
00173                 VectorKernel::KernelTypes kernelType,
00174                 const IPosition& kernelShape,
00175                 const Vector<Double>& parameters
00176         ) const;
00177 
00178         void _fillGaussian(
00179                 T& maxVal, T& volume, Matrix<T>& pixels,
00180                 T height, T xCentre, T yCentre,
00181                 T majorAxis, T ratio, T positionAngle
00182         ) const;
00183 
00184         T _makeKernel(
00185                 Array<T>& kernel,
00186                 VectorKernel::KernelTypes kernelType,
00187                 const std::vector<Quantity>& parameters,
00188                 const ImageInterface<T>& inImage
00189         ) const;
00190 
00191         IPosition _shapeOfKernel(
00192                 const VectorKernel::KernelTypes kernelType,
00193                 const Vector<Double>& parameters,
00194                 const uInt ndim
00195         ) const;
00196 
00197         uInt _sizeOfGaussian(const Double width, const Double nSigma) const;
00198 
00199         std::vector<Quantity> _getConvolvingBeamForTargetResolution(
00200                 const std::vector<Quantity>& targetBeamParms,
00201                 const GaussianBeam& inputBeam
00202         ) const;
00203 };
00204 
00205 }
00206 
00207 #ifndef CASACORE_NO_AUTO_TEMPLATES
00208 #include <imageanalysis/ImageAnalysis/Image2DConvolver.tcc>
00209 #endif //# CASACORE_NO_AUTO_TEMPLATES
00210 #endif
00211 
00212 
00213 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1