d691b7f7361e2b4269427bc5753f6a3cae92bc9d
[IRC.git] / Robust / src / Benchmarks / oooJava / tracking / Lambda.java
1 public class Lambda {
2     
3     /* current processing image related */
4     float[] m_image;
5     int m_rows;
6     int m_cols;
7     int m_r;
8     
9     int m_num_p;
10     
11     /* benchmark constants */
12     int WINSZ;
13     public int N_FEA;
14
15     /* constructor */
16     public Lambda(int winsz,
17                   int nfea,
18                   int pnum,
19                   int nump) {
20       this.WINSZ = winsz;
21       this.N_FEA = nfea;
22       this.m_num_p = nump;
23     }
24     
25     public int getNumP() {
26       return this.m_num_p;
27     }
28     
29     public int getR() {
30       return this.m_r;
31     }
32     
33     public int getRows() {
34       return this.m_rows;
35     }
36     
37     public int getCols() {
38       return this.m_cols;
39     }
40     
41     public float[] getImage() {
42       return this.m_image;
43     }
44     
45     public void calcGoodFeature(ImageXM imxm,
46                                 ImageYM imym) {
47       float[] dX, dY;
48       int sizeX, sizeY, rowY, colY;
49       int i, j;
50       float[] xx, yy, xy, image;
51       int rows_xx, cols_xx, rows_yy, cols_yy, rows_xy, cols_xy;
52       float[] tr, det, c_xx, c_xy, c_yy;
53       int rows_tr, cols_tr, rows_det, cols_det, rows_cxx, cols_cxx;
54       int rows_cxy, cols_cxyrows_cyy, cols_cyy;
55       
56       dX = imxm.getImage();
57       dY = imym.getImage();
58       sizeX = imxm.getRows();
59       sizeY = imxm.getCols();
60       rowY = imym.getRows();
61       colY = imym.getCols();
62
63       rows_xx = sizeX;
64       cols_xx = sizeY;
65       xx = new float[rows_xx * cols_xx];
66       rows_xy = sizeX;
67       cols_xy = sizeY;
68       xy = new float[rows_xy * cols_xy];
69       rows_yy = sizeX;
70       cols_yy = sizeY;
71       yy = new float[rows_yy * cols_yy];
72
73       for( i=0; i<sizeX; i++) {
74         for( j=0; j<sizeY; j++) {
75           xx[i * sizeY + j] = (float)(dX[i * sizeY + j] * dX[i * sizeY + j]);
76           xy[i * sizeY + j] = (float)(dX[i * sizeY + j] * dY[i * sizeY + j]);            
77           yy[i * sizeY + j] = (float)(dY[i * sizeY + j] * dY[i * sizeY + j]);            
78         }
79       }
80
81       c_xx = calcAreaSum(xx, sizeY, sizeX);
82       c_xy = calcAreaSum(xy, sizeY, sizeX);
83       c_yy = calcAreaSum(yy, sizeY, sizeX);    
84
85       rows_tr = sizeX;
86       cols_tr = sizeY;
87       tr = new float[rows_tr * cols_tr];
88       rows_det = sizeX;
89       cols_det = sizeY;
90       det = new float[rows_det * cols_det];
91       this.m_rows = sizeX;
92       this.m_cols = sizeY;
93       image = this.m_image = new float[this.m_rows * this.m_cols];        
94
95       for( i=0; i<sizeX; i++) {
96         for( j=0; j<sizeY; j++) {
97           tr[i * sizeY + j] = c_xx[i * sizeY + j] + c_yy[i * sizeY + j];
98           det[i * sizeY + j] = c_xx[i * sizeY + j] * c_yy[i * sizeY + j] 
99                                                           - c_xy[i * sizeY + j] * c_xy[i * sizeY + j];            
100 //        lambda[i * sizeY + j] = (float)(det[i * sizeY + j]/(tr[i * sizeY + j]) + 0.00001);       
101           image[i * sizeY + j] = (float)((det[i * sizeY + j]*100000)
102               /((tr[i * sizeY + j]*100000) + 0.1));  
103         }
104       }
105     }
106
107     public float[] calcAreaSum(float[] src, 
108         int sizeY, 
109         int sizeX) {
110       int nave, nave_half, i, j, k;
111       float[] ret, a1;
112       int rows_ret, cols_ret, rows_a1, cols_a1;
113       float a1sum;
114
115       nave = this.WINSZ;
116       nave_half = (int)(Math.floor((nave+1)/2))-1;
117
118       rows_ret = sizeX;
119       cols_ret = sizeY;
120       ret = new float[rows_ret * cols_ret];
121
122       for(i=0; i<sizeX; i++) {
123         rows_a1 = 1;
124         cols_a1 = sizeY+nave;
125         a1 = new float[rows_a1 * cols_a1];
126
127         for(j=0; j<sizeY; j++) {
128           a1[j+nave_half] = src[i*sizeY+j];
129         }
130
131         a1sum = 0;
132         for(k=0; k<nave; k++) {
133           a1sum += a1[k];
134         }
135
136         for(j=0; j<sizeY; j++) {
137           ret[i*sizeY+j] = a1sum;
138           a1sum += a1[j+nave] - a1[j];
139         }
140       }
141       a1 = null;
142
143       for(i=0; i<sizeY; i++) {
144         rows_a1 = 1;
145         cols_a1 = sizeX+nave;
146         a1 = new float[rows_a1 * cols_a1];
147
148         for(j=0; j<sizeX; j++) {
149           a1[j+nave_half] = ret[j*sizeY+i];
150         }
151
152         a1sum = 0;
153         for(k=0; k<nave; k++) {
154           a1sum += a1[k];
155         }
156
157         for(j=0; j<sizeX; j++) {
158           ret[j*sizeY+i] = a1sum;
159           a1sum += a1[j+nave] - a1[j];
160         }
161       }
162       a1 = null;
163
164       return ret; 
165     }
166     
167     public void reshape() {
168       float[] out, image;
169       int i, j, k;
170       int r, c;
171
172       image = this.m_image;
173       r = this.m_rows;
174       c = this.m_cols;
175
176       out = new float[r * c];
177
178       k = 0;
179       for(i=0; i<c; i++) {
180         for(j=0; j<r; j++) {
181           out[k++] = image[j * c + i];
182         }
183       }
184       this.m_image = out;
185       this.m_rows = r * c;
186       this.m_cols = 1;
187       this.m_r= r;
188     }
189
190     
191     public void printImage() {
192       //    result validation
193       for(int i=0; i<this.m_rows; i++) {
194           for(int j=0; j<this.m_cols; j++) {
195               System.printI((int)(this.m_image[i * this.m_cols + j]*10));
196           }
197       }
198     }
199     
200     
201 }