source: tags/release-0.9/Detection/growObject.cc @ 813

Last change on this file since 813 was 3, checked in by Matthew Whiting, 18 years ago

This is the first full import of all working code to
the Duchamp repository.
Made three directories at top level:

branches/ tags/ trunk/

and trunk/ has the full set of code:
ATrous/ Cubes/ Detection/ InputComplete? InputExample? README Utils/ docs/ mainDuchamp.cc param.cc param.hh

File size: 5.3 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <vector>
4#include <Cubes/cubes.hh>
5#include <Utils/utils.hh>
6
7using std::vector;
8using std::setw;
9
10// void Detection::growObject(Image &image)
11// {
12//   vector <bool> isInObj(image.getSize(),false);
13//   for(int i=0;i<this->pix.size();i++)
14//     isInObj[this->pix[i].getX() + this->pix[i].getY()*image.getDimX()] = true;
15
16//   for(int pix=0; pix<this->pix.size(); pix++){ // for each pixel in the object
17
18//     for(int xnbr=-1; xnbr<=1; xnbr++){
19//       for(int ynbr=-1; ynbr<=1; ynbr++){
20//      if((xnbr!=0)||(ynbr!=0)){ // ignore when both=0 ie. the current object pixel
21
22//        Voxel *pixnew = new Voxel;
23//        *pixnew = object.getPixel(pix);
24//        long newx = this->pix[pix].getX() + xnbr;
25//        long newy = this->pix[pix].getY() + ynbr;
26         
27//        if((newx<image.getDimX())&&(newy<image.getDimY())&&(newx>=0)&&(newy>=0)){
28           
29//          pixnew->setX(newx);
30//          pixnew->setY(newy);
31//          pixnew->setF(image.getPixValue(newx,newy));
32           
33//          if( (!isInObj[newx+newy*image.getDimX()]) &&
34//              (isDetection(pixnew->getF(), image.getMean(),
35//                           image.getSigma(), image.pars().getGrowthCut())) ){
36//            isInObj[newx+newy*image.getDimX()] = true;
37//            this->addPixel(*pixnew);
38//          }
39//        }
40//        delete pixnew;
41//      }
42//       }
43//     }
44
45//   }
46
47//   isInObj.clear();
48
49// }
50
51
52void growObject(Detection &object, Image &image)
53{
54  vector <bool> isInObj(image.getSize(),false);
55  for(int i=0;i<object.getSize();i++)
56    isInObj[object.getX(i) + object.getY(i)*image.getDimX()] = true;
57
58  for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object
59
60    for(int xnbr=-1; xnbr<=1; xnbr++){
61      for(int ynbr=-1; ynbr<=1; ynbr++){
62        if((xnbr!=0)||(ynbr!=0)){ // ignore when both=0 ie. the current object pixel
63
64          Voxel *pixnew = new Voxel;
65          *pixnew = object.getPixel(pix);
66          long newx = object.getX(pix) + xnbr;
67          long newy = object.getY(pix) + ynbr;
68         
69          if((newx<image.getDimX())&&(newy<image.getDimY())&&(newx>=0)&&(newy>=0)){
70           
71            pixnew->setX(newx);
72            pixnew->setY(newy);
73            pixnew->setF(image.getPixValue(newx,newy));
74           
75            if( (!isInObj[newx+newy*image.getDimX()]) &&
76                (isDetection(pixnew->getF(), image.getMean(),
77                             image.getSigma(), image.pars().getGrowthCut())) ){
78              isInObj[newx+newy*image.getDimX()] = true;
79              object.addPixel(*pixnew);
80            }
81          }
82          delete pixnew;
83        }
84      }
85    }
86
87  }
88
89  isInObj.clear();
90
91}
92
93void growObject(Detection &object, Cube &cube)
94{
95  vector <bool> isInObj(cube.getSize(),false);
96  float *cut     = new float;       
97  float *flux    = new float;
98  float *thresh1 = new float;
99  float *thresh2 = new float;
100  long  *pos     = new long;
101  long  *chanpos = new long;
102  long  *newx    = new long;
103  long  *newy    = new long;
104  long  *newz    = new long;
105
106  for(int i=0;i<object.getSize();i++) {
107    long pos = object.getX(i) + object.getY(i)*cube.getDimX() +
108      object.getZ(i)*cube.getDimX()*cube.getDimY();
109    isInObj[pos] = true;
110  }
111  *cut = cube.pars().getGrowthCut();
112 
113  for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object
114
115//     std::cout.setf(std::ios::right);
116//     std::cout <<":"<< setw(6) << pix+1 << "/";
117//     std::cout.unsetf(std::ios::right);
118//     std::cout.setf(std::ios::left);
119//     std::cout << setw(6) << object.getSize() << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b" << std::flush;
120//     std::cout.unsetf(std::ios::left);
121
122
123    for(int xnbr=-1; xnbr<=1; xnbr++){
124      for(int ynbr=-1; ynbr<=1; ynbr++){
125        for(int znbr=-1; znbr<=1; znbr++){
126
127          if((xnbr!=0)||(ynbr!=0)||(znbr!=0)){ // ignore when all=0 ie. the current object pixel
128
129            Voxel *pixnew = new Voxel;
130            *pixnew = object.getPixel(pix);
131            *newx = object.getX(pix) + xnbr;
132            *newy = object.getY(pix) + ynbr;
133            *newz = object.getZ(pix) + znbr;
134         
135            if((*newx<cube.getDimX())&&(*newx>=0)&&
136               (*newy<cube.getDimY())&&(*newy>=0)&&
137               (*newz<cube.getDimZ())&&(*newz>=0)){
138           
139//            std::cerr << *newx<<" "<<*newy<<" "<<*newz<<"  "
140//                      <<cube.getDimX()<<" "<<cube.getDimY()<<" "<<cube.getDimZ()
141//                      <<std::endl;
142              pixnew->setX(*newx);
143              pixnew->setY(*newy);
144              pixnew->setZ(*newz);
145              // In following R=recon, B=baseline
146              // Four cases: i) B+R -- use recon
147              //            ii) R   -- use recon
148              //           iii) B   -- use array
149              //            iv) none-- use array
150              if(cube.isRecon()) *flux = cube.getReconValue(*newx,*newy,*newz);
151              else  *flux = cube.getPixValue(*newx,*newy,*newz);
152              pixnew->setF(*flux);
153
154              *chanpos = *newx + *newy * cube.getDimX();
155              *pos = *newx + *newy * cube.getDimX() + *newz * cube.getDimX() * cube.getDimY();
156              // thresh1 = spectral growth threshold
157              *thresh1 = cube.getSpecMean(*chanpos) + *cut * cube.getSpecSigma(*chanpos);
158              // thresh2 = channel map growth threshold
159              *thresh2 = cube.getChanMean(*newz) + *cut * cube.getChanSigma(*newz);
160              if( (!isInObj[*pos]) &&
161                  ( (*flux > *thresh1) || (*flux > *thresh2) ) ){
162                isInObj[*pos] = true;
163                object.addPixel(*pixnew);
164              }
165            }
166            delete pixnew;
167          }
168
169        }
170      }
171    }
172     
173  } // end of pix loop
174
175  object.calcParams();
176
177  delete cut;       
178  delete flux;
179  delete thresh1;
180  delete thresh2;
181  delete pos;
182  delete chanpos;
183  delete newx;
184  delete newy;
185  delete newz;
186
187  isInObj.clear();
188
189}
Note: See TracBrowser for help on using the repository browser.