Line data Source code
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: casa-feedback@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 :
31 : #include <imageanalysis/ImageAnalysis/ImageTask.h>
32 :
33 : #include <casacore/casa/aips.h>
34 : #include <casacore/casa/Arrays/Array.h>
35 : #include <casacore/scimath/Mathematics/VectorKernel.h>
36 : #include <casacore/casa/Quanta/Quantum.h>
37 : #include <casacore/casa/Arrays/ArrayFwd.h>
38 :
39 : namespace casacore {
40 :
41 : template <class T> class ImageInterface;
42 : class String;
43 : class CoordinateSystem;
44 : class ImageInfo;
45 : class Unit;
46 : class GaussianBeam;
47 : }
48 :
49 : namespace casa {
50 :
51 : // <summary>
52 : // This class does 2D convolution of an image by a functional form
53 : // </summary>
54 :
55 : // <use visibility=export>
56 :
57 : // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
58 : // </reviewed>
59 :
60 : // <prerequisite>
61 : // <li> <linkto class="casacore::ImageInterface">casacore::ImageInterface</linkto>
62 : // <li> <linkto class="casacore::Convolver">casacore::Convolver</linkto>
63 : // </prerequisite>
64 :
65 : // <etymology>
66 : // This class handles 2D convolution of images
67 : // </etymology>
68 :
69 : // <synopsis>
70 : // This class convolves an image by a specified 2D function.
71 : // </synopsis>
72 :
73 : // <example>
74 : // <srcBlock>
75 : // </srcBlock>
76 : // </example>
77 :
78 : // <motivation>
79 : // Convolution is a standard image processing requirement. The
80 : // class object has no state.
81 : // The convolution is done via FFT. Thus input pixels which
82 : // are masked are set to 0 before the convolution. The mask
83 : // is transferred to the output image. No additional scaling
84 : // of the output image values is done.
85 : //
86 : // </motivation>
87 :
88 : // <todo asof="2001/08/28">
89 : // <li>
90 : // </todo>
91 :
92 : template <class T> class Image2DConvolver : public ImageTask<T> {
93 : public:
94 :
95 : const static casacore::String CLASS_NAME;
96 :
97 : Image2DConvolver() = delete;
98 :
99 : Image2DConvolver(
100 : const SPCIIT image, const casacore::Record *const ®ionPtr,
101 : const casacore::String& mask, const casacore::String& outname,
102 : const casacore::Bool overwrite
103 : );
104 :
105 : Image2DConvolver(const Image2DConvolver<T> &other) = delete;
106 :
107 0 : ~Image2DConvolver() {}
108 :
109 : Image2DConvolver &operator=(const Image2DConvolver<T> &other) = delete;
110 :
111 : SPIIT convolve();
112 :
113 : // type is a string that starts with "g" (gaussian), "b" (boxcar), or "h"
114 : // (hanning), and is case insensitive
115 : void setKernel(
116 : const casacore::String& type, const casacore::Quantity& major,
117 : const casacore::Quantity& minor, const casacore::Quantity& pa
118 : );
119 :
120 348 : void setScale(casacore::Double d) { _scale = d; }
121 :
122 : void setAxes(const std::pair<casacore::uInt, casacore::uInt>& axes);
123 :
124 0 : void setTargetRes(casacore::Bool b) { _targetres = b; }
125 :
126 0 : casacore::String getClass() const { return CLASS_NAME; }
127 :
128 : // if true, do not log certain info/warning messages which would normally
129 : // be logged during convolution
130 348 : void setSuppressWarnings(casacore::Bool b) { _suppressWarnings = b; }
131 :
132 : protected:
133 :
134 0 : CasacRegionManager::StokesControl _getStokesControl() const {
135 0 : return CasacRegionManager::USE_ALL_STOKES;
136 : }
137 :
138 0 : std::vector<casacore::Coordinate::Type> _getNecessaryCoordinates() const {
139 0 : return std::vector<casacore::Coordinate::Type>();
140 : }
141 :
142 0 : inline casacore::Bool _supportsMultipleRegions() const {return true;}
143 :
144 : private:
145 : casacore::VectorKernel::KernelTypes _type;
146 : casacore::Double _scale;
147 : casacore::Quantity _major, _minor, _pa;
148 : casacore::IPosition _axes;
149 : casacore::Bool _targetres = casacore::False;
150 : casacore::Bool _suppressWarnings = casacore::False;
151 :
152 : void _checkKernelParameters(
153 : casacore::VectorKernel::KernelTypes kernelType,
154 : const casacore::Vector<casacore::Quantity>& parameters
155 : ) const;
156 :
157 : void _convolve(
158 : SPIIT imageOut, const casacore::ImageInterface<T>& imageIn,
159 : casacore::VectorKernel::KernelTypes kernelType
160 : ) const;
161 :
162 : // returns the value by which pixel values will be scaled
163 : Double _dealWithRestoringBeam (
164 : casacore::String& brightnessUnitOut, casacore::GaussianBeam& beamOut,
165 : const casacore::Array<Double>& kernelArray, Double kernelVolume,
166 : const casacore::VectorKernel::KernelTypes kernelType,
167 : const casacore::Vector<casacore::Quantity>& parameters,
168 : const casacore::CoordinateSystem& cSys,
169 : const casacore::GaussianBeam& beamIn,
170 : const casacore::Unit& brightnessUnit, casacore::Bool emitMessage
171 : ) const;
172 :
173 : void _doMultipleBeams(
174 : ImageInfo& iiOut, Double& kernelVolume, SPIIT imageOut,
175 : String& brightnessUnitOut, GaussianBeam& beamOut, Double factor1,
176 : const ImageInterface<T>& imageIn, const std::vector<Quantity>& originalParms,
177 : std::vector<Quantity>& kernelParms, Array<Double>& kernel,
178 : VectorKernel::KernelTypes kernelType, Bool logFactors, Double pixelArea
179 : ) const;
180 :
181 : // The kernel is currently always real-valued, so make it Double at this
182 : // point to avoid unnecessary templating issues if the image has is
183 : // complex valued
184 : void _doSingleBeam(
185 : ImageInfo& iiOut, Double& kernelVolume, std::vector<Quantity>& kernelParms,
186 : Array<Double>& kernel, String& brightnessUnitOut, GaussianBeam& beamOut,
187 : SPIIT imageOut, const ImageInterface<T>& imageIn,
188 : const std::vector<Quantity>& originalParms,
189 : VectorKernel::KernelTypes kernelType, Bool logFactors, Double factor1,
190 : Double pixelArea
191 : ) const;
192 :
193 : Double _fillKernel (
194 : casacore::Matrix<Double>& kernelMatrix,
195 : casacore::VectorKernel::KernelTypes kernelType,
196 : const casacore::IPosition& kernelShape,
197 : const casacore::Vector<casacore::Double>& parameters
198 : ) const;
199 :
200 : void _fillGaussian(
201 : Double& maxVal, Double& volume, casacore::Matrix<Double>& pixels,
202 : Double height, Double xCentre, Double yCentre,
203 : Double majorAxis, Double ratio, Double positionAngle
204 : ) const;
205 :
206 : Double _makeKernel(
207 : casacore::Array<Double>& kernel,
208 : casacore::VectorKernel::KernelTypes kernelType,
209 : const std::vector<casacore::Quantity>& parameters,
210 : const casacore::ImageInterface<T>& inImage
211 : ) const;
212 :
213 : casacore::IPosition _shapeOfKernel(
214 : const casacore::VectorKernel::KernelTypes kernelType,
215 : const casacore::Vector<casacore::Double>& parameters,
216 : const casacore::uInt ndim
217 : ) const;
218 :
219 : casacore::uInt _sizeOfGaussian(
220 : const casacore::Double width, const casacore::Double nSigma
221 : ) const;
222 :
223 : std::vector<casacore::Quantity> _getConvolvingBeamForTargetResolution(
224 : const std::vector<casacore::Quantity>& targetBeamParms,
225 : const casacore::GaussianBeam& inputBeam
226 : ) const;
227 :
228 : void _logBeamInfo(
229 : const ImageInfo& imageInfo, const String& desc
230 : ) const;
231 :
232 : void _log(const String& msg, LogIO::Command priority) const;
233 : };
234 :
235 : }
236 :
237 : #ifndef CASACORE_NO_AUTO_TEMPLATES
238 : #include <imageanalysis/ImageAnalysis/Image2DConvolver.tcc>
239 : #endif //# CASACORE_NO_AUTO_TEMPLATES
240 : #endif
|