1 | #include <iostream> |
---|
2 | #include <iomanip> |
---|
3 | #include <vector> |
---|
4 | #include <Cubes/cubes.hh> |
---|
5 | #include <Utils/utils.hh> |
---|
6 | |
---|
7 | using std::vector; |
---|
8 | using std::setw; |
---|
9 | |
---|
10 | void growObject(Detection &object, Cube &cube) |
---|
11 | { |
---|
12 | /** |
---|
13 | * growObject(Detection, Cube) |
---|
14 | * A function to grow an object (given by the Detection) |
---|
15 | * out to some lower threshold. |
---|
16 | * The Cube is necessary to see both the Param list, containing |
---|
17 | * the growth threshold, and the actual array of pixel fluxes. |
---|
18 | * Each pixel has each of its neighbours examined, and if one of |
---|
19 | * them is not in the object but above the growth threshold, it |
---|
20 | * is added to the object. |
---|
21 | */ |
---|
22 | |
---|
23 | |
---|
24 | vector <bool> isInObj(cube.getSize(),false); |
---|
25 | float thresh1; |
---|
26 | float thresh2; |
---|
27 | long chanpos; |
---|
28 | |
---|
29 | for(int i=0;i<object.getSize();i++) { |
---|
30 | long pos = object.getX(i) + object.getY(i)*cube.getDimX() + |
---|
31 | object.getZ(i)*cube.getDimX()*cube.getDimY(); |
---|
32 | isInObj[pos] = true; |
---|
33 | } |
---|
34 | float cut = cube.pars().getGrowthCut(); |
---|
35 | |
---|
36 | for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object |
---|
37 | |
---|
38 | for(int xnbr=-1; xnbr<=1; xnbr++){ |
---|
39 | for(int ynbr=-1; ynbr<=1; ynbr++){ |
---|
40 | for(int znbr=-1; znbr<=1; znbr++){ |
---|
41 | |
---|
42 | if((xnbr!=0)||(ynbr!=0)||(znbr!=0)){ |
---|
43 | // ignore when all=0 ie. the current object pixel |
---|
44 | |
---|
45 | Voxel pixnew = object.getPixel(pix); |
---|
46 | long newx = object.getX(pix) + xnbr; |
---|
47 | long newy = object.getY(pix) + ynbr; |
---|
48 | long newz = object.getZ(pix) + znbr; |
---|
49 | |
---|
50 | if((newx<cube.getDimX())&&(newx>=0)&& |
---|
51 | (newy<cube.getDimY())&&(newy>=0)&& |
---|
52 | (newz<cube.getDimZ())&&(newz>=0)){ |
---|
53 | |
---|
54 | pixnew.setX(newx); |
---|
55 | pixnew.setY(newy); |
---|
56 | pixnew.setZ(newz); |
---|
57 | // In following R=recon, B=baseline |
---|
58 | // Four cases: i) B+R -- use recon |
---|
59 | // ii) R -- use recon |
---|
60 | // iii) B -- use array |
---|
61 | // iv) none-- use array |
---|
62 | float flux; |
---|
63 | if(cube.isRecon()) flux = cube.getReconValue(newx,newy,newz); |
---|
64 | else flux = cube.getPixValue(newx,newy,newz); |
---|
65 | pixnew.setF(flux); |
---|
66 | |
---|
67 | long chanpos = newx + newy * cube.getDimX(); |
---|
68 | long pos = newx + newy * cube.getDimX() + |
---|
69 | newz * cube.getDimX() * cube.getDimY(); |
---|
70 | // thresh1 = spectral growth threshold |
---|
71 | float thresh1 = cube.getSpecMean(chanpos) + cut * cube.getSpecSigma(chanpos); |
---|
72 | // thresh2 = channel map growth threshold |
---|
73 | float thresh2 = cube.getChanMean(newz) + cut * cube.getChanSigma(newz); |
---|
74 | if( (!isInObj[pos]) && ( (flux > thresh1) || (flux > thresh2) ) ){ |
---|
75 | isInObj[pos] = true; |
---|
76 | object.addPixel(pixnew); |
---|
77 | } // end of if |
---|
78 | |
---|
79 | } // end of if clause regarding newx, newy, newz |
---|
80 | |
---|
81 | } // end of if clause regarding xnbr, ynbr, znbr |
---|
82 | |
---|
83 | } // end of znbr loop |
---|
84 | } // end of ynbr loop |
---|
85 | } // end of xnbr loop |
---|
86 | |
---|
87 | } // end of pix loop |
---|
88 | |
---|
89 | object.calcParams(); |
---|
90 | |
---|
91 | isInObj.clear(); |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | void growObject(Detection &object, Image &image) |
---|
98 | { |
---|
99 | vector <bool> isInObj(image.getSize(),false); |
---|
100 | for(int i=0;i<object.getSize();i++) |
---|
101 | isInObj[object.getX(i) + object.getY(i)*image.getDimX()] = true; |
---|
102 | |
---|
103 | for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object |
---|
104 | |
---|
105 | for(int xnbr=-1; xnbr<=1; xnbr++){ |
---|
106 | for(int ynbr=-1; ynbr<=1; ynbr++){ |
---|
107 | if((xnbr!=0)||(ynbr!=0)){ // ignore when both=0 ie. the current object pixel |
---|
108 | |
---|
109 | Voxel *pixnew = new Voxel; |
---|
110 | *pixnew = object.getPixel(pix); |
---|
111 | long newx = object.getX(pix) + xnbr; |
---|
112 | long newy = object.getY(pix) + ynbr; |
---|
113 | |
---|
114 | if((newx<image.getDimX())&&(newy<image.getDimY())&&(newx>=0)&&(newy>=0)){ |
---|
115 | |
---|
116 | pixnew->setX(newx); |
---|
117 | pixnew->setY(newy); |
---|
118 | pixnew->setF(image.getPixValue(newx,newy)); |
---|
119 | |
---|
120 | if( (!isInObj[newx+newy*image.getDimX()]) && |
---|
121 | (isDetection(pixnew->getF(), image.getMean(), |
---|
122 | image.getSigma(), image.pars().getGrowthCut())) ){ |
---|
123 | isInObj[newx+newy*image.getDimX()] = true; |
---|
124 | object.addPixel(*pixnew); |
---|
125 | } |
---|
126 | } |
---|
127 | delete pixnew; |
---|
128 | } |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | isInObj.clear(); |
---|
135 | |
---|
136 | } |
---|