source: tags/release-1.6.1/src/Utils/GaussSmooth2D.hh @ 1441

Last change on this file since 1441 was 1393, checked in by MatthewWhiting, 10 years ago

A large changeset that moves all use of bool arrays (ie. bool *) to std::vector<bool>. This will be a bit safer, plus potentially cheaper in memory usage. Interfaces to all stats functions with masks have changed accordingly, as well as the Gaussian smoothing functions and some spectral utility functions.

File size: 4.3 KB
Line 
1// -----------------------------------------------------------------------
2// GaussSmooth2D.hh: Definition of GaussSmooth2D class, used to smooth a
3//                 2D image with a Gaussian kernel.
4// -----------------------------------------------------------------------
5// Copyright (C) 2006, Matthew Whiting, ATNF
6//
7// This program is free software; you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2 of the License, or (at your
10// option) any later version.
11//
12// Duchamp is distributed in the hope that it will be useful, but WITHOUT
13// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15// for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Duchamp; if not, write to the Free Software Foundation,
19// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20//
21// Correspondence concerning Duchamp may be directed to:
22//    Internet email: Matthew.Whiting [at] atnf.csiro.au
23//    Postal address: Dr. Matthew Whiting
24//                    Australia Telescope National Facility, CSIRO
25//                    PO Box 76
26//                    Epping NSW 1710
27//                    AUSTRALIA
28// -----------------------------------------------------------------------
29#ifndef GAUSSSMOOTH2D_H
30#define GAUSSSMOOTH2D_H
31#include <vector>
32#include <duchamp/duchamp.hh>
33
34/// @brief How the edges of the array are dealt with
35enum EDGES { EQUALTOEDGE,       ///< All pixels are used and treated equally
36             SCALEBYCOVERAGE,   ///< All pixels are used, but edge pixels are weighted down by the kernel coverage
37             TRUNCATE           ///< Pixels at edge are set to Blank.
38};
39
40/// @brief
41///  Define a Gaussian to smooth a 2D array.
42/// @details
43///  A simple class to define a Gaussian kernel that can be used to
44///  smooth a two-dimensional array.
45
46template <class Type>
47class GaussSmooth2D
48{
49public:
50  GaussSmooth2D();          ///< Basic constructor: no kernel defined.
51  virtual ~GaussSmooth2D(); ///< Destructor
52  GaussSmooth2D(const GaussSmooth2D& g);
53  GaussSmooth2D& operator=(const GaussSmooth2D& g);
54 
55  void defaults();
56
57  /// @brief Specific constructor that sets up kernel.
58  GaussSmooth2D(float maj, float min, float pa, float cutoff); 
59  /// @brief Specific constructor that sets up kernel.
60  GaussSmooth2D(float maj, float min, float pa); 
61  /// @brief Specific constructor that sets up kernel: assuming circular gaussian.
62  GaussSmooth2D(float maj); 
63
64  /// @brief Define the size and the array of coefficients.
65  void   define(float maj, float min, float pa, float cutoff);
66
67  /// @brief Set the size of the kernel
68  void   setKernelWidth(float width){kernWidth = width;};
69
70  /// @brief Smooth an array with the Gaussian kernel
71  Type *smooth(Type *input, size_t xdim, size_t ydim, EDGES edgeTreatment=EQUALTOEDGE); 
72  /// @brief Smooth an array with the Gaussian kernel, using a mask to define blank pixels
73  Type *smooth(Type *input, size_t xdim, size_t ydim, std::vector<bool> mask, EDGES edgeTreatment=EQUALTOEDGE); 
74 
75  void   setKernMaj(float f){kernMaj=f;};
76  void   setKernMin(float f){kernMin=f;};
77  void   setKernPA(float f){kernPA=f;};
78 
79  Type   getKernelPt(int i){return kernel[i];};
80  Type  *getKernel(){return kernel;};
81
82  int    getKernelWidth(){return kernWidth;};
83  float  getStddevScale(){return stddevScale;};
84
85  void   setBlankVal(Type b){blankVal = b;};
86  Type   getBlankVal(){return blankVal;};
87
88    bool isAllocated(){return allocated;};
89
90private:
91  float  kernMaj;      ///< The FWHM of the major axis of the elliptical Gaussian.
92  float  kernMin;      ///< The FWHM of the minor axis of the elliptical Gaussian.
93  float  kernPA;       ///< The position angle of the elliptical Gaussian.
94  size_t kernWidth;    ///< The width of the kernel (in pixels).
95  float  stddevScale;  ///< The factor by which the rms of the input array gets scaled by (assuming iid normally)
96  Type  *kernel;       ///< The coefficients of the smoothing kernel
97  bool   allocated;    ///< Have the coefficients been allocated in memory?
98  Type   blankVal;     ///< What value to set blanks (when doing TRUNCATE mode)
99
100};
101
102#include <duchamp/Utils/GaussSmooth2D.tcc>
103
104#endif  // GAUSSSMOOTH2D_H
105 
Note: See TracBrowser for help on using the repository browser.