source: tags/release-1.0.5/src/Detection/thresholding_functions.cc @ 1455

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

A few changes, mostly minor:
duchamp.hh -- added #undef statements for the PACKAGE-related definitions,

to get rid of compilation complaints.

Cubes/plotting.cc -- added call to plotBlankEdges to DetectionMap?
Cubes/cubes.cc -- added explicit calls to Column class

added new function DataArray::addObjectOffsets.
improved Cube destructor.

Cubes/detectionIO.cc -- added this-> to logColSet
Cubes/cubes.hh -- new functions getLogColSet etc. new prototype
Detection/thresholding_functions.cc -- added checks for blank-ness in detection functions.

File size: 2.4 KB
Line 
1#include <iostream>
2#include <math.h>
3#include <Cubes/cubes.hh>
4
5bool Image::isDetection(long x, long y)
6{
7  if(this->par.getFlagFDR())
8    return ( (!this->par.isBlank(this->array[y*axisDim[0]+x])) &&
9             (this->pValue[y*axisDim[0]+x] < this->pCutLevel)     );
10  else
11    return ( (!this->par.isBlank(this->array[y*axisDim[0]+x])) &&
12             ( ((this->array[y*axisDim[0]+x]-this->mean)/this->sigma)
13               > this->cutLevel ) );
14}
15
16bool Image::isDetection(float value)
17{
18  return ( (!this->par.isBlank(value)) &&
19           (((value - this->mean) / this->sigma) > this->cutLevel) );
20}
21
22bool Image::isDetectionFDR(float pvalue)
23{
24  return (  (pvalue < this->pCutLevel ) );
25
26}
27
28bool isDetection(float value, float mean, float sigma, float cut)
29{
30  return ( ((value - mean) / sigma) > cut ) ;
31}
32
33int Image::setupFDR()
34{
35  /**
36   *  Image::setupFDR()
37   *   Determines the critical Prob value for the False Discovery Rate
38   *    detection routine. All pixels with Prob less than this value will
39   *    be considered detections.
40   *   The Prob here is the probability, assuming a Normal distribution, of
41   *    obtaining a value as high or higher than the pixel value (ie. only the
42   *    positive tail of the PDF)
43   */
44
45  this->alpha = this->par.alphaFDR;
46
47  // first calculate p-value for each pixel, using mean and sigma
48  // assume Gaussian for now.
49
50  float *orderedP = new float[this->numPixels];
51  int count = 0;
52  for(int pix=0; pix<this->numPixels; pix++){
53
54    if( !(this->par.isBlank(this->array[pix])) ){
55      float zStat = (this->array[pix] - this->mean) / (this->sigma);
56      this->pValue[pix] = 0.5 * erfc(zStat/M_SQRT2);
57      // Want the factor of 0.5 here, as we are only considering the positive tail
58      //  of the distribution. Don't care about negative detections.
59     
60      orderedP[count++] = this->pValue[pix];
61    }
62    else this->pValue[pix] = 1.0;
63    //need to make this high so that it won't be below the P cut level.
64  }
65
66  // now order them
67  sort(orderedP,0,count);
68 
69  // now find the maximum P value.
70  int max = 0;
71  float cN = 0.;
72  int psfCtr;
73  int numPix = int(this->par.getBeamSize());
74  for(psfCtr=1;psfCtr<=numPix;(psfCtr)++)
75    cN += 1./float(psfCtr);
76
77  for(int loopCtr=0;loopCtr<count;loopCtr++) {
78    if( orderedP[loopCtr] < (double(loopCtr+1)*this->alpha/(cN * double(count))) ) {
79      max = loopCtr;
80    }
81  }
82
83  this->pCutLevel = orderedP[max];
84
85  delete [] orderedP;
86
87}
88
Note: See TracBrowser for help on using the repository browser.