add tracking benchmark
[IRC.git] / Robust / src / Benchmarks / oooJava / tracking / ImageXM.java
1 public class ImageXM {
2     
3     /* current processing image related */
4     float[] m_image;
5     int m_rows;
6     int m_cols;
7
8     int m_counter;
9     
10     /* constructor */
11     public ImageXM(int counter,
12                    int rows,
13                    int cols) {
14       this.m_counter = counter;
15       this.m_rows = rows;
16       this.m_cols = cols;
17       this.m_image = new float[rows * cols];
18     }
19
20     public int getRows() {
21       return this.m_rows;
22     }
23     
24     public int getCols() {
25       return this.m_cols;
26     }
27     
28     public float[] getImage() {
29       return this.m_image;
30     }
31
32     public boolean addCalcSobelResult(ImageX imx) {
33       int startRow = imx.getRowsRS();
34       int endRow = imx.getRowsRE();
35       int i, j, k, cols;
36       float[] image, r;
37       
38       image = this.m_image;
39       this.m_counter--;
40       cols = this.m_cols;
41       
42       // clone data piece      
43       r = imx.getResult();
44       k = 0;
45       for(i = startRow; i < endRow; i++) {
46         for(j = 0; j < cols; j++) {
47           image[i * cols + j] = r[k * cols + j];
48         }
49         k++;
50       }
51       
52       return (0 == this.m_counter);
53     }
54     
55     public void calcSobel_dX() {
56       int rows_k1, cols_k1, rows_k2, cols_k2;
57       int[] kernel_1, kernel_2;
58       float temp;
59       int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
60       int k, i, j, kernelSum_1, kernelSum_2;
61       float[] result, image;
62       int rows = this.m_rows;
63       int cols = this.m_cols;
64
65       image = this.m_image;
66       
67       rows_k1 = 1;
68       cols_k1 = 3;
69       kernel_1 = new int[rows_k1 * cols_k1];
70       rows_k2 = 1;
71       cols_k2 = 3;
72       kernel_2 = new int[rows_k2 * cols_k2];   
73
74       kernel_1[0] = 1;
75       kernel_1[1] = 2;
76       kernel_1[2] = 1;
77
78       kernelSize = 3;
79       kernelSum_1 = 4;
80       
81       kernel_2[0] = 1;
82       kernel_2[1] = 0;
83       kernel_2[2] = -1;
84
85       kernelSum_2 = 2;
86
87       startCol = 1;           //((kernelSize)/2);
88       endCol = cols - 1;      //(int)(cols - (kernelSize/2));
89       halfKernel = 1;         //(kernelSize-1)/2;
90
91       startRow = 1;       //(kernelSize)/2;
92       endRow = (rows-1);  //(rows - (kernelSize)/2);
93
94       for(i=startRow; i<endRow; i++) {
95           for(j=startCol; j<endCol; j++) {
96               temp = 0;
97               for(k=-halfKernel; k<=halfKernel; k++) {
98                   temp += (float)(image[(i+k) * cols + j] 
99                                          * (float)(kernel_1[k+halfKernel]));
100               }
101               image[i * cols + j] = (float)(temp/kernelSum_1);
102               image[i * cols + j] = (float)(image[i * cols + j] + 128);
103           }
104       }
105     }
106     
107     public void printImage() {
108       //    result validation
109       for(int i=0; i<this.m_rows; i++) {
110           for(int j=0; j<this.m_cols; j++) {
111               System.printI((int)(this.m_image[i * this.m_cols + j]*10));
112           }
113       }
114     }
115 }