casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SepImageConvolver.h
Go to the documentation of this file.
00001 //# SepImageConvolver.h: separable 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: SepImageConvolver.h 20229 2008-01-29 15:19:06Z gervandiepen $
00027 
00028 #ifndef IMAGES_SEPIMAGECONVOLVER_H
00029 #define IMAGES_SEPIMAGECONVOLVER_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Logging/LogIO.h>
00035 #include <casa/Arrays/Vector.h>
00036 #include <casa/Containers/Block.h>
00037 #include <images/Images/ImageInterface.h>
00038 #include <scimath/Mathematics/VectorKernel.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 //# Forward Declarations
00043 template <class T> class Quantum;
00044 class String;
00045 
00046 
00047 
00048 // <summary>
00049 // This class does separable convolution of an image
00050 // </summary>
00051 
00052 // <use visibility=export>
00053 
00054 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00055 // </reviewed>
00056 
00057 // <prerequisite>
00058 //   <li> <linkto class="ImageInterface">ImageInterface</linkto>
00059 //   <li> <linkto class="Convolver">Convolver</linkto>
00060 // </prerequisite>
00061 
00062 // <etymology>
00063 // This class handles convolution of images by separable kernels.
00064 // </etymology>
00065 
00066 // <synopsis>
00067 // Convolution kernels can be separable or not.  For example,
00068 // convolution of an image by a 2-D gaussian when the position angle
00069 // of the Gaussian is along one of the axes is separable. If the
00070 // position angle is otherwise, it is not separable.   When the
00071 // kernel is separable, an N-dimensional specification of the
00072 // convolution kernel is straightforward.
00073 //
00074 // Although this class is templated, it will only work
00075 // for Float and Double types.
00076 // </synopsis>
00077 
00078 // <example>
00079 // <srcBlock>
00080 // </srcBlock>
00081 // </example>
00082 
00083 // <motivation>
00084 // Separable and non-separable convolution are standard requirements.
00085 // </motivation>
00086 
00087 // <todo asof="1999/03/31">
00088 //   <li> 
00089 // </todo>
00090  
00091 
00092 template <class T> class SepImageConvolver
00093 {
00094 public:
00095 
00096 
00097 // Constructor 
00098    SepImageConvolver (ImageInterface<T>& image, LogIO &os, Bool showProgress);
00099 
00100 // Copy constructor.  Uses reference semantics.
00101    SepImageConvolver(const SepImageConvolver<T> &other);
00102 
00103 // Destructor
00104   ~SepImageConvolver();
00105 
00106 // Assignment operator. Uses reference semantics.
00107    SepImageConvolver &operator=(const SepImageConvolver<T> &other);
00108 
00109 // Set convolution kernel vector.  The specified axis is convolved
00110 // by the given kernel.
00111    void setKernel(uInt axis, const Vector<T>& kernel);
00112 
00113 // Set convolution kernel.  The specified axis is convolved
00114 // by the given kernel.  If autoScale is True then kernel volume is unity,
00115 // else kernel peak is 1 * scale. If useImageShapeExactly is True, the kernel
00116 // will be the shape of the axis, else it will be big enough 
00117 // to accomodate the kernel width (e.g. +/- 5sigma for Gaussian)
00118 // <group>
00119    void setKernel(uInt axis, VectorKernel::KernelTypes kernelType,
00120                   const Quantum<Double>& width, Bool autoScale,
00121                   Bool useImageShapeExactly=True, Double scale=1.0);
00122    void setKernel(uInt axis, VectorKernel::KernelTypes kernelType,
00123                   Double width, Bool autoScale, 
00124                   Bool useImageShapeExactly=True, Double scale=1.0);
00125 // </group>
00126 
00127 // Get the convolution kernel for the specified axis
00128    Vector<T> getKernel(uInt axis);
00129 
00130 // Get the convolution kernel shape for the specified axis
00131    uInt  getKernelShape(uInt axis);
00132 
00133 // Perform the convolution either outputting to a new image
00134 // or in-situ.    The error checking for the
00135 // convolution parameters is done when you call this
00136 // function.  If outputting a new image, and it needs a mask and doesn't have one,
00137 // the it will be given one if possible and the input
00138 // mask will be transferred to the output.  Masked pixels
00139 // are zeroed before convolving
00140 // <group>
00141    void convolve(ImageInterface<T>& imageOut);
00142    void convolve();
00143 // </group>
00144 
00145 
00146 private:
00147    ImageInterface<T>* itsImagePtr;
00148    LogIO itsOs;
00149    Vector<uInt> itsAxes;
00150    PtrBlock<Vector<T>* > itsVectorKernels;
00151    Bool itsShowProgress;
00152 
00153 //
00154 
00155    void checkAxis(uInt axis);
00156    Bool isTempImage (const ImageInterface<Float>* pIm) const;
00157    void zero();
00158    void smoothProfiles (ImageInterface<T>& in,
00159                         const Int& axis,
00160                         const Vector<T>& psf);
00161 };
00162 
00163 
00164 
00165 } //# NAMESPACE CASA - END
00166 
00167 #ifndef CASACORE_NO_AUTO_TEMPLATES
00168 #include <imageanalysis/ImageAnalysis/SepImageConvolver.tcc>
00169 #endif //# CASACORE_NO_AUTO_TEMPLATES
00170 #endif