1 | #include <iostream> |
---|
2 | #include <iomanip> |
---|
3 | #include <vector> |
---|
4 | #include <Cubes/cubes.hh> |
---|
5 | #include <Utils/utils.hh> |
---|
6 | #include <Utils/Statistics.hh> |
---|
7 | |
---|
8 | using std::vector; |
---|
9 | using std::setw; |
---|
10 | |
---|
11 | void growObject(Detection &object, Cube &cube) |
---|
12 | { |
---|
13 | /** |
---|
14 | * growObject(Detection, Cube) |
---|
15 | * A function to grow an object (given by the Detection) |
---|
16 | * out to some lower threshold. |
---|
17 | * The Cube is necessary to see both the Param list, containing |
---|
18 | * the growth threshold, and the actual array of pixel fluxes. |
---|
19 | * Each pixel has each of its neighbours examined, and if one of |
---|
20 | * them is not in the object but above the growth threshold, it |
---|
21 | * is added to the object. |
---|
22 | */ |
---|
23 | |
---|
24 | |
---|
25 | vector <bool> isInObj(cube.getSize(),false); |
---|
26 | float thresh1; |
---|
27 | float thresh2; |
---|
28 | long chanpos; |
---|
29 | |
---|
30 | for(int i=0;i<object.getSize();i++) { |
---|
31 | long pos = object.getX(i) + object.getY(i)*cube.getDimX() + |
---|
32 | object.getZ(i)*cube.getDimX()*cube.getDimY(); |
---|
33 | isInObj[pos] = true; |
---|
34 | } |
---|
35 | |
---|
36 | StatsContainer<float> growthStats = cube.getStats(); |
---|
37 | |
---|
38 | growthStats.setThresholdSNR(cube.pars().getGrowthCut()); |
---|
39 | growthStats.setUseFDR(false); |
---|
40 | |
---|
41 | for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object |
---|
42 | |
---|
43 | for(int xnbr=-1; xnbr<=1; xnbr++){ |
---|
44 | for(int ynbr=-1; ynbr<=1; ynbr++){ |
---|
45 | for(int znbr=-1; znbr<=1; znbr++){ |
---|
46 | |
---|
47 | if((xnbr!=0)||(ynbr!=0)||(znbr!=0)){ |
---|
48 | // ignore when all=0 ie. the current object pixel |
---|
49 | |
---|
50 | Voxel pixnew = object.getPixel(pix); |
---|
51 | long newx = object.getX(pix) + xnbr; |
---|
52 | long newy = object.getY(pix) + ynbr; |
---|
53 | long newz = object.getZ(pix) + znbr; |
---|
54 | |
---|
55 | if((newx<cube.getDimX())&&(newx>=0)&& |
---|
56 | (newy<cube.getDimY())&&(newy>=0)&& |
---|
57 | (newz<cube.getDimZ())&&(newz>=0)){ |
---|
58 | |
---|
59 | pixnew.setX(newx); |
---|
60 | pixnew.setY(newy); |
---|
61 | pixnew.setZ(newz); |
---|
62 | |
---|
63 | float flux; |
---|
64 | if(cube.isRecon()) flux = cube.getReconValue(newx,newy,newz); |
---|
65 | else flux = cube.getPixValue(newx,newy,newz); |
---|
66 | pixnew.setF(flux); |
---|
67 | |
---|
68 | long chanpos = newx + newy * cube.getDimX(); |
---|
69 | long pos = newx + newy * cube.getDimX() + |
---|
70 | newz * cube.getDimX() * cube.getDimY(); |
---|
71 | if( (!isInObj[pos]) && growthStats.isDetection(flux) ){ |
---|
72 | isInObj[pos] = true; |
---|
73 | object.addPixel(pixnew); |
---|
74 | } // end of if |
---|
75 | |
---|
76 | } // end of if clause regarding newx, newy, newz |
---|
77 | |
---|
78 | } // end of if clause regarding xnbr, ynbr, znbr |
---|
79 | |
---|
80 | } // end of znbr loop |
---|
81 | } // end of ynbr loop |
---|
82 | } // end of xnbr loop |
---|
83 | |
---|
84 | } // end of pix loop |
---|
85 | |
---|
86 | object.calcParams(); |
---|
87 | |
---|
88 | isInObj.clear(); |
---|
89 | |
---|
90 | } |
---|
91 | |
---|