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 | // ----------------------------------------------------------------------- |
---|
28 | #include <iostream> |
---|
29 | #include <iomanip> |
---|
30 | #include <vector> |
---|
31 | #include <duchamp/Cubes/cubeUtils.hh> |
---|
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> |
---|
37 | |
---|
38 | using std::vector; |
---|
39 | using std::setw; |
---|
40 | |
---|
41 | using namespace PixelInfo; |
---|
42 | using namespace Statistics; |
---|
43 | |
---|
44 | namespace duchamp |
---|
45 | { |
---|
46 | |
---|
47 | void growObject(Detection &object, Cube &cube) |
---|
48 | { |
---|
49 | /** |
---|
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. |
---|
61 | */ |
---|
62 | |
---|
63 | |
---|
64 | if(cube.pars().getFlagGrowth() && (cube.pars().getGrowthCut()<cube.pars().getCut())) { |
---|
65 | |
---|
66 | vector <bool> isInObj(cube.getSize(),false); |
---|
67 | bool flagAdj = cube.pars().getFlagAdjacent(); |
---|
68 | int threshS = int(cube.pars().getThreshS()); |
---|
69 | if(flagAdj) threshS = 1; |
---|
70 | int threshV = int(cube.pars().getThreshV()); |
---|
71 | |
---|
72 | vector<Voxel> voxlist = object.getPixelSet(); |
---|
73 | int origSize = voxlist.size(); |
---|
74 | long zero = 0; |
---|
75 | |
---|
76 | for(int i=0;i<voxlist.size();i++) { |
---|
77 | long pos = voxlist[i].getX() + voxlist[i].getY()*cube.getDimX() + |
---|
78 | voxlist[i].getZ()*cube.getDimX()*cube.getDimY(); |
---|
79 | isInObj[pos] = true; |
---|
80 | } |
---|
81 | |
---|
82 | StatsContainer<float> growthStats(cube.stats()); |
---|
83 | |
---|
84 | if(cube.pars().getFlagUserGrowthThreshold()) |
---|
85 | growthStats.setThreshold(cube.pars().getGrowthThreshold()); |
---|
86 | else |
---|
87 | growthStats.setThresholdSNR(cube.pars().getGrowthCut()); |
---|
88 | |
---|
89 | growthStats.setUseFDR(false); |
---|
90 | |
---|
91 | // for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object |
---|
92 | for(int pix=0; pix<voxlist.size(); pix++){ // for each pixel in the object |
---|
93 | |
---|
94 | int xmin = std::max(voxlist[pix].getX() - threshS, zero); |
---|
95 | int xmax = std::min(voxlist[pix].getX() + threshS, cube.getDimX()-1); |
---|
96 | int ymin = std::max(voxlist[pix].getY() - threshS, zero); |
---|
97 | int ymax = std::min(voxlist[pix].getY() + threshS, cube.getDimY()-1); |
---|
98 | int zmin = std::max(voxlist[pix].getZ() - threshV, zero); |
---|
99 | int zmax = std::min(voxlist[pix].getZ() + threshV, cube.getDimZ()-1); |
---|
100 | |
---|
101 | //loop over surrounding pixels. |
---|
102 | for(int x=xmin; x<=xmax; x++){ |
---|
103 | for(int y=ymin; y<=ymax; y++){ |
---|
104 | for(int z=zmin; z<=zmax; z++){ |
---|
105 | |
---|
106 | if((x!=voxlist[pix].getX())||(y!=voxlist[pix].getY())||(z!=voxlist[pix].getZ())){ |
---|
107 | // ignore when the current object pixel |
---|
108 | |
---|
109 | long pos = x + y * cube.getDimX() + z * cube.getDimX() * cube.getDimY(); |
---|
110 | |
---|
111 | if(!isInObj[pos] && // pixel not already in object? |
---|
112 | !cube.isBlank(x,y,z) && // pixel not BLANK? |
---|
113 | !cube.pars().isInMW(z) && // pixel not MW? |
---|
114 | (flagAdj || hypot(x,y)<threshS) ){ // pixel not too far away? |
---|
115 | |
---|
116 | float flux; |
---|
117 | if(cube.isRecon()) flux = cube.getReconValue(x,y,z); |
---|
118 | else flux = cube.getPixValue(x,y,z); |
---|
119 | |
---|
120 | Voxel pixnew(x,y,z,flux); |
---|
121 | |
---|
122 | if( growthStats.isDetection(flux) ){ |
---|
123 | isInObj[pos] = true; |
---|
124 | voxlist.push_back(pixnew); |
---|
125 | } // end of if |
---|
126 | |
---|
127 | } // end of if clause regarding position OK |
---|
128 | |
---|
129 | } // end of if clause regarding position not same |
---|
130 | |
---|
131 | } // end of z loop |
---|
132 | } // end of y loop |
---|
133 | } // end of x loop |
---|
134 | |
---|
135 | } // end of pix loop |
---|
136 | |
---|
137 | |
---|
138 | // Add in new pixels to the Detection |
---|
139 | for(int i=origSize; i<voxlist.size(); i++){ |
---|
140 | object.addPixel(voxlist[i]); |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | object.calcFluxes(cube.getArray(), cube.getDimArray()); |
---|
145 | |
---|
146 | isInObj.clear(); |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | } |
---|
151 | } |
---|