e6200c132972a9baa84f6b1c87610a06c2ddfd2b
[IRC.git] / Robust / src / Benchmarks / Scheduling / Tracking / IYLM.java
1 public class IYLM {
2     flag tomergeIYL;
3     flag toaddIYL;
4     flag finish;
5     
6     /* current processing image related */
7     float[] m_image;
8     int m_rows;
9     int m_cols;
10     
11     /* current processing image related */
12     float[] m_result;
13     int m_rows_r;
14     int m_cols_r;
15     
16     int m_counter;
17     
18     /* processing type */
19     int m_id_t; // 0--Ipyr1; 1--Ipyr2;
20     
21     /* constructor */
22     public IYLM(int tid,
23                 int counter,
24                 float[] data,
25                 int rows,
26                 int cols) {
27       this.m_id_t = tid;
28       this.m_counter = counter;
29       this.m_rows = this.m_rows_r = rows;
30       this.m_cols = this.m_cols_r = cols;
31       this.m_image = data;
32       this.m_result = new float[rows * cols];
33     }
34     
35     public int getIdT() {
36       return this.m_id_t;
37     }
38     
39     public int getRows() {
40       return this.m_rows;
41     }
42     
43     public int getCols() {
44       return this.m_cols;
45     }
46     
47     public float[] getImage() {
48       return this.m_image;
49     }
50     
51     public int getRowsR() {
52       return this.m_rows_r;
53     }
54     
55     public int getColsR() {
56       return this.m_cols_r;
57     }
58     
59     public float[] getResult() {
60       return this.m_result;
61     }
62     
63     public boolean addCalcSobelResult(IYL iyl) {
64       int startRow = iyl.getRowsRS();
65       int endRow = iyl.getRowsRE();
66       int i, j, k, cols;
67       float[] image, r;
68       
69       image = this.m_result;
70       this.m_counter--;
71       cols = this.m_cols_r;
72       
73       // clone data piece      
74       r = iyl.getResult();
75       k = 0;
76       for(i = startRow; i < endRow; i++) {
77         for(j = 0; j < cols; j++) {
78           image[i * cols + j] = r[k * cols + j];
79         }
80         k++;
81       }
82       
83       return (0 == this.m_counter);
84     }
85     
86     public void calcSobel_dY() {
87       int rows_k1, cols_k1, rows_k2, cols_k2;
88       int[] kernel_1, kernel_2;
89       float temp;
90       int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
91       int k, i, j, kernelSum_1, kernelSum_2;
92       float[] result, image;
93       int rows = this.m_rows_r;
94       int cols = this.m_cols_r;
95       
96       // level 1 is the base image.
97       
98       image = this.m_result;
99       
100       rows_k1 = 1;
101       cols_k1 = 3;
102       kernel_1 = new int[rows_k1 * cols_k1];
103       rows_k2 = 1;
104       cols_k2 = 3;
105       kernel_2 = new int[rows_k2 * cols_k2];
106
107       kernel_1[0] = 1;
108       kernel_1[1] = 0;
109       kernel_1[2] = -1;
110
111       kernelSize = 3;
112       kernelSum_1 = 2;
113       
114       kernel_2[0] = 1;
115       kernel_2[1] = 2;
116       kernel_2[2] = 1;
117
118       kernelSum_2 = 4;
119
120       startCol = 1;       //(kernelSize/2);
121       endCol = cols - 1;  //(int)(cols - (kernelSize/2));
122       halfKernel = 1;     //(kernelSize-1)/2;
123
124       startRow = 1;       //(kernelSize)/2;
125       endRow = (rows-1);  //(rows - (kernelSize)/2);
126
127       for(i=startRow; i<endRow; i++) {
128           for(j=startCol; j<endCol; j++) {
129               temp = 0;
130               for(k=-halfKernel; k<=halfKernel; k++) {
131                   temp += (float)(image[(i+k) * cols + j] 
132                                          * (float)(kernel_1[k+halfKernel]));
133               }
134               image[i * cols + j] = (float)(temp/kernelSum_1);
135               image[i * cols + j] = (float)(image[i * cols + j] + 128);
136           }
137       }
138     }
139     
140     public void printImage() {
141       //    result validation
142       for(int i=0; i<this.m_rows; i++) {
143           for(int j=0; j<this.m_cols; j++) {
144               System.printI((int)(this.m_image[i * this.m_cols + j]*10));
145           }
146       }
147     }
148     
149     public void printResult() {
150       //    result validation
151       for(int i=0; i<this.m_rows_r; i++) {
152           for(int j=0; j<this.m_cols_r; j++) {
153               System.printI((int)(this.m_result[i * this.m_cols_r + j]*10));
154           }
155       }
156     }
157 }