source: tags/release-0.9/Detection/thresholding_functions.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: 2.2 KB
Line 
1#include <iostream>
2#include <math.h>
3#include <Cubes/cubes.hh>
4#include <Utils/utils.hh>
5
6bool Image::isDetection(long x, long y)
7{
8  if(this->par.getFlagFDR())
9    return ( this->pValue[y*axisDim[0]+x] < this->pCutLevel );
10  else
11    return ( ((this->array[y*axisDim[0]+x]-this->mean)/this->sigma) > this->cutLevel );
12}
13
14bool Image::isDetection(float value)
15{
16  return ( ((value - this->mean) / this->sigma) > this->cutLevel ) ;
17}
18
19bool Image::isDetectionFDR(float pvalue)
20{
21  return (  pvalue < this->pCutLevel ) ;
22
23}
24
25bool isDetection(float value, float mean, float sigma, float cut)
26{
27  return ( ((value - mean) / sigma) > cut ) ;
28}
29
30int Image::setupFDR()
31{
32  this->alpha = this->par.alphaFDR;
33
34  // first calculate p-value for each pixel, using mean and sigma
35  // assume Gaussian for now.
36  bool *isGood = new bool[this->numPixels];
37  int *loopCtr = new int;
38  for(*loopCtr=0;*loopCtr<this->numPixels;(*loopCtr)++)
39    isGood[*loopCtr] = !(this->par.isBlank(this->array[*loopCtr]));
40
41  float *rootTwo = new float;
42  *rootTwo=sqrt(2.);
43  for(int j=0;j<this->numPixels;j++){
44    if(isGood[j])
45      this->pValue[j] = 0.5*erfc((this->array[j] - this->mean) / (*rootTwo * this->sigma));
46    else
47      this->pValue[j] = 1.;  //need to make this high so that it won't be below the P cut level.
48  }
49  delete rootTwo;
50
51  // now order them
52  float *orderedP = new float[this->numPixels];
53  int *count = new int;
54  *count = 0;
55  for(*loopCtr=0;*loopCtr<this->numPixels;(*loopCtr)++)
56    if(isGood[*loopCtr])
57      orderedP[(*count)++] = this->pValue[*loopCtr];
58
59  sort(orderedP,0,(*count-1));
60 
61  // now find the maximum P value.
62  int *max = new int;
63  *max = -1;
64  float *cN  = new float;
65  *cN = 0.;
66  int *psfCtr = new int;
67  int *numPix = new int;
68  *numPix = int(this->par.getBeamSize());
69  for(*psfCtr=1;*psfCtr<=*numPix;(*psfCtr)++)
70    *cN += 1./float(*psfCtr);
71  delete psfCtr;
72  delete numPix;
73
74  for(*loopCtr=0;*loopCtr<*count;(*loopCtr)++) {
75    if( orderedP[*loopCtr] < (double(*loopCtr+1)*this->alpha/(*cN * double(*count))) )
76      *max = *loopCtr;
77  }
78
79  this->pCutLevel = orderedP[*max];
80
81  delete [] orderedP;
82  delete [] isGood;
83  delete max;
84  delete cN;
85  delete count;
86  delete loopCtr;
87}
88
Note: See TracBrowser for help on using the repository browser.