[300] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // growObject.cc: Grow a detected object down to a lower flux threshold. |
---|
| 3 | // ----------------------------------------------------------------------- |
---|
| 4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 5 | // |
---|
| 6 | // This program is free software; you can redistribute it and/or modify it |
---|
| 7 | // under the terms of the GNU General Public License as published by the |
---|
| 8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 9 | // option) any later version. |
---|
| 10 | // |
---|
| 11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 14 | // for more details. |
---|
| 15 | // |
---|
| 16 | // You should have received a copy of the GNU General Public License |
---|
| 17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 19 | // |
---|
| 20 | // Correspondence concerning Duchamp may be directed to: |
---|
| 21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 22 | // Postal address: Dr. Matthew Whiting |
---|
| 23 | // Australia Telescope National Facility, CSIRO |
---|
| 24 | // PO Box 76 |
---|
| 25 | // Epping NSW 1710 |
---|
| 26 | // AUSTRALIA |
---|
| 27 | // ----------------------------------------------------------------------- |
---|
[3] | 28 | #include <iostream> |
---|
| 29 | #include <iomanip> |
---|
| 30 | #include <vector> |
---|
[463] | 31 | #include <duchamp/Cubes/cubeUtils.hh> |
---|
[393] | 32 | #include <duchamp/Cubes/cubes.hh> |
---|
| 33 | #include <duchamp/Utils/utils.hh> |
---|
| 34 | #include <duchamp/Utils/Statistics.hh> |
---|
| 35 | #include <duchamp/PixelMap/Voxel.hh> |
---|
| 36 | #include <duchamp/Detection/detection.hh> |
---|
[3] | 37 | |
---|
| 38 | using std::vector; |
---|
| 39 | using std::setw; |
---|
| 40 | |
---|
[258] | 41 | using namespace PixelInfo; |
---|
[274] | 42 | using namespace Statistics; |
---|
[258] | 43 | |
---|
[378] | 44 | namespace duchamp |
---|
[3] | 45 | { |
---|
| 46 | |
---|
[378] | 47 | void growObject(Detection &object, Cube &cube) |
---|
| 48 | { |
---|
[528] | 49 | /// @details |
---|
| 50 | /// A function to grow an object (given by the Detection) by |
---|
| 51 | /// including neighbouring voxels out to some lower threshold than |
---|
| 52 | /// what was previously used in the detection. |
---|
| 53 | /// |
---|
| 54 | /// Each pixel has each of its neighbours examined, and if one of |
---|
| 55 | /// them is not in the object but above the growth threshold, it |
---|
| 56 | /// is added to the object. |
---|
| 57 | /// |
---|
| 58 | /// \param object Object to be grown. |
---|
| 59 | /// \param cube Necessary to see both the Param list, containing |
---|
| 60 | /// the growth threshold, and the actual array of pixel fluxes. |
---|
[3] | 61 | |
---|
[504] | 62 | if(cube.pars().getFlagGrowth()){ |
---|
[378] | 63 | |
---|
[504] | 64 | bool doGrowing; |
---|
| 65 | if(cube.pars().getFlagUserGrowthThreshold()) |
---|
[539] | 66 | doGrowing = cube.pars().getGrowthThreshold()<cube.pars().getThreshold(); |
---|
[504] | 67 | else |
---|
| 68 | doGrowing = cube.pars().getGrowthCut()<cube.pars().getCut(); |
---|
[190] | 69 | |
---|
[504] | 70 | if(doGrowing){ |
---|
[458] | 71 | |
---|
[504] | 72 | vector <bool> isInObj(cube.getSize(),false); |
---|
| 73 | bool flagAdj = cube.pars().getFlagAdjacent(); |
---|
| 74 | int threshS = int(cube.pars().getThreshS()); |
---|
| 75 | if(flagAdj) threshS = 1; |
---|
| 76 | int threshV = int(cube.pars().getThreshV()); |
---|
| 77 | |
---|
| 78 | vector<Voxel> voxlist = object.getPixelSet(); |
---|
| 79 | int origSize = voxlist.size(); |
---|
| 80 | long zero = 0; |
---|
| 81 | |
---|
[541] | 82 | for(unsigned int i=0;i<voxlist.size();i++) { |
---|
[504] | 83 | long pos = voxlist[i].getX() + voxlist[i].getY()*cube.getDimX() + |
---|
| 84 | voxlist[i].getZ()*cube.getDimX()*cube.getDimY(); |
---|
| 85 | isInObj[pos] = true; |
---|
| 86 | } |
---|
[190] | 87 | |
---|
[504] | 88 | StatsContainer<float> growthStats(cube.stats()); |
---|
[3] | 89 | |
---|
[504] | 90 | if(cube.pars().getFlagUserGrowthThreshold()) |
---|
| 91 | growthStats.setThreshold(cube.pars().getGrowthThreshold()); |
---|
| 92 | else |
---|
| 93 | growthStats.setThresholdSNR(cube.pars().getGrowthCut()); |
---|
[461] | 94 | |
---|
[504] | 95 | growthStats.setUseFDR(false); |
---|
[3] | 96 | |
---|
[504] | 97 | // for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object |
---|
[541] | 98 | for(unsigned int pix=0; pix<voxlist.size(); pix++){ // for each pixel in the object |
---|
[3] | 99 | |
---|
[504] | 100 | int xmin = std::max(voxlist[pix].getX() - threshS, zero); |
---|
| 101 | int xmax = std::min(voxlist[pix].getX() + threshS, cube.getDimX()-1); |
---|
| 102 | int ymin = std::max(voxlist[pix].getY() - threshS, zero); |
---|
| 103 | int ymax = std::min(voxlist[pix].getY() + threshS, cube.getDimY()-1); |
---|
| 104 | int zmin = std::max(voxlist[pix].getZ() - threshV, zero); |
---|
| 105 | int zmax = std::min(voxlist[pix].getZ() + threshV, cube.getDimZ()-1); |
---|
[458] | 106 | |
---|
[504] | 107 | //loop over surrounding pixels. |
---|
| 108 | for(int x=xmin; x<=xmax; x++){ |
---|
| 109 | for(int y=ymin; y<=ymax; y++){ |
---|
| 110 | for(int z=zmin; z<=zmax; z++){ |
---|
[458] | 111 | |
---|
[504] | 112 | if((x!=voxlist[pix].getX())||(y!=voxlist[pix].getY())||(z!=voxlist[pix].getZ())){ |
---|
| 113 | // ignore when the current object pixel |
---|
[458] | 114 | |
---|
[504] | 115 | long pos = x + y * cube.getDimX() + z * cube.getDimX() * cube.getDimY(); |
---|
[458] | 116 | |
---|
[504] | 117 | if(!isInObj[pos] && // pixel not already in object? |
---|
| 118 | !cube.isBlank(x,y,z) && // pixel not BLANK? |
---|
| 119 | !cube.pars().isInMW(z) && // pixel not MW? |
---|
[539] | 120 | (flagAdj || hypot(x-voxlist[pix].getX(),y-voxlist[pix].getY())<threshS) ){ // pixel not too far away? |
---|
[3] | 121 | |
---|
[504] | 122 | float flux; |
---|
| 123 | if(cube.isRecon()) flux = cube.getReconValue(x,y,z); |
---|
| 124 | else flux = cube.getPixValue(x,y,z); |
---|
[190] | 125 | |
---|
[504] | 126 | Voxel pixnew(x,y,z,flux); |
---|
[539] | 127 | |
---|
[504] | 128 | if( growthStats.isDetection(flux) ){ |
---|
| 129 | isInObj[pos] = true; |
---|
| 130 | voxlist.push_back(pixnew); |
---|
| 131 | } // end of if |
---|
[86] | 132 | |
---|
[504] | 133 | } // end of if clause regarding position OK |
---|
[86] | 134 | |
---|
[504] | 135 | } // end of if clause regarding position not same |
---|
[86] | 136 | |
---|
[504] | 137 | } // end of z loop |
---|
| 138 | } // end of y loop |
---|
| 139 | } // end of x loop |
---|
[86] | 140 | |
---|
[504] | 141 | } // end of pix loop |
---|
[86] | 142 | |
---|
| 143 | |
---|
[504] | 144 | // Add in new pixels to the Detection |
---|
[541] | 145 | for(unsigned int i=origSize; i<voxlist.size(); i++){ |
---|
[504] | 146 | object.addPixel(voxlist[i]); |
---|
| 147 | } |
---|
[458] | 148 | |
---|
| 149 | |
---|
[504] | 150 | object.calcFluxes(cube.getArray(), cube.getDimArray()); |
---|
[86] | 151 | |
---|
[504] | 152 | isInObj.clear(); |
---|
[458] | 153 | |
---|
[504] | 154 | } |
---|
| 155 | |
---|
[458] | 156 | } |
---|
[378] | 157 | } |
---|
[86] | 158 | } |
---|