source: tags/release-1.1/src/Detection/growObject.cc @ 1391

Last change on this file since 1391 was 300, checked in by Matthew Whiting, 17 years ago
  • Fixed a bug that was incorrectly evaluating the integrated flux. It wasn't getting multiplied by the number of spatial pixels, so the values were way off.
  • Also fixed wcsIO.cc so that when a 2D section of a cube is given, the number of axes stored in the fitsHeader class is 2.
  • Changed the full results printing so that the FTOT column is printed as well. The results written to the screen are the same.
  • Some distribution text at the start of files.
File size: 4.4 KB
Line 
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 <Cubes/cubes.hh>
32#include <Utils/utils.hh>
33#include <Utils/Statistics.hh>
34#include <PixelMap/Voxel.hh>
35#include <Detection/detection.hh>
36
37using std::vector;
38using std::setw;
39
40using namespace PixelInfo;
41using namespace Statistics;
42
43void growObject(Detection &object, Cube &cube)
44{
45  /**
46   *    A function to grow an object (given by the Detection) by
47   *    including neighbouring voxels out to some lower threshold than
48   *    what was previously used in the detection. 
49   *
50   *    Each pixel has each of its neighbours examined, and if one of
51   *    them is not in the object but above the growth threshold, it
52   *    is added to the object.
53   *
54   *    \param object Object to be grown.
55   *    \param cube Necessary to see both the Param list, containing
56   *    the growth threshold, and the actual array of pixel fluxes.
57   */
58
59
60  vector <bool> isInObj(cube.getSize(),false);
61  bool flagAdj = cube.pars().getFlagAdjacent();
62  int threshS = int(cube.pars().getThreshS());
63  if(flagAdj) threshS = 1;
64  int threshV = int(cube.pars().getThreshV());
65
66  for(int i=0;i<object.getSize();i++) {
67    Voxel vox = object.getPixel(i);
68    long pos = vox.getX() + vox.getY()*cube.getDimX() +
69      vox.getZ()*cube.getDimX()*cube.getDimY();
70    isInObj[pos] = true;
71  }
72 
73  StatsContainer<float> growthStats = cube.getStats();
74
75  growthStats.setThresholdSNR(cube.pars().getGrowthCut());
76  growthStats.setUseFDR(false);
77 
78  for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object
79
80    for(int xnbr=-1*threshS; xnbr<=1*threshS; xnbr++){
81      for(int ynbr=-1*threshS; ynbr<=1*threshS; ynbr++){
82        for(int znbr=-1*threshV; znbr<=1*threshV; znbr++){
83
84          if((xnbr!=0)||(ynbr!=0)||(znbr!=0)){
85            // ignore when all=0 ie. the current object pixel
86
87            Voxel pixnew = object.getPixel(pix);
88            long newx = pixnew.getX() + xnbr;
89            long newy = pixnew.getY() + ynbr;
90            long newz = pixnew.getZ() + znbr;
91         
92            if((newx<cube.getDimX())&&(newx>=0)&&   // x in cube?
93               (newy<cube.getDimY())&&(newy>=0)&&   // y in cube?
94               (newz<cube.getDimZ())&&(newz>=0)&&   // z in cube?
95               !cube.isBlank(newx,newy,newz)   &&   // pixel not BLANK?
96               !cube.pars().isInMW(newz)       &&   // pixel not MW?
97               (flagAdj || hypot(xnbr,ynbr))     ){ // pixel not too far?
98           
99              pixnew.setX(newx);
100              pixnew.setY(newy);
101              pixnew.setZ(newz);
102
103              float flux;
104              if(cube.isRecon()) flux = cube.getReconValue(newx,newy,newz);
105              else               flux = cube.getPixValue(newx,newy,newz);
106              pixnew.setF(flux);
107
108              long pos = newx + newy * cube.getDimX() +
109                newz * cube.getDimX() * cube.getDimY();
110              if( (!isInObj[pos]) && growthStats.isDetection(flux) ){
111                isInObj[pos] = true;
112                object.addPixel(pixnew);
113              } // end of if
114
115            } // end of if clause regarding newx, newy, newz
116
117          } // end of if clause regarding xnbr, ynbr, znbr
118
119        } // end of znbr loop
120      } // end of ynbr loop
121    } // end of xnbr loop
122     
123  } // end of pix loop
124
125  object.calcFluxes(cube.getArray(), cube.getDimArray());
126
127  isInObj.clear();
128
129}
130
Note: See TracBrowser for help on using the repository browser.