casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Image2DConvolver.h
Go to the documentation of this file.
1 //# Image2DConvolver.h: 2D convolution of an image
2 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
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: Image2DConvolver.h 20229 2008-01-29 15:19:06Z gervandiepen $
27 
28 #ifndef IMAGES_IMAGE2DCONVOLVER_H
29 #define IMAGES_IMAGE2DCONVOLVER_H
30 
32 
33 #include <casa/aips.h>
34 #include <casa/Arrays/Array.h>
36 #include <casa/Quanta/Quantum.h>
37 
38 namespace casacore {
39 
40 template <class T> class ImageInterface;
41 template <class T> class Matrix;
42 template <class T> class Vector;
43 class String;
44 class IPosition;
45 class CoordinateSystem;
46 class ImageInfo;
47 class Unit;
48 class GaussianBeam;
49 }
50 
51 namespace casa {
52 
53 // <summary>
54 // This class does 2D convolution of an image by a functional form
55 // </summary>
56 
57 // <use visibility=export>
58 
59 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
60 // </reviewed>
61 
62 // <prerequisite>
63 // <li> <linkto class="casacore::ImageInterface">casacore::ImageInterface</linkto>
64 // <li> <linkto class="casacore::Convolver">casacore::Convolver</linkto>
65 // </prerequisite>
66 
67 // <etymology>
68 // This class handles 2D convolution of images
69 // </etymology>
70 
71 // <synopsis>
72 // This class convolves an image by a specified 2D function.
73 // </synopsis>
74 
75 // <example>
76 // <srcBlock>
77 // </srcBlock>
78 // </example>
79 
80 // <motivation>
81 // Convolution is a standard image processing requirement. The
82 // class object has no state.
83 // The convolution is done via FFT. Thus input pixels which
84 // are masked are set to 0 before the convolution. The mask
85 // is transferred to the output image. No additional scaling
86 // of the output image values is done.
87 //
88 // </motivation>
89 
90 // <todo asof="2001/08/28">
91 // <li>
92 // </todo>
93 
94 template <class T> class Image2DConvolver : public ImageTask<T> {
95 public:
96 
98 
99  Image2DConvolver() = delete;
100 
102  const SPCIIT image, const casacore::Record *const &regionPtr,
103  const casacore::String& mask, const casacore::String& outname,
104  const casacore::Bool overwrite
105  );
106 
107  Image2DConvolver(const Image2DConvolver<T> &other) = delete;
108 
110 
111  Image2DConvolver &operator=(const Image2DConvolver<T> &other) = delete;
112 
113  SPIIT convolve();
114 
115  // type is a string that starts with "g" (gaussian), "b" (boxcar), or "h"
116  // (hanning), and is case insensitive
117  void setKernel(
118  const casacore::String& type, const casacore::Quantity& major,
119  const casacore::Quantity& minor, const casacore::Quantity& pa
120  );
121 
123 
124  void setAxes(const std::pair<casacore::uInt, casacore::uInt>& axes);
125 
127 
129 
130  // if true, do not log certain info/warning messages which would normally
131  // be logged during convolution
133 
134 protected:
135 
138  }
139 
140  std::vector<casacore::Coordinate::Type> _getNecessaryCoordinates() const {
141  return std::vector<casacore::Coordinate::Type>();
142  }
143 
144  inline casacore::Bool _supportsMultipleRegions() const {return true;}
145 
146 private:
153 
156  const casacore::Vector<casacore::Quantity>& parameters
157  ) const;
158 
159  void _convolve(
160  SPIIT imageOut, const casacore::ImageInterface<T>& imageIn,
162  ) const;
163 
164  // returns the value by which pixel values will be scaled
166  casacore::String& brightnessUnitOut, casacore::GaussianBeam& beamOut,
167  const casacore::Array<Double>& kernelArray, Double kernelVolume,
168  const casacore::VectorKernel::KernelTypes kernelType,
169  const casacore::Vector<casacore::Quantity>& parameters,
170  const casacore::CoordinateSystem& cSys,
171  const casacore::GaussianBeam& beamIn,
172  const casacore::Unit& brightnessUnit, casacore::Bool emitMessage
173  ) const;
174 
175  void _doMultipleBeams(
176  ImageInfo& iiOut, Double& kernelVolume, SPIIT imageOut,
177  String& brightnessUnitOut, GaussianBeam& beamOut, Double factor1,
178  const ImageInterface<T>& imageIn, const std::vector<Quantity>& originalParms,
179  std::vector<Quantity>& kernelParms, Array<Double>& kernel,
180  VectorKernel::KernelTypes kernelType, Bool logFactors, Double pixelArea
181  ) const;
182 
183  // The kernel is currently always real-valued, so make it Double at this
184  // point to avoid unnecessary templating issues if the image has is
185  // complex valued
186  void _doSingleBeam(
187  ImageInfo& iiOut, Double& kernelVolume, std::vector<Quantity>& kernelParms,
188  Array<Double>& kernel, String& brightnessUnitOut, GaussianBeam& beamOut,
189  SPIIT imageOut, const ImageInterface<T>& imageIn,
190  const std::vector<Quantity>& originalParms,
191  VectorKernel::KernelTypes kernelType, Bool logFactors, Double factor1,
192  Double pixelArea
193  ) const;
194 
196  casacore::Matrix<Double>& kernelMatrix,
198  const casacore::IPosition& kernelShape,
199  const casacore::Vector<casacore::Double>& parameters
200  ) const;
201 
202  void _fillGaussian(
203  Double& maxVal, Double& volume, casacore::Matrix<Double>& pixels,
204  Double height, Double xCentre, Double yCentre,
205  Double majorAxis, Double ratio, Double positionAngle
206  ) const;
207 
209  casacore::Array<Double>& kernel,
211  const std::vector<casacore::Quantity>& parameters,
212  const casacore::ImageInterface<T>& inImage
213  ) const;
214 
216  const casacore::VectorKernel::KernelTypes kernelType,
217  const casacore::Vector<casacore::Double>& parameters,
218  const casacore::uInt ndim
219  ) const;
220 
222  const casacore::Double width, const casacore::Double nSigma
223  ) const;
224 
225  std::vector<casacore::Quantity> _getConvolvingBeamForTargetResolution(
226  const std::vector<casacore::Quantity>& targetBeamParms,
227  const casacore::GaussianBeam& inputBeam
228  ) const;
229 
230  void _logBeamInfo(
231  const ImageInfo& imageInfo, const String& desc
232  ) const;
233 
234  void _log(const String& msg, LogIO::Command priority) const;
235 };
236 
237 }
238 
239 #ifndef CASACORE_NO_AUTO_TEMPLATES
240 #include <imageanalysis/ImageAnalysis/Image2DConvolver.tcc>
241 #endif //# CASACORE_NO_AUTO_TEMPLATES
242 #endif
void _log(const String &msg, LogIO::Command priority) const
casacore::uInt _sizeOfGaussian(const casacore::Double width, const casacore::Double nSigma) const
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
This class does 2D convolution of an image by a functional form.
A 1-D Specialization of the Array class.
casacore::Bool _supportsMultipleRegions() const
void setScale(casacore::Double d)
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
void _fillGaussian(Double &maxVal, Double &volume, casacore::Matrix< Double > &pixels, Double height, Double xCentre, Double yCentre, Double majorAxis, Double ratio, Double positionAngle) const
virtual Type type()
Return the type enum.
Double _dealWithRestoringBeam(casacore::String &brightnessUnitOut, casacore::GaussianBeam &beamOut, const casacore::Array< Double > &kernelArray, Double kernelVolume, const casacore::VectorKernel::KernelTypes kernelType, const casacore::Vector< casacore::Quantity > &parameters, const casacore::CoordinateSystem &cSys, const casacore::GaussianBeam &beamIn, const casacore::Unit &brightnessUnit, casacore::Bool emitMessage) const
returns the value by which pixel values will be scaled
casacore::IPosition _axes
void _doMultipleBeams(ImageInfo &iiOut, Double &kernelVolume, SPIIT imageOut, String &brightnessUnitOut, GaussianBeam &beamOut, Double factor1, const ImageInterface< T > &imageIn, const std::vector< Quantity > &originalParms, std::vector< Quantity > &kernelParms, Array< Double > &kernel, VectorKernel::KernelTypes kernelType, Bool logFactors, Double pixelArea) const
Command
Special commands to the LogIO object.
Definition: LogIO.h:171
casacore::IPosition _shapeOfKernel(const casacore::VectorKernel::KernelTypes kernelType, const casacore::Vector< casacore::Double > &parameters, const casacore::uInt ndim) const
Double _makeKernel(casacore::Array< Double > &kernel, casacore::VectorKernel::KernelTypes kernelType, const std::vector< casacore::Quantity > &parameters, const casacore::ImageInterface< T > &inImage) const
A 2-D Specialization of the Array class.
Represents a Gaussian restoring beam associated with an image.
Definition: GaussianBeam.h:68
void _convolve(SPIIT imageOut, const casacore::ImageInterface< T > &imageIn, casacore::VectorKernel::KernelTypes kernelType) const
Image2DConvolver & operator=(const Image2DConvolver< T > &other)=delete
defines physical units
Definition: Unit.h:189
void _doSingleBeam(ImageInfo &iiOut, Double &kernelVolume, std::vector< Quantity > &kernelParms, Array< Double > &kernel, String &brightnessUnitOut, GaussianBeam &beamOut, SPIIT imageOut, const ImageInterface< T > &imageIn, const std::vector< Quantity > &originalParms, VectorKernel::KernelTypes kernelType, Bool logFactors, Double factor1, Double pixelArea) const
The kernel is currently always real-valued, so make it Double at this point to avoid unnecessary temp...
casacore::Quantity _pa
std::vector< casacore::Quantity > _getConvolvingBeamForTargetResolution(const std::vector< casacore::Quantity > &targetBeamParms, const casacore::GaussianBeam &inputBeam) const
void setSuppressWarnings(casacore::Bool b)
if true, do not log certain info/warning messages which would normally be logged during convolution ...
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
casacore::Double _scale
A base class for astronomical images.
void _logBeamInfo(const ImageInfo &imageInfo, const String &desc) const
#define SPIIT
Definition: ImageTypedefs.h:34
casacore::Bool _suppressWarnings
Double _fillKernel(casacore::Matrix< Double > &kernelMatrix, casacore::VectorKernel::KernelTypes kernelType, const casacore::IPosition &kernelShape, const casacore::Vector< casacore::Double > &parameters) const
void _checkKernelParameters(casacore::VectorKernel::KernelTypes kernelType, const casacore::Vector< casacore::Quantity > &parameters) const
double Double
Definition: aipstype.h:55
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
casacore::Quantity _minor
void setKernel(const casacore::String &type, const casacore::Quantity &major, const casacore::Quantity &minor, const casacore::Quantity &pa)
type is a string that starts with &quot;g&quot; (gaussian), &quot;b&quot; (boxcar), or &quot;h&quot; (hanning), and is case insensi...
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
std::vector< casacore::Coordinate::Type > _getNecessaryCoordinates() const
Represents the minimum set of coordinates necessary for the task to function.
void setTargetRes(casacore::Bool b)
casacore::VectorKernel::KernelTypes _type
const Bool False
Definition: aipstype.h:44
#define SPCIIT
Definition: ImageTypedefs.h:35
static const casacore::String CLASS_NAME
casacore::String getClass() const
String: the storage and methods of handling collections of characters.
Definition: String.h:223
CasacRegionManager::StokesControl _getStokesControl() const
Miscellaneous information related to an image.
Definition: ImageInfo.h:92
void setAxes(const std::pair< casacore::uInt, casacore::uInt > &axes)
casacore::Quantity _major
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