1 | #include <iostream> |
---|
2 | //#include <Cubes/cubes.hh> |
---|
3 | #include <Utils/utils.hh> |
---|
4 | using namespace std; |
---|
5 | |
---|
6 | void findSourcesAtrous1D(Image &image, Param &par) |
---|
7 | { |
---|
8 | float blankPixValue = par.getBlankPixVal(); |
---|
9 | bool flagFDR = par.getFlagFDR(); |
---|
10 | long size = image.getSize(); |
---|
11 | float *arr = new float[size]; |
---|
12 | float *newarr = new float[size]; |
---|
13 | float *resid = new float[size]; |
---|
14 | int goodSize=0; |
---|
15 | for(int i=0;i<size;i++){ |
---|
16 | if(!par.isBlank(image.getPixValue(i))) |
---|
17 | arr[goodSize++] = image.getPixValue(i); |
---|
18 | } |
---|
19 | float originalMean,originalSigma,mean,sigma; |
---|
20 | if(goodSize>0){ |
---|
21 | findMedianStats(arr,goodSize,originalMean,originalSigma); |
---|
22 | image.setStats(originalMean,originalSigma,par.getCut()); |
---|
23 | image.getArray(arr); |
---|
24 | atrous1DReconstruct(size,arr,newarr,par); |
---|
25 | |
---|
26 | goodSize=0; |
---|
27 | for(int i=0;i<size;i++) |
---|
28 | if(!par.isBlank(image.getPixValue(i))) |
---|
29 | resid[goodSize++] = arr[i] - newarr[i]; |
---|
30 | findNormalStats(resid,goodSize,mean,sigma); |
---|
31 | |
---|
32 | long *dim = new long[2]; dim[0] = size; dim[1]=1; |
---|
33 | Image *newimage = new Image(dim); |
---|
34 | // *newimage = image; |
---|
35 | newimage->saveArray(newarr,size); |
---|
36 | // newimage->setStats(mean,sigma,par.getCut()); |
---|
37 | newimage->setStats(originalMean,sigma,par.getCut()); |
---|
38 | if(flagFDR) setupFDR(*newimage,par); |
---|
39 | lutz_detect(*newimage,par); |
---|
40 | for(int obj=0;obj<newimage->getNumObj();obj++){ |
---|
41 | Detection *object = new Detection; |
---|
42 | *object = newimage->getObject(obj); |
---|
43 | for(int pix=0;pix<object->getSize();pix++) { |
---|
44 | // set the flux of each pixel in each object to the flux |
---|
45 | // in the corresponding pixel in the original image. |
---|
46 | float flux = image.getPixValue(object->getX(pix),object->getY(pix)); |
---|
47 | object->setF(pix,flux); |
---|
48 | } |
---|
49 | image.addObject(*object); |
---|
50 | maskObject(image,*object); |
---|
51 | delete object; |
---|
52 | } |
---|
53 | delete newimage; |
---|
54 | } |
---|
55 | delete [] arr; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | void findSourcesAtrous2D(Image &image, Param &par) |
---|
60 | { |
---|
61 | float blankPixValue = par.getBlankPixVal(); |
---|
62 | bool flagFDR = par.getFlagFDR(); |
---|
63 | |
---|
64 | long size = image.getSize(); |
---|
65 | float *arr = new float[size]; |
---|
66 | float *newarr = new float[size]; |
---|
67 | float *resid = new float[size]; |
---|
68 | int goodSize=0; |
---|
69 | for(int i=0;i<size;i++){ |
---|
70 | if(!par.isBlank(image.getPixValue(i))) |
---|
71 | arr[goodSize++] = image.getPixValue(i); |
---|
72 | } |
---|
73 | if(goodSize>0){ |
---|
74 | long xdim = image.getDimX(); |
---|
75 | long ydim = image.getDimY(); |
---|
76 | long *dim = new long[2]; |
---|
77 | dim[0] = xdim; dim[1] = ydim; |
---|
78 | |
---|
79 | float originalMean,originalSigma,mean,sigma; |
---|
80 | // findMedianStats(arr,goodSize,mean,sigma); |
---|
81 | findMedianStats(arr,goodSize,originalMean,originalSigma); |
---|
82 | // cerr<<"findSourcesAtrous2D: mean = "<<mean<<", sigma = "<<sigma<<endl; |
---|
83 | image.setStats(originalMean,originalSigma,par.getCut()); |
---|
84 | image.getArray(arr); |
---|
85 | // atrous2DReconstruct(xdim,ydim,arr,newarr,par); |
---|
86 | atrous2DReconstruct(xdim,ydim,arr,newarr,par); |
---|
87 | |
---|
88 | goodSize=0; |
---|
89 | for(int i=0;i<size;i++) |
---|
90 | if(!par.isBlank(image.getPixValue(i))) |
---|
91 | resid[goodSize++] = arr[i] - newarr[i]; |
---|
92 | findNormalStats(resid,goodSize,mean,sigma); |
---|
93 | |
---|
94 | Image *newimage = new Image(dim); |
---|
95 | // *newimage = image; |
---|
96 | newimage->saveArray(newarr,size); |
---|
97 | // newimage->setStats(mean,sigma,par.getCut()); |
---|
98 | newimage->setStats(originalMean,sigma,par.getCut()); |
---|
99 | if(flagFDR) setupFDR(*newimage,par); |
---|
100 | lutz_detect(*newimage,par); |
---|
101 | for(int obj=0;obj<newimage->getNumObj();obj++){ |
---|
102 | Detection *object = new Detection; |
---|
103 | *object = newimage->getObject(obj); |
---|
104 | for(int pix=0;pix<object->getSize();pix++) { |
---|
105 | // set the flux of each pixel in each object to the flux |
---|
106 | // in the corresponding pixel in the original image. |
---|
107 | float flux = image.getPixValue(object->getX(pix),object->getY(pix)); |
---|
108 | object->setF(pix,flux); |
---|
109 | } |
---|
110 | image.addObject(*object); |
---|
111 | maskObject(image,*object); |
---|
112 | delete object; |
---|
113 | } |
---|
114 | delete newimage; |
---|
115 | } |
---|
116 | delete [] arr; |
---|
117 | delete [] newarr; |
---|
118 | } |
---|
119 | |
---|