// ----------------------------------------------------------------------- // atrous_2d_reconstruct.cc: 2-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 using Statistics::madfmToSigma; namespace duchamp { void atrous2DReconstruct(long &xdim, long &ydim, float *&input, float *&output, Param &par) { /** * A routine that uses the a trous wavelet method to reconstruct a * 2-dimensional image. * * If there are no non-BLANK pixels (and we are testing for * BLANKs), the reconstruction cannot be done, so we return the * input array as the output array and give a warning message. * * \param xdim The length of the x-axis of the image. * \param ydim The length of the y-axis of the image. * \param input The input spectrum. * \param output The returned reconstructed spectrum. This array * needs to be declared beforehand. * \param par The Param set:contains all necessary info about the * filter and reconstruction parameters. */ long size = xdim * ydim; long mindim = xdim; if (ydimct1)&&(par.isBlank(input[row*xdim+ct2]))) ct2--; xLim1[row] = ct1; xLim2[row] = ct2; avGapX += ct2 - ct1; } avGapX /= float(ydim); for(int col=0;colct1)&&(par.isBlank(input[col+xdim*ct2]))) ct2--; yLim1[col] = ct1; yLim2[col] = ct2; avGapY += ct2 - ct1; } avGapY /= float(xdim); mindim = int(avGapX); if(avGapY < avGapX) mindim = int(avGapY); numScales = par.filter().getNumScales(mindim); } float threshold; int iteration=0; newsigma = 1.e9; for(int i=0;iyLim2[xpos])){ // if(yyLim2[xpos]) y = 2*yLim2[xpos] - y; // } // } int oldrow = y * xdim; for(int xoffset=-filterHW; xoffset<=filterHW; xoffset++){ int x = xpos + spacing*xoffset; // Boundary conditions -- assume reflection at boundaries. // Use limits as calculated above // if(xLim1[ypos]!=xLim2[ypos]){ // // if these are equal we will get into an infinite loop here // while((xxLim2[ypos])){ // if(xxLim2[ypos]) x = 2*xLim2[ypos] - x; // } // } int oldpos = oldrow + x; float oldCoeff; if((y>=yLim1[xpos])&&(y<=yLim2[xpos])&& (x>=xLim1[ypos])&&(x<=xLim2[ypos]) ) oldCoeff = coeffs[oldpos]; else oldCoeff = 0.; filterpos++; if(isGood[pos]) wavelet[pos] -= filter[filterpos] * oldCoeff; // wavelet[pos] -= filter[filterpos] * coeffs[oldpos]; } //-> end of xoffset loop } //-> end of yoffset loop } //-> end of else{ ( from if(!isGood[pos]) ) } //-> end of xpos loop } //-> end of ypos loop // Need to do this after we've done *all* the convolving for(int pos=0;pos=par.getMinScale()){ array = new float[size]; goodSize=0; for(int pos=0;pos threshold ) output[pos] += wavelet[pos]; } } spacing *= 2; } // END OF LOOP OVER SCALES for(int pos=0;pos reconTolerance) ); if(par.isVerbose()) std::cout << "Completed "<