// ----------------------------------------------------------------------- // atrous_1d_reconstruct.cc: 1-dimensional wavelet reconstruction. // ----------------------------------------------------------------------- // Copyright (C) 2006, Matthew Whiting, ATNF // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your // option) any later version. // // Duchamp is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License // along with Duchamp; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA // // Correspondence concerning Duchamp may be directed to: // Internet email: Matthew.Whiting [at] atnf.csiro.au // Postal address: Dr. Matthew Whiting // Australia Telescope National Facility, CSIRO // PO Box 76 // Epping NSW 1710 // AUSTRALIA // ----------------------------------------------------------------------- #include #include #include #include #include #include #include #include #include #include #include using Statistics::madfmToSigma; namespace duchamp { void atrous1DReconstruct(long &xdim, float *&input, float *&output, Param &par) { /// A routine that uses the a trous wavelet method to reconstruct a /// 1-dimensional spectrum. /// The Param object "par" contains all necessary info about the filter and /// reconstruction parameters. /// /// If all pixels are BLANK (and we are testing for BLANKs), the /// reconstruction will simply give BLANKs back, so we return the /// input array as the output array. /// /// \param xdim The length of the spectrum. /// \param input The input spectrum. /// \param output The returned reconstructed spectrum. This array needs to /// be declared beforehand. /// \param par The Param set. const float SNR_THRESH=par.getAtrousCut(); const int MIN_SCALE=par.getMinScale(); static bool firstTime = true; int numScales = par.filter().getNumScales(xdim); int maxScale = par.getMaxScale(); if((maxScale>0)&&(maxScale<=numScales)) maxScale = std::min(maxScale,numScales); else{ if((firstTime)&&(maxScale!=0)){ firstTime=false; std::stringstream errmsg; errmsg << "The requested value of the parameter scaleMax, \"" << maxScale << "\" is outside the allowed range (1-" << numScales <<").\nSetting to " << numScales << ".\n"; duchampWarning("Reading parameters",errmsg.str()); } maxScale = numScales; } double *sigmaFactors = new double[numScales+1]; for(int i=0;i<=numScales;i++){ if(i<=par.filter().maxFactor(1)) sigmaFactors[i] = par.filter().sigmaFactor(1,i); else sigmaFactors[i] = sigmaFactors[i-1] / sqrt(2.); } float mean,sigma,originalSigma,originalMean,oldsigma,newsigma; bool *isGood = new bool[xdim]; int goodSize=0; for(int pos=0;pos=xdim)){ // boundary conditions are reflection. if(x<0) x = 0 - x; else if(x>=xdim) x = 2*(xdim-1) - x; } int filterpos = (xoffset+filterHW); int oldpos = x; if(isGood[oldpos]) wavelet[pos] -= filter[filterpos]*coeffs[oldpos]; } //-> end of xoffset loop } //-> end of else{ ( from if(!isGood[pos]) ) } //-> end of xpos loop // Need to do this after we've done *all* the convolving for(int pos=0;pos=MIN_SCALE){ findMedianStats(wavelet,xdim,isGood,mean,sigma); for(int pos=0;pos (mean+SNR_THRESH*originalSigma*sigmaFactors[scale]) ) output[pos] += wavelet[pos]; } } spacing *= 2; } //-> end of scale loop // Only add the final smoothed array if we are doing *all* the scales. if(numScales == par.filter().getNumScales(xdim)) for(int pos=0;pos reconTolerance) ); if(par.isVerbose()) std::cout << "Completed "<