[301] | 1 | // ----------------------------------------------------------------------- |
---|
[638] | 2 | // GaussSmooth2D.hh: Definition of GaussSmooth2D class, used to smooth a |
---|
[301] | 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 | // ----------------------------------------------------------------------- |
---|
[638] | 29 | #ifndef GAUSSSMOOTH2D_H |
---|
| 30 | #define GAUSSSMOOTH2D_H |
---|
[913] | 31 | #include <duchamp/duchamp.hh> |
---|
[275] | 32 | |
---|
[682] | 33 | /// @brief How the edges of the array are dealt with |
---|
| 34 | enum EDGES { EQUALTOEDGE, ///< All pixels are used and treated equally |
---|
| 35 | SCALEBYCOVERAGE, ///< All pixels are used, but edge pixels are weighted down by the kernel coverage |
---|
| 36 | TRUNCATE ///< Pixels at edge are set to Blank. |
---|
| 37 | }; |
---|
| 38 | |
---|
[528] | 39 | /// @brief |
---|
| 40 | /// Define a Gaussian to smooth a 2D array. |
---|
| 41 | /// @details |
---|
| 42 | /// A simple class to define a Gaussian kernel that can be used to |
---|
| 43 | /// smooth a two-dimensional array. |
---|
[275] | 44 | |
---|
[516] | 45 | template <class Type> |
---|
[638] | 46 | class GaussSmooth2D |
---|
[275] | 47 | { |
---|
| 48 | public: |
---|
[638] | 49 | GaussSmooth2D(); ///< Basic constructor: no kernel defined. |
---|
| 50 | virtual ~GaussSmooth2D(); ///< Destructor |
---|
| 51 | GaussSmooth2D(const GaussSmooth2D& g); |
---|
| 52 | GaussSmooth2D& operator=(const GaussSmooth2D& g); |
---|
[365] | 53 | |
---|
[682] | 54 | void defaults(); |
---|
[275] | 55 | |
---|
[528] | 56 | /// @brief Specific constructor that sets up kernel. |
---|
[638] | 57 | GaussSmooth2D(float maj, float min, float pa); |
---|
[528] | 58 | /// @brief Specific constructor that sets up kernel: assuming circular gaussian. |
---|
[638] | 59 | GaussSmooth2D(float maj); |
---|
[275] | 60 | |
---|
[528] | 61 | /// @brief Define the size and the array of coefficients. |
---|
[275] | 62 | void define(float maj, float min, float pa); |
---|
| 63 | |
---|
[682] | 64 | /// @brief Set the size of the kernel |
---|
| 65 | void setKernelWidth(float width){kernWidth = width;}; |
---|
| 66 | |
---|
[528] | 67 | /// @brief Smooth an array with the Gaussian kernel |
---|
[1187] | 68 | Type *smooth(Type *input, size_t xdim, size_t ydim, EDGES edgeTreatment=EQUALTOEDGE); |
---|
[528] | 69 | /// @brief Smooth an array with the Gaussian kernel, using a mask to define blank pixels |
---|
[1187] | 70 | Type *smooth(Type *input, size_t xdim, size_t ydim, bool *mask, EDGES edgeTreatment=EQUALTOEDGE); |
---|
[275] | 71 | |
---|
| 72 | void setKernMaj(float f){kernMaj=f;}; |
---|
| 73 | void setKernMin(float f){kernMin=f;}; |
---|
| 74 | void setKernPA(float f){kernPA=f;}; |
---|
[1187] | 75 | |
---|
[516] | 76 | Type getKernelPt(int i){return kernel[i];}; |
---|
| 77 | Type *getKernel(){return kernel;}; |
---|
| 78 | |
---|
[682] | 79 | int getKernelWidth(){return kernWidth;}; |
---|
[275] | 80 | float getStddevScale(){return stddevScale;}; |
---|
| 81 | |
---|
[682] | 82 | void setBlankVal(Type b){blankVal = b;}; |
---|
| 83 | Type getBlankVal(){return blankVal;}; |
---|
| 84 | |
---|
[1187] | 85 | bool isAllocated(){return allocated;}; |
---|
| 86 | |
---|
[275] | 87 | private: |
---|
[528] | 88 | float kernMaj; ///< The FWHM of the major axis of the elliptical Gaussian. |
---|
| 89 | float kernMin; ///< The FWHM of the minor axis of the elliptical Gaussian. |
---|
| 90 | float kernPA; ///< The position angle of the elliptical Gaussian. |
---|
[1187] | 91 | size_t kernWidth; ///< The width of the kernel (in pixels). |
---|
[528] | 92 | float stddevScale; ///< The factor by which the rms of the input array gets scaled by (assuming iid normally) |
---|
[516] | 93 | Type *kernel; ///< The coefficients of the smoothing kernel |
---|
[275] | 94 | bool allocated; ///< Have the coefficients been allocated in memory? |
---|
[682] | 95 | Type blankVal; ///< What value to set blanks (when doing TRUNCATE mode) |
---|
[275] | 96 | |
---|
| 97 | }; |
---|
| 98 | |
---|
[710] | 99 | #include <duchamp/Utils/GaussSmooth2D.tcc> |
---|
[684] | 100 | |
---|
[638] | 101 | #endif // GAUSSSMOOTH2D_H |
---|
[1187] | 102 | |
---|