source: trunk/Cubes/cubicSearch.cc @ 53

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

Added some improved stats and image segmenting routines:
Utils/getStats.cc -- added functions to calculate the individual stats,

so eg. if one only wants the median, one calculates
it and not the madfm as well.

Utils/utils.hh -- prototypes for above functions added
Cubes/cubes.cc -- added extractImage and extractSpectrum as easy tasks

to get a particular spectrum or channel map.
Also findStats, which calculates the correct stats
for the image.

Cubes/cubes.hh -- Prototypes for above functions
Cubes/cubicSearch.cc -- Made use of the above functions
ATrous/ReconSearch.cc -- Made use of the above functions

File size: 7.1 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <vector>
5#include <Cubes/cubes.hh>
6#include <Utils/utils.hh>
7
8void Cube::SimpleSearch3D()
9{
10  /**
11   * Cube::SimpleSearch3D()
12   *  A front end to the cubic searching routine that does not
13   *  involve any wavelet reconstruction.
14   *  Although if baseline-removal is required that is done prior to searching.
15   *  Once searching is complete, the detection map is updated and
16   *  the intermediate detections are logged in the log file.
17   */
18
19  this->objectList = cubicSearch(this->axisDim,this->array,this->par);
20   
21  this->updateDetectMap();
22  if(this->par.getFlagLog()) this->logDetectionList();
23
24}
25
26
27vector <Detection> cubicSearch(long *dim, float *Array, Param &par)
28{
29  /**
30   * cubicSearch
31   *  Takes a dimension array and data array as input (and Parameter set)
32   *  and searches for detections in a combination of 1D and 2D searches.
33   *  Returns a vector list of Detections.
34   *  No reconstruction is assumed to have taken place, so statistics are
35   *  calculated (using robust methods) from the data array itself.
36   */
37
38  vector <Detection> outputList;
39  int zdim = dim[2];
40  int xySize = dim[0] * dim[1];
41  int fullSize = zdim * xySize;
42  int num = 0;
43
44  float blankPixValue = par.getBlankPixVal();
45  bool *isGood = new bool[fullSize];
46  for(int pos=0;pos<fullSize;pos++)
47    isGood[pos] = !par.isBlank(Array[pos]);
48 
49  float dud;
50
51  // FIRST SEARCH --  IN EACH SPECTRUM.
52  // FIRST, GET STATS -- not any more...
53  if(zdim>1){
54    if(par.isVerbose()) std::cout << "  1D: |                    |" << std::flush;
55    if(par.isVerbose()) std::cout << "Done  0%" << "\b\b\b\b\b\b\b\b" << std::flush;
56    float *specMedian = new float[xySize];
57    float *specSigma = new float[xySize];
58
59    for(int npix=0; npix<xySize; npix++){
60      float *spec = new float[zdim];
61      int goodSize=0;
62      for(int z=0;z<zdim;z++) if(isGood[z*xySize+npix]) spec[goodSize++] = Array[z*xySize+npix];
63      if(goodSize>0) findMedianStats(spec,goodSize,specMedian[npix],dud);
64      else specMedian[npix] = blankPixValue;
65      //     if(goodSize>0) findNormalStats(spec,goodSize,dud,specSigma[npix]);
66      if(goodSize>0){
67        findMedianStats(spec,goodSize,dud,specSigma[npix]);
68        specSigma[npix] /= correctionFactor;
69      }
70      else specSigma[npix] = 1.;
71      delete spec;
72    }
73    // NEXT, DO SOURCE FINDING
74    int numSearches = xySize + zdim;
75    for(int npix=0; npix<xySize; npix++){
76
77      if( par.isVerbose() && ((100*(npix+1)/xySize)%5 == 0) ){
78        std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|";
79        for(int i=0;i<(100*(npix+1)/xySize)/5;i++) std::cout << "#";
80        for(int i=(100*(npix+1)/xySize)/5;i<20;i++) std::cout << " ";
81        std::cout << "|" << std::flush;
82      }
83
84//       float *spec = new float[zdim];
85//       for(int z=0;z<zdim;z++) spec[z] = Array[z*xySize + npix];
86      long *specdim = new long[2];
87      specdim[0] = zdim; specdim[1]=1;
88      Image *spectrum = new Image(specdim);
89      spectrum->saveParam(par);
90      spectrum->pars().setBeamSize(2.); // for spectrum, only neighbouring channels correlated
91//       spectrum->saveArray(spec,zdim);
92      spectrum->extractSpectrum(Array,dim,npix);
93      spectrum->setStats(specMedian[npix],specSigma[npix],par.getCut());
94//       spectrum->findStats(11);
95      if(par.getFlagFDR()) spectrum->setupFDR();
96      spectrum->setMinSize(par.getMinChannels());
97      //      spectrum->lutz_detect();
98      spectrum->spectrumDetect();
99      for(int obj=0;obj<spectrum->getNumObj();obj++){
100        Detection *object = new Detection;
101        *object = spectrum->getObject(obj);
102//      if(par.getFlagGrowth()) growObject(*object,*spectrum);
103        for(int pix=0;pix<object->getSize();pix++) {
104          // Fix up coordinates of each pixel to match original array
105          object->setZ(pix, object->getX(pix));
106          object->setX(pix, npix%dim[0]);
107          object->setY(pix, npix/dim[0]);
108        }
109        object->addOffsets(par);
110        object->calcParams();
111//      outputList.push_back(*object);
112        mergeIntoList(*object,outputList,par);
113        delete object;
114      }
115      delete spectrum;
116//       delete spec;
117      delete specdim;
118    }
119
120//     delete [] specMedian;
121//     delete [] specSigma;
122
123    num = outputList.size();
124    if(par.isVerbose())
125      std::cout <<"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFound " << num <<";" << std::flush;
126
127  }
128
129  // SECOND SEARCH --  IN EACH CHANNEL
130  // FIRST, GET STATS
131  if(par.isVerbose()) std::cout << "  2D: |                    |" << std::flush;
132  if(par.isVerbose()) std::cout << "Done  0%" << "\b\b\b\b\b\b\b\b" << std::flush;
133  float *imageMedian = new float[zdim];
134  float *imageSigma = new float[zdim];
135  for(int z=0; z<zdim; z++){
136    float *image = new float[xySize];
137    int goodSize=0;
138    for(int npix=0; npix<xySize; npix++)
139      if(isGood[z*xySize + npix]) image[goodSize++] = Array[z*xySize + npix];
140    if(goodSize>0){// findMedianStats(image,goodSize,imageMedian[z],dud);
141      findMedianStats(image,goodSize,imageMedian[z],imageSigma[z]);
142      imageSigma[z] /= correctionFactor;
143    }
144    else{// imageMedian[z] = blankPixValue;
145      imageMedian[z] = blankPixValue;
146      imageSigma[z] = 1.;
147    }
148//     if(goodSize>0) findNormalStats(image,goodSize,dud,imageSigma[z]);
149//     else imageSigma[z] = 1.;
150    delete image;
151  }
152  // NEXT, DO SOURCE FINDING
153  bool *doChannel = new bool[zdim];
154  for(int z=0;z<zdim;z++)
155    doChannel[z] = !( par.getFlagMW() && (z>=par.getMinMW()) && (z<=par.getMaxMW()) );
156
157  for(int z=0; z<zdim; z++){
158
159    if( par.isVerbose() && ((100*(z+1)/zdim)%5 == 0) ){
160      std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|";
161      for(int i=0;i<(100*(z+1)/zdim)/5;i++) std::cout << "#";
162      for(int i=(100*(z+1)/zdim)/5;i<20;i++) std::cout << " ";
163      std::cout << "|" << std::flush;
164    }
165
166    if( doChannel[z] ){
167
168//       float *image = new float[xySize];
169//       for(int npix=0; npix<xySize; npix++) image[npix] = Array[z*xySize + npix];
170      long *imdim = new long[2];
171      imdim[0] = dim[0]; imdim[1] = dim[1];
172      Image *channelImage = new Image(imdim);
173      channelImage->saveParam(par);
174//       channelImage->saveArray(image,xySize);
175      channelImage->extractImage(Array,dim,z);
176      channelImage->setStats(imageMedian[z],imageSigma[z],par.getCut());
177//       channelImage->findStats(11);
178      if(par.getFlagFDR()) channelImage->setupFDR();
179      channelImage->setMinSize(par.getMinPix());
180      channelImage->lutz_detect();
181      for(int obj=0;obj<channelImage->getNumObj();obj++){
182        Detection *object = new Detection;
183        *object = channelImage->getObject(obj);
184//      if(par.getFlagGrowth()) growObject(*object,*channelImage);
185        // Fix up coordinates of each pixel to match original array
186        for(int pix=0;pix<object->getSize();pix++) object->setZ(pix, z);
187        object->addOffsets(par);
188        object->calcParams();
189//      outputList.push_back(*object);
190        mergeIntoList(*object,outputList,par);
191        delete object;
192      }
193//       delete image;
194      delete channelImage;
195      delete imdim;
196    }
197
198  }
199
200  if(par.isVerbose())
201    std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFound " << outputList.size() - num
202              << ".                                           " << std::endl << std::flush;
203
204   delete [] imageMedian;
205   delete [] imageSigma;
206  delete [] isGood;
207  delete [] doChannel;
208
209  return outputList;
210}
Note: See TracBrowser for help on using the repository browser.