--- /dev/null
+public class BlurPiece {
+
+ /* current processing image related */
+ int[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* results related */
+ float[] m_result;
+ int m_rows_rs;
+ int m_rows_re;
+ int m_cols_r;
+
+ /* id indicating the piece # */
+ int m_id;
+ int m_range;
+
+ /* constructor */
+ public BlurPiece(int id,
+ int range,
+ int[] data) {
+ this.m_id = id;
+ this.m_range = range;
+ this.m_image = data;
+ this.m_rows = data[0];
+ this.m_cols = data[1];
+ }
+
+ public int getId() {
+ return this.m_id;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public int getRowsRS() {
+ return this.m_rows_rs;
+ }
+
+ public int getRowsRE() {
+ return this.m_rows_re;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public void blur() {
+ int rows, cols;
+ float temp;
+ int[] kernel, imageIn;
+ int rows_k, cols_k;
+ int k, i, j;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow, kernelSum;
+ int[] inputs;
+ float[] image;
+
+ inputs = this.m_image;
+ rows = this.m_rows;
+ cols = this.m_cols;
+ this.m_rows_rs = this.m_id * this.m_range;
+ this.m_rows_re = (this.m_id + 1) * this.m_range;
+ if(rows < this.m_rows_re) {
+ this.m_rows_re = rows;
+ }
+ this.m_cols_r = this.m_cols;
+ image = this.m_result = new float[(this.m_rows_re-this.m_rows_rs)*cols];
+
+ kernel = new int[5];
+ rows_k = 1;
+ cols_k = 5;
+
+ kernel[0] = 1;
+ kernel[1] = 4;
+ kernel[2] = 6;
+ kernel[3] = 4;
+ kernel[4] = 1;
+
+ kernelSize = 5;
+ kernelSum = 16;
+
+ startCol = 2; //((kernelSize)/2);
+ endCol = cols - 2; //round(cols - (kernelSize/2));
+ halfKernel = 2; //(kernelSize-1)/2;
+
+ if((this.m_rows_re <= 2) || (this.m_rows_rs >= rows - 2)) {
+ return;
+ }
+ startRow = (2>this.m_rows_rs)?2:(this.m_rows_rs); //(kernelSize)/2;
+ endRow = ((rows-2)<this.m_rows_re)?(rows-2):(this.m_rows_re); //(rows - (kernelSize)/2);
+
+ int ii = startRow - this.m_rows_rs;
+ for(i=startRow; i<endRow; i++){
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)((inputs[4 + i * cols + (j+k)]
+ * (float)(kernel[k+halfKernel])));
+ }
+
+ image[ii * cols + j] = (float)(temp/kernelSum);
+ }
+ ii++;
+ }
+
+ /*ii = startRow - this.m_rows_rs;
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)((image[(ii+k) * cols + j]
+ * (float)(kernel[k+halfKernel])));
+ }
+ image[ii * cols + j] = (float)(temp/kernelSum);
+ }
+ ii++;
+ }*/
+ }
+
+ public void printImage() {
+ // result validation
+ System.printI(33333333);
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI(this.m_image[i * this.m_cols + j + 4]);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class BlurPieceL {
+
+ /* current processing image related */
+ int[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* results related */
+ float[] m_result;
+ int m_rows_rs;
+ int m_rows_re;
+ int m_cols_r;
+
+ /* id indicating the piece # */
+ int m_id;
+ int m_range;
+
+ /* constructor */
+ public BlurPieceL(int id,
+ int range,
+ int[] data) {
+ this.m_id = id;
+ this.m_range = range;
+ this.m_image = data;
+ this.m_rows = data[0];
+ this.m_cols = data[1];
+ }
+
+ public int getId() {
+ return this.m_id;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public int getRowsRS() {
+ return this.m_rows_rs;
+ }
+
+ public int getRowsRE() {
+ return this.m_rows_re;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public void blur() {
+ int rows, cols;
+ float temp;
+ int[] kernel, imageIn;
+ int rows_k, cols_k;
+ int k, i, j;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow, kernelSum;
+ int[] inputs;
+ float[] image;
+
+ inputs = this.m_image;
+ rows = this.m_rows;
+ cols = this.m_cols;
+ this.m_rows_rs = this.m_id * this.m_range;
+ this.m_rows_re = (this.m_id + 1) * this.m_range;
+ if(rows < this.m_rows_re) {
+ this.m_rows_re = rows;
+ }
+ this.m_cols_r = this.m_cols;
+ image = this.m_result = new float[(this.m_rows_re-this.m_rows_rs)*cols];
+
+ kernel = new int[5];
+ rows_k = 1;
+ cols_k = 5;
+
+ kernel[0] = 1;
+ kernel[1] = 4;
+ kernel[2] = 6;
+ kernel[3] = 4;
+ kernel[4] = 1;
+
+ kernelSize = 5;
+ kernelSum = 16;
+
+ startCol = 2; //((kernelSize)/2);
+ endCol = cols - 2; //round(cols - (kernelSize/2));
+ halfKernel = 2; //(kernelSize-1)/2;
+
+ if((this.m_rows_re <= 2) || (this.m_rows_rs >= rows - 2)) {
+ return;
+ }
+ startRow = (2>this.m_rows_rs)?2:(this.m_rows_rs); //(kernelSize)/2;
+ endRow = ((rows-2)<this.m_rows_re)?(rows-2):(this.m_rows_re); //(rows - (kernelSize)/2);
+
+ int ii = startRow - this.m_rows_rs;
+ for(i=startRow; i<endRow; i++){
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)((inputs[4 + i * cols + (j+k)]
+ * (float)(kernel[k+halfKernel])));
+ }
+
+ image[ii * cols + j] = (float)(temp/kernelSum);
+ }
+ ii++;
+ }
+
+ /*ii = startRow - this.m_rows_rs;
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)((image[(ii+k) * cols + j]
+ * (float)(kernel[k+halfKernel])));
+ }
+ image[ii * cols + j] = (float)(temp/kernelSum);
+ }
+ ii++;
+ }*/
+ }
+
+ public void printImage() {
+ // result validation
+ System.printI(33333333);
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI(this.m_image[i * this.m_cols + j + 4]);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class IDX {
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+ int m_r;
+
+ /* results related */
+ int m_rows_rs;
+ int m_rows_re;
+ int m_cols_r;
+ int[] m_ind;
+
+ /* benchmark constants */
+ public int N_FEA;
+
+ /* id indicating the piece # */
+ int m_id;
+ int m_range;
+
+ /* constructor */
+ public IDX(int nfea,
+ int id,
+ int range,
+ float[] data,
+ int rows,
+ int cols,
+ int r) {
+ this.N_FEA = nfea;
+
+ this.m_id = id;
+ this.m_range = range;
+
+ this.m_image = data;
+ this.m_rows = rows;
+ this.m_cols = cols;
+ this.m_r = r;
+
+ this.m_rows_rs = this.m_id * this.m_range;
+ this.m_rows_re = (this.m_id + 1) * this.m_range;
+ this.m_cols_r = cols;
+
+ this.m_ind = new int[(this.m_rows_re - this.m_rows_rs) * this.m_cols_r];
+ }
+
+ public int getR() {
+ return this.m_r;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public int[] getInd() {
+ return this.m_ind;
+ }
+
+ public int getRowsRS() {
+ return this.m_rows_rs;
+ }
+
+ public int getRowsRE() {
+ return this.m_rows_re;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public void fSortIndices() {
+ int i, j, k, startRow, endRow;
+ int[] ind;
+ int rows_i, cols_i;
+ float[] image;
+
+ image = this.m_image;
+
+ rows_i = this.m_rows;
+ cols_i = this.m_cols;
+ ind = this.m_ind;
+
+ startRow = this.m_rows_rs;
+ endRow = this.m_rows_re;
+ int ii = 0;
+ for(k=0; k<cols_i; k++) {
+ for(i=0; i<rows_i; i++) {
+ float local = image[i * cols_i + k];
+ ii = 0;
+ for(j=startRow; j<endRow; j++) {
+ if(local <= image[j*cols_i+k]) {
+ ind[ii * cols_i + k]++;
+ }
+ ii++;
+ }
+ }
+ }
+ }
+
+ public void printImage() {
+ // result validation
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI((int)(this.m_image[i * this.m_cols + j]*10));
+ }
+ }
+ }
+
+ public void printInd() {
+ // result validation
+ System.printI(44444444);
+ for(int i=0; i<this.m_rows_re-this.m_rows_rs; i++) {
+ for(int j=0; j<this.m_cols_r; j++) {
+ System.printI((int)(this.m_ind[i * this.m_cols_r + j]*10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class IXL {
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* results related */
+ float[] m_result;
+ int m_rows_rs;
+ int m_rows_re;
+ int m_cols_r;
+
+ /* id indicating the piece # */
+ int m_id;
+ int m_range;
+
+ /* constructor */
+ public IXL(int id, int range, float[] data, int rows, int cols) {
+ this.m_id = id;
+ this.m_range = range;
+ this.m_image = data;
+ this.m_rows = rows;
+ this.m_cols = cols;
+ }
+
+ public int getId() {
+ return this.m_id;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public int getRowsRS() {
+ return this.m_rows_rs;
+ }
+
+ public int getRowsRE() {
+ return this.m_rows_re;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public void calcSobel_dX() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ image = this.m_image;
+
+ this.m_rows_rs = this.m_id * this.m_range;
+ this.m_rows_re = (this.m_id + 1) * this.m_range;
+ this.m_cols_r = cols;
+ result = this.m_result = new float[(this.m_rows_re - this.m_rows_rs) * this.m_cols_r];
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 2;
+ kernel_1[2] = 1;
+
+ kernelSize = 3;
+ kernelSum_1 = 4;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 0;
+ kernel_2[2] = -1;
+
+ kernelSum_2 = 2;
+
+ startCol = 1; // ((kernelSize)/2);
+ endCol = cols - 1; // (int)(cols - (kernelSize/2));
+ halfKernel = 1; // (kernelSize-1)/2;
+
+ if ((this.m_rows_re < 1) || (this.m_rows_rs > rows - 1)) {
+ return;
+ }
+ startRow = (1 > this.m_rows_rs) ? 1 : (this.m_rows_rs); // (kernelSize)/2;
+ endRow = ((rows - 1) < this.m_rows_re) ? (rows - 1) : (this.m_rows_re); // (rows
+ // -
+ // (kernelSize)/2);
+
+ int ii = startRow - this.m_rows_rs;
+ for (i = startRow; i < endRow; i++) {
+ for (j = startCol; j < endCol; j++) {
+ temp = 0;
+ for (k = -halfKernel; k <= halfKernel; k++) {
+ temp += (float) (image[i * cols + (j + k)] * (float) (kernel_2[k + halfKernel]));
+ }
+ result[ii * cols + j] = (float) (temp / kernelSum_2);
+ }
+ ii++;
+ }
+ }
+
+ public void printResult() {
+ // result validation
+ System.printI(11111111);
+ for (int i = 0; i < this.m_rows_re - this.m_rows_rs; i++) {
+ for (int j = 0; j < this.m_cols_r; j++) {
+ System.printI((int) (this.m_result[i * this.m_cols_r + j] * 10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class IXLM {
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* current processing image related */
+ float[] m_result;
+ int m_rows_r;
+ int m_cols_r;
+
+ int m_counter;
+
+ /* constructor */
+ public IXLM(int counter,
+ float[] data,
+ int rows,
+ int cols) {
+ this.m_counter = counter;
+ this.m_rows = this.m_rows_r = rows;
+ this.m_cols = this.m_cols_r = cols;
+ this.m_image = data;
+ this.m_result = new float[rows * cols];
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public int getRowsR() {
+ return this.m_rows_r;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public boolean addCalcSobelResult(IXL ixl) {
+ int startRow = ixl.getRowsRS();
+ int endRow = ixl.getRowsRE();
+ int i, j, k, cols;
+ float[] image, r;
+
+ image = this.m_result;
+ this.m_counter--;
+ cols = this.m_cols_r;
+
+ // clone data piece
+ r = ixl.getResult();
+ k = 0;
+ for(i = startRow; i < endRow; i++) {
+ for(j = 0; j < cols; j++) {
+ image[i * cols + j] = r[k * cols + j];
+ }
+ k++;
+ }
+
+ return (0 == this.m_counter);
+ }
+
+ public void calcSobel_dX() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows_r;
+ int cols = this.m_cols_r;
+
+ image = this.m_result;
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 2;
+ kernel_1[2] = 1;
+
+ kernelSize = 3;
+ kernelSum_1 = 4;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 0;
+ kernel_2[2] = -1;
+
+ kernelSum_2 = 2;
+
+ startCol = 1; //((kernelSize)/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ startRow = 1; //(kernelSize)/2;
+ endRow = (rows-1); //(rows - (kernelSize)/2);
+
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[(i+k) * cols + j]
+ * (float)(kernel_1[k+halfKernel]));
+ }
+ image[i * cols + j] = (float)(temp/kernelSum_1);
+ image[i * cols + j] = (float)(image[i * cols + j] + 128);
+ }
+ }
+ }
+
+ public void printImage() {
+ // result validation
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI((int)(this.m_image[i * this.m_cols + j]*10));
+ }
+ }
+ }
+
+ public void printResult() {
+ // result validation
+ for(int i=0; i<this.m_rows_r; i++) {
+ for(int j=0; j<this.m_cols_r; j++) {
+ System.printI((int)(this.m_result[i * this.m_cols_r + j]*10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class IXLMR {
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* current processing image related */
+ float[] m_result;
+ int m_rows_r;
+ int m_cols_r;
+
+ int m_counter;
+
+ /* constructor */
+ public IXLMR(int counter,
+ float[] data,
+ int rows,
+ int cols) {
+ this.m_counter = counter;
+ this.m_rows = this.m_rows_r = rows;
+ this.m_cols = this.m_cols_r = cols;
+ this.m_image = data;
+ this.m_result = new float[rows * cols];
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public int getRowsR() {
+ return this.m_rows_r;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public boolean addCalcSobelResult(IXLR ixl) {
+ int startRow = ixl.getRowsRS();
+ int endRow = ixl.getRowsRE();
+ int i, j, k, cols;
+ float[] image, r;
+
+ image = this.m_result;
+ this.m_counter--;
+ cols = this.m_cols_r;
+
+ // clone data piece
+ r = ixl.getResult();
+ k = 0;
+ for(i = startRow; i < endRow; i++) {
+ for(j = 0; j < cols; j++) {
+ image[i * cols + j] = r[k * cols + j];
+ }
+ k++;
+ }
+
+ return (0 == this.m_counter);
+ }
+
+ public void calcSobel_dX() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows_r;
+ int cols = this.m_cols_r;
+
+ image = this.m_result;
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 2;
+ kernel_1[2] = 1;
+
+ kernelSize = 3;
+ kernelSum_1 = 4;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 0;
+ kernel_2[2] = -1;
+
+ kernelSum_2 = 2;
+
+ startCol = 1; //((kernelSize)/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ startRow = 1; //(kernelSize)/2;
+ endRow = (rows-1); //(rows - (kernelSize)/2);
+
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[(i+k) * cols + j]
+ * (float)(kernel_1[k+halfKernel]));
+ }
+ image[i * cols + j] = (float)(temp/kernelSum_1);
+ image[i * cols + j] = (float)(image[i * cols + j] + 128);
+ }
+ }
+ }
+
+ public void printImage() {
+ // result validation
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI((int)(this.m_image[i * this.m_cols + j]*10));
+ }
+ }
+ }
+
+ public void printResult() {
+ // result validation
+ for(int i=0; i<this.m_rows_r; i++) {
+ for(int j=0; j<this.m_cols_r; j++) {
+ System.printI((int)(this.m_result[i * this.m_cols_r + j]*10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class IXLR {
+
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* results related */
+ float[] m_result;
+ int m_rows_rs;
+ int m_rows_re;
+ int m_cols_r;
+
+ /* id indicating the piece # */
+ int m_id;
+ int m_range;
+
+ /* constructor */
+ public IXLR(int id,
+ int range,
+ float[] data,
+ int rows,
+ int cols) {
+ this.m_id = id;
+ this.m_range = range;
+ this.m_image = data;
+ this.m_rows = rows;
+ this.m_cols = cols;
+ }
+
+ public int getId() {
+ return this.m_id;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public int getRowsRS() {
+ return this.m_rows_rs;
+ }
+
+ public int getRowsRE() {
+ return this.m_rows_re;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public void calcSobel_dX() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ image = this.m_image;
+
+ this.m_rows_rs = this.m_id * this.m_range;
+ this.m_rows_re = (this.m_id + 1) * this.m_range;
+ this.m_cols_r = cols;
+ result=this.m_result=new float[(this.m_rows_re-this.m_rows_rs)*this.m_cols_r];
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 2;
+ kernel_1[2] = 1;
+
+ kernelSize = 3;
+ kernelSum_1 = 4;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 0;
+ kernel_2[2] = -1;
+
+ kernelSum_2 = 2;
+
+ startCol = 1; //((kernelSize)/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ if((this.m_rows_re < 1) || (this.m_rows_rs > rows - 1)) {
+ return;
+ }
+ startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2;
+ endRow = ((rows-1)<this.m_rows_re)?(rows-1):(this.m_rows_re); //(rows - (kernelSize)/2);
+
+ int ii = startRow - this.m_rows_rs;
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[i * cols + (j+k)]
+ * (float)(kernel_2[k+halfKernel]));
+ }
+ result[ii * cols + j] = (float)(temp/kernelSum_2);
+ }
+ ii++;
+ }
+ }
+
+ public void printResult() {
+ // result validation
+ System.printI(11111111);
+ for(int i=0; i<this.m_rows_re-this.m_rows_rs; i++) {
+ for(int j=0; j<this.m_cols_r; j++) {
+ System.printI((int)(this.m_result[i * this.m_cols_r + j]*10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class IYL {
+
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* results related */
+ float[] m_result;
+ int m_rows_rs;
+ int m_rows_re;
+ int m_cols_r;
+
+ /* id indicating the piece # */
+ int m_id;
+ int m_range;
+
+ /* constructor */
+ public IYL(int id,
+ int range,
+ float[] image,
+ int rows,
+ int cols) {
+ this.m_id = id;
+ this.m_range = range;
+ this.m_image = image;
+ this.m_rows = rows;
+ this.m_cols = cols;
+ }
+
+ public int getId() {
+ return this.m_id;
+ }
+
+ public int getRowsRS() {
+ return this.m_rows_rs;
+ }
+
+ public int getRowsRE() {
+ return this.m_rows_re;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public void calcSobel_dY() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ // level 1 is the base image.
+
+ image = this.m_image;
+
+ this.m_rows_rs = this.m_id * this.m_range;
+ this.m_rows_re = (this.m_id + 1) * this.m_range;
+ this.m_cols_r = cols;
+ result=this.m_result=new float[(this.m_rows_re-this.m_rows_rs)*this.m_cols_r];
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 0;
+ kernel_1[2] = -1;
+
+ kernelSize = 3;
+ kernelSum_1 = 2;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 2;
+ kernel_2[2] = 1;
+
+ kernelSum_2 = 4;
+
+ startCol = 1; //(kernelSize/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ if((this.m_rows_re < 1) || (this.m_rows_rs > rows - 1)) {
+ return;
+ }
+ startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2;
+ endRow = ((rows-1)<this.m_rows_re)?(rows-1):(this.m_rows_re); //(rows - (kernelSize)/2);
+
+ int ii = startRow - this.m_rows_rs;
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[i * cols + (j+k)]
+ * (float)(kernel_2[k+halfKernel]));
+ }
+ result[ii * cols + j] = (float)(temp/kernelSum_2);
+ }
+ ii++;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class IYLM {
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* current processing image related */
+ float[] m_result;
+ int m_rows_r;
+ int m_cols_r;
+
+ int m_counter;
+
+ /* constructor */
+ public IYLM(int counter,
+ float[] data,
+ int rows,
+ int cols) {
+ this.m_counter = counter;
+ this.m_rows = this.m_rows_r = rows;
+ this.m_cols = this.m_cols_r = cols;
+ this.m_image = data;
+ this.m_result = new float[rows * cols];
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public int getRowsR() {
+ return this.m_rows_r;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public boolean addCalcSobelResult(IYL iyl) {
+ int startRow = iyl.getRowsRS();
+ int endRow = iyl.getRowsRE();
+ int i, j, k, cols;
+ float[] image, r;
+
+ image = this.m_result;
+ this.m_counter--;
+ cols = this.m_cols_r;
+
+ // clone data piece
+ r = iyl.getResult();
+ k = 0;
+ for(i = startRow; i < endRow; i++) {
+ for(j = 0; j < cols; j++) {
+ image[i * cols + j] = r[k * cols + j];
+ }
+ k++;
+ }
+
+ return (0 == this.m_counter);
+ }
+
+ public void calcSobel_dY() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows_r;
+ int cols = this.m_cols_r;
+
+ // level 1 is the base image.
+
+ image = this.m_result;
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 0;
+ kernel_1[2] = -1;
+
+ kernelSize = 3;
+ kernelSum_1 = 2;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 2;
+ kernel_2[2] = 1;
+
+ kernelSum_2 = 4;
+
+ startCol = 1; //(kernelSize/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ startRow = 1; //(kernelSize)/2;
+ endRow = (rows-1); //(rows - (kernelSize)/2);
+
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[(i+k) * cols + j]
+ * (float)(kernel_1[k+halfKernel]));
+ }
+ image[i * cols + j] = (float)(temp/kernelSum_1);
+ image[i * cols + j] = (float)(image[i * cols + j] + 128);
+ }
+ }
+ }
+
+ public void printImage() {
+ // result validation
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI((int)(this.m_image[i * this.m_cols + j]*10));
+ }
+ }
+ }
+
+ public void printResult() {
+ // result validation
+ for(int i=0; i<this.m_rows_r; i++) {
+ for(int j=0; j<this.m_cols_r; j++) {
+ System.printI((int)(this.m_result[i * this.m_cols_r + j]*10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class IYLMR {
+
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* current processing image related */
+ float[] m_result;
+ int m_rows_r;
+ int m_cols_r;
+
+ int m_counter;
+
+ /* constructor */
+ public IYLMR(int counter,
+ float[] data,
+ int rows,
+ int cols) {
+ this.m_counter = counter;
+ this.m_rows = this.m_rows_r = rows;
+ this.m_cols = this.m_cols_r = cols;
+ this.m_image = data;
+ this.m_result = new float[rows * cols];
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public int getRowsR() {
+ return this.m_rows_r;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public boolean addCalcSobelResult(IYLR iyl) {
+ int startRow = iyl.getRowsRS();
+ int endRow = iyl.getRowsRE();
+ int i, j, k, cols;
+ float[] image, r;
+
+ image = this.m_result;
+ this.m_counter--;
+ cols = this.m_cols_r;
+
+ // clone data piece
+ r = iyl.getResult();
+ k = 0;
+ for(i = startRow; i < endRow; i++) {
+ for(j = 0; j < cols; j++) {
+ image[i * cols + j] = r[k * cols + j];
+ }
+ k++;
+ }
+
+ return (0 == this.m_counter);
+ }
+
+ public void calcSobel_dY() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows_r;
+ int cols = this.m_cols_r;
+
+ // level 1 is the base image.
+
+ image = this.m_result;
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 0;
+ kernel_1[2] = -1;
+
+ kernelSize = 3;
+ kernelSum_1 = 2;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 2;
+ kernel_2[2] = 1;
+
+ kernelSum_2 = 4;
+
+ startCol = 1; //(kernelSize/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ startRow = 1; //(kernelSize)/2;
+ endRow = (rows-1); //(rows - (kernelSize)/2);
+
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[(i+k) * cols + j]
+ * (float)(kernel_1[k+halfKernel]));
+ }
+ image[i * cols + j] = (float)(temp/kernelSum_1);
+ image[i * cols + j] = (float)(image[i * cols + j] + 128);
+ }
+ }
+ }
+
+ public void printImage() {
+ // result validation
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI((int)(this.m_image[i * this.m_cols + j]*10));
+ }
+ }
+ }
+
+ public void printResult() {
+ // result validation
+ for(int i=0; i<this.m_rows_r; i++) {
+ for(int j=0; j<this.m_cols_r; j++) {
+ System.printI((int)(this.m_result[i * this.m_cols_r + j]*10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class IYLR {
+
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* results related */
+ float[] m_result;
+ int m_rows_rs;
+ int m_rows_re;
+ int m_cols_r;
+
+ /* id indicating the piece # */
+ int m_id;
+ int m_range;
+
+ /* constructor */
+ public IYLR(int id,
+ int range,
+ float[] image,
+ int rows,
+ int cols) {
+ this.m_id = id;
+ this.m_range = range;
+ this.m_image = image;
+ this.m_rows = rows;
+ this.m_cols = cols;
+ }
+
+ public int getId() {
+ return this.m_id;
+ }
+
+ public int getRowsRS() {
+ return this.m_rows_rs;
+ }
+
+ public int getRowsRE() {
+ return this.m_rows_re;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public void calcSobel_dY() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ // level 1 is the base image.
+
+ image = this.m_image;
+
+ this.m_rows_rs = this.m_id * this.m_range;
+ this.m_rows_re = (this.m_id + 1) * this.m_range;
+ this.m_cols_r = cols;
+ result=this.m_result=new float[(this.m_rows_re-this.m_rows_rs)*this.m_cols_r];
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 0;
+ kernel_1[2] = -1;
+
+ kernelSize = 3;
+ kernelSum_1 = 2;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 2;
+ kernel_2[2] = 1;
+
+ kernelSum_2 = 4;
+
+ startCol = 1; //(kernelSize/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ if((this.m_rows_re < 1) || (this.m_rows_rs > rows - 1)) {
+ return;
+ }
+ startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2;
+ endRow = ((rows-1)<this.m_rows_re)?(rows-1):(this.m_rows_re); //(rows - (kernelSize)/2);
+
+ int ii = startRow - this.m_rows_rs;
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[i * cols + (j+k)]
+ * (float)(kernel_2[k+halfKernel]));
+ }
+ result[ii * cols + j] = (float)(temp/kernelSum_2);
+ }
+ ii++;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class ImageReader {
+
+ int row;
+ int col;
+
+ public ImageReader() {
+
+ }
+
+ public int[] readImage(String file) {
+
+ FileInputStream fs = new FileInputStream(file);
+ int bflen = 14; // 14 byte BITMAPFILEHEADER
+ byte bf[] = new byte[bflen];
+ // fs.read(bf,0,bflen);
+ fs.read(bf);
+ int bilen = 40; // 40-byte BITMAPINFOHEADER
+ byte bi[] = new byte[bilen];
+ // fs.read(bi,0,bilen);
+ fs.read(bi);
+ // Interperet data.
+ int nsize =
+ (((int) bf[5] & 0xff) << 24) | (((int) bf[4] & 0xff) << 16) | (((int) bf[3] & 0xff) << 8)
+ | (int) bf[2] & 0xff;
+// System.out.println("File type is :" + (char) bf[0] + (char) bf[1]);
+// System.out.println("Size of file is :" + nsize);
+ int nbisize =
+ (((int) bi[3] & 0xff) << 24) | (((int) bi[2] & 0xff) << 16) | (((int) bi[1] & 0xff) << 8)
+ | (int) bi[0] & 0xff;
+// System.out.println("Size of bitmapinfoheader is :" + nbisize);
+ int nwidth =
+ (((int) bi[7] & 0xff) << 24) | (((int) bi[6] & 0xff) << 16) | (((int) bi[5] & 0xff) << 8)
+ | (int) bi[4] & 0xff;
+ col=nwidth;
+// System.out.println("Width is :" + nwidth);
+ int nheight =
+ (((int) bi[11] & 0xff) << 24) | (((int) bi[10] & 0xff) << 16) | (((int) bi[9] & 0xff) << 8)
+ | (int) bi[8] & 0xff;
+ row=nheight;
+// System.out.println("Height is :" + nheight);
+ int nplanes = (((int) bi[13] & 0xff) << 8) | (int) bi[12] & 0xff;
+// System.out.println("Planes is :" + nplanes);
+ int nbitcount = (((int) bi[15] & 0xff) << 8) | (int) bi[14] & 0xff;
+// System.out.println("BitCount is :" + nbitcount);
+ // Look for non-zero values to indicate compression
+ int ncompression =
+ (((int) bi[19]) << 24) | (((int) bi[18]) << 16) | (((int) bi[17]) << 8) | (int) bi[16];
+// System.out.println("Compression is :" + ncompression);
+ int nsizeimage =
+ (((int) bi[23] & 0xff) << 24) | (((int) bi[22] & 0xff) << 16)
+ | (((int) bi[21] & 0xff) << 8) | (int) bi[20] & 0xff;
+// System.out.println("SizeImage is :" + nsizeimage);
+ int nxpm =
+ (((int) bi[27] & 0xff) << 24) | (((int) bi[26] & 0xff) << 16)
+ | (((int) bi[25] & 0xff) << 8) | (int) bi[24] & 0xff;
+// System.out.println("X-Pixels per meter is :" + nxpm);
+ int nypm =
+ (((int) bi[31] & 0xff) << 24) | (((int) bi[30] & 0xff) << 16)
+ | (((int) bi[29] & 0xff) << 8) | (int) bi[28] & 0xff;
+// System.out.println("Y-Pixels per meter is :" + nypm);
+ int nclrused =
+ (((int) bi[35] & 0xff) << 24) | (((int) bi[34] & 0xff) << 16)
+ | (((int) bi[33] & 0xff) << 8) | (int) bi[32] & 0xff;
+// System.out.println("Colors used are :" + nclrused);
+ int nclrimp =
+ (((int) bi[39] & 0xff) << 24) | (((int) bi[38] & 0xff) << 16)
+ | (((int) bi[37] & 0xff) << 8) | (int) bi[36] & 0xff;
+// System.out.println("Colors important are :" + nclrimp);
+
+ int ndata[];
+
+ if (nbitcount == 24) {
+ // No Palatte data for 24-bit format but scan lines are
+ // padded out to even 4-byte boundaries.
+ int npad = (nsizeimage / nheight) - nwidth * 3;
+ ndata = new int[(nheight * nwidth) + 4];
+ byte brgb[] = new byte[(nwidth + npad) * 3 * nheight];
+ // fs.read (brgb, 0, (nwidth + npad) * 3 * nheight);
+ fs.read(brgb);
+ int nindex = 0;
+ for (int j = 0; j < nheight; j++) {
+ for (int i = 0; i < nwidth; i++) {
+// ndata[nwidth * (nheight - j - 1) + i] =
+// (255 & 0xff) << 24 | (((int) brgb[nindex + 2] & 0xff) << 16)
+// | (((int) brgb[nindex + 1] & 0xff) << 8) | (int) brgb[nindex] & 0xff;
+// System.out.println("Encoded Color at ("
+// +i+","+j+")is:"+brgb+" (R,G,B)= (" +((int)(brgb[nindex + 2]) & 0xff)+","
+// +((int)brgb[nindex + 1]&0xff)+"," +((int)brgb[nindex]&0xff)+")");
+ int ta=((3*((int)(brgb[nindex + 2]) & 0xff)+6*((int)brgb[nindex + 1]&0xff)+((int)brgb[nindex]&0xff))) /10 ;
+ ndata[nwidth * (nheight - j - 1) + i+4] =ta;
+// System.out.println(ta);
+ nindex += 3;
+ }
+ nindex += npad;
+ }
+ // image = createImage
+ // ( new MemoryImageSource (nwidth, nheight,
+ // ndata, 0, nwidth));
+
+ } else if (nbitcount == 8) {
+ // Have to determine the number of colors, the clrsused
+ // parameter is dominant if it is greater than zero. If
+ // zero, calculate colors based on bitsperpixel.
+ int nNumColors = 0;
+ if (nclrused > 0) {
+ nNumColors = nclrused;
+ } else {
+ nNumColors = (1 & 0xff) << nbitcount;
+ }
+ System.out.println("The number of Colors is" + nNumColors);
+ // Some bitmaps do not have the sizeimage field calculated
+ // Ferret out these cases and fix 'em.
+ if (nsizeimage == 0) {
+ nsizeimage = ((((nwidth * nbitcount) + 31) & 31) >> 3);
+ nsizeimage *= nheight;
+ System.out.println("nsizeimage (backup) is" + nsizeimage);
+ }
+ // Read the palatte colors.
+ int npalette[] = new int[nNumColors];
+ byte bpalette[] = new byte[nNumColors * 4];
+ // fs.read (bpalette, 0, nNumColors*4);
+ fs.read(bpalette);
+ int nindex8 = 0;
+ for (int n = 0; n < nNumColors; n++) {
+ npalette[n] =
+ (255 & 0xff) << 24 | (((int) bpalette[nindex8 + 2] & 0xff) << 16)
+ | (((int) bpalette[nindex8 + 1] & 0xff) << 8) | (int) bpalette[nindex8] & 0xff;
+ // System.out.println ("Palette Color "+n
+ // +" is:"+npalette[n]+" (res,R,G,B)= (" +((int)(bpalette[nindex8+3]) &
+ // 0xff)+"," +((int)(bpalette[nindex8+2]) & 0xff)+","
+ // +((int)bpalette[nindex8+1]&0xff)+","
+ // +((int)bpalette[nindex8]&0xff)+")");
+ nindex8 += 4;
+ }
+ // Read the image data (actually indices into the palette)
+ // Scan lines are still padded out to even 4-byte
+ // boundaries.
+ int npad8 = (nsizeimage / nheight) - nwidth;
+ System.out.println("nPad is:" + npad8);
+// int ndata8[] = new int[nwidth * nheight];
+ ndata = new int[(nwidth * nheight)+4];
+ byte bdata[] = new byte[(nwidth + npad8) * nheight];
+ // fs.read (bdata, 0, (nwidth+npad8)*nheight);
+ fs.read(bdata);
+ nindex8 = 0;
+ for (int j8 = 0; j8 < nheight; j8++) {
+ for (int i8 = 0; i8 < nwidth; i8++) {
+ ndata[nwidth * (nheight - j8 - 1) + i8+4] = npalette[((int) bdata[nindex8] & 0xff)];
+ nindex8++;
+ }
+ nindex8 += npad8;
+ }
+ // image = createImage ( new MemoryImageSource (nwidth, nheight,
+ // ndata8, 0, nwidth));
+ } else {
+ System.out.println("Not a 24-bit or 8-bit Windows Bitmap, aborting...");
+ // image = (Image)null;
+ }
+ fs.close();
+
+ ndata[0] = nheight;
+ ndata[1] = nwidth;
+ ndata[2] = nheight * nwidth;
+ ndata[3] = 2;
+
+ return ndata;
+
+ }
+
+}
\ No newline at end of file
--- /dev/null
+public class ImageX {
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* results related */
+ float[] m_result;
+ int m_rows_rs;
+ int m_rows_re;
+ int m_cols_r;
+
+ /* id indicating the piece # */
+ int m_id;
+ int m_range;
+
+ /* constructor */
+ public ImageX(int id,
+ int range,
+ float[] data,
+ int rows,
+ int cols) {
+ this.m_id = id;
+ this.m_range = range;
+ this.m_image = data;
+ this.m_rows = rows;
+ this.m_cols = cols;
+ }
+
+ public int getId() {
+ return this.m_id;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public int getRowsRS() {
+ return this.m_rows_rs;
+ }
+
+ public int getRowsRE() {
+ return this.m_rows_re;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public void calcSobel_dX() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ image = this.m_image;
+
+ this.m_rows_rs = this.m_id * this.m_range;
+ this.m_rows_re = (this.m_id + 1) * this.m_range;
+ this.m_cols_r = cols;
+ result=this.m_result=new float[(this.m_rows_re-this.m_rows_rs)*this.m_cols_r];
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 2;
+ kernel_1[2] = 1;
+
+ kernelSize = 3;
+ kernelSum_1 = 4;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 0;
+ kernel_2[2] = -1;
+
+ kernelSum_2 = 2;
+
+ startCol = 1; //((kernelSize)/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ if((this.m_rows_re < 1) || (this.m_rows_rs > rows - 1)) {
+ return;
+ }
+ startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2;
+ endRow = ((rows-1)<this.m_rows_re)?(rows-1):(this.m_rows_re); //(rows - (kernelSize)/2);
+
+ int ii = startRow - this.m_rows_rs;
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[i * cols + (j+k)]
+ * (float)(kernel_2[k+halfKernel]));
+ }
+ result[ii * cols + j] = (float)(temp/kernelSum_2);
+ }
+ ii++;
+ }
+ }
+
+ public void printResult() {
+ // result validation
+ System.printI(11111111);
+ for(int i=0; i<this.m_rows_re-this.m_rows_rs; i++) {
+ for(int j=0; j<this.m_cols_r; j++) {
+ System.printI((int)(this.m_result[i * this.m_cols_r + j]*10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class ImageXM {
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ int m_counter;
+
+ /* constructor */
+ public ImageXM(int counter,
+ int rows,
+ int cols) {
+ this.m_counter = counter;
+ this.m_rows = rows;
+ this.m_cols = cols;
+ this.m_image = new float[rows * cols];
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public boolean addCalcSobelResult(ImageX imx) {
+ int startRow = imx.getRowsRS();
+ int endRow = imx.getRowsRE();
+ int i, j, k, cols;
+ float[] image, r;
+
+ image = this.m_image;
+ this.m_counter--;
+ cols = this.m_cols;
+
+ // clone data piece
+ r = imx.getResult();
+ k = 0;
+ for(i = startRow; i < endRow; i++) {
+ for(j = 0; j < cols; j++) {
+ image[i * cols + j] = r[k * cols + j];
+ }
+ k++;
+ }
+
+ return (0 == this.m_counter);
+ }
+
+ public void calcSobel_dX() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ image = this.m_image;
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 2;
+ kernel_1[2] = 1;
+
+ kernelSize = 3;
+ kernelSum_1 = 4;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 0;
+ kernel_2[2] = -1;
+
+ kernelSum_2 = 2;
+
+ startCol = 1; //((kernelSize)/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ startRow = 1; //(kernelSize)/2;
+ endRow = (rows-1); //(rows - (kernelSize)/2);
+
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[(i+k) * cols + j]
+ * (float)(kernel_1[k+halfKernel]));
+ }
+ image[i * cols + j] = (float)(temp/kernelSum_1);
+ image[i * cols + j] = (float)(image[i * cols + j] + 128);
+ }
+ }
+ }
+
+ public void printImage() {
+ // result validation
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI((int)(this.m_image[i * this.m_cols + j]*10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class ImageY {
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ /* results related */
+ float[] m_result;
+ int m_rows_rs;
+ int m_rows_re;
+ int m_cols_r;
+
+ /* id indicating the piece # */
+ int m_id;
+ int m_range;
+
+ /* constructor */
+ public ImageY(int id,
+ int range,
+ float[] image,
+ int rows,
+ int cols) {
+ this.m_id = id;
+ this.m_range = range;
+ this.m_image = image;
+ this.m_rows = rows;
+ this.m_cols = cols;
+ }
+
+ public int getId() {
+ return this.m_id;
+ }
+
+ public int getRowsRS() {
+ return this.m_rows_rs;
+ }
+
+ public int getRowsRE() {
+ return this.m_rows_re;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public float[] getResult() {
+ return this.m_result;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public void calcSobel_dY() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ // level 1 is the base image.
+
+ image = this.m_image;
+
+ this.m_rows_rs = this.m_id * this.m_range;
+ this.m_rows_re = (this.m_id + 1) * this.m_range;
+ this.m_cols_r = cols;
+ result=this.m_result=new float[(this.m_rows_re-this.m_rows_rs)*this.m_cols_r];
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 0;
+ kernel_1[2] = -1;
+
+ kernelSize = 3;
+ kernelSum_1 = 2;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 2;
+ kernel_2[2] = 1;
+
+ kernelSum_2 = 4;
+
+ startCol = 1; //(kernelSize/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ if((this.m_rows_re < 1) || (this.m_rows_rs > rows - 1)) {
+ return;
+ }
+ startRow = (1>this.m_rows_rs)?1:(this.m_rows_rs); //(kernelSize)/2;
+ endRow = ((rows-1)<this.m_rows_re)?(rows-1):(this.m_rows_re); //(rows - (kernelSize)/2);
+
+ int ii = startRow - this.m_rows_rs;
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[i * cols + (j+k)]
+ * (float)(kernel_2[k+halfKernel]));
+ }
+ result[ii * cols + j] = (float)(temp/kernelSum_2);
+ }
+ ii++;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class ImageYM {
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+
+ int m_counter;
+
+ /* constructor */
+ public ImageYM(int counter,
+ int rows,
+ int cols) {
+ this.m_counter = counter;
+ this.m_rows = rows;
+ this.m_cols = cols;
+ this.m_image = new float[rows * cols];
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public boolean addCalcSobelResult(ImageY imy) {
+ int startRow = imy.getRowsRS();
+ int endRow = imy.getRowsRE();
+ int i, j, k, cols;
+ float[] image, r;
+
+ image = this.m_image;
+ this.m_counter--;
+ cols = this.m_cols;
+
+ // clone data piece
+ r = imy.getResult();
+ k = 0;
+ for(i = startRow; i < endRow; i++) {
+ for(j = 0; j < cols; j++) {
+ image[i * cols + j] = r[k * cols + j];
+ }
+ k++;
+ }
+
+ return (0 == this.m_counter);
+ }
+
+ public void calcSobel_dY() {
+ int rows_k1, cols_k1, rows_k2, cols_k2;
+ int[] kernel_1, kernel_2;
+ float temp;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow;
+ int k, i, j, kernelSum_1, kernelSum_2;
+ float[] result, image;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ // level 1 is the base image.
+
+ image = this.m_image;
+
+ rows_k1 = 1;
+ cols_k1 = 3;
+ kernel_1 = new int[rows_k1 * cols_k1];
+ rows_k2 = 1;
+ cols_k2 = 3;
+ kernel_2 = new int[rows_k2 * cols_k2];
+
+ kernel_1[0] = 1;
+ kernel_1[1] = 0;
+ kernel_1[2] = -1;
+
+ kernelSize = 3;
+ kernelSum_1 = 2;
+
+ kernel_2[0] = 1;
+ kernel_2[1] = 2;
+ kernel_2[2] = 1;
+
+ kernelSum_2 = 4;
+
+ startCol = 1; //(kernelSize/2);
+ endCol = cols - 1; //(int)(cols - (kernelSize/2));
+ halfKernel = 1; //(kernelSize-1)/2;
+
+ startRow = 1; //(kernelSize)/2;
+ endRow = (rows-1); //(rows - (kernelSize)/2);
+
+ for(i=startRow; i<endRow; i++) {
+ for(j=startCol; j<endCol; j++) {
+ temp = 0;
+ for(k=-halfKernel; k<=halfKernel; k++) {
+ temp += (float)(image[(i+k) * cols + j]
+ * (float)(kernel_1[k+halfKernel]));
+ }
+ image[i * cols + j] = (float)(temp/kernelSum_1);
+ image[i * cols + j] = (float)(image[i * cols + j] + 128);
+ }
+ }
+ }
+
+ public void printImage() {
+ // result validation
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI((int)(this.m_image[i * this.m_cols + j]*10));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+public class Lambda {
+
+ /* current processing image related */
+ float[] m_image;
+ int m_rows;
+ int m_cols;
+ int m_r;
+
+ int m_num_p;
+
+ /* benchmark constants */
+ int WINSZ;
+ public int N_FEA;
+
+ /* constructor */
+ public Lambda(int winsz,
+ int nfea,
+ int pnum,
+ int nump) {
+ this.WINSZ = winsz;
+ this.N_FEA = nfea;
+ this.m_num_p = nump;
+ }
+
+ public int getNumP() {
+ return this.m_num_p;
+ }
+
+ public int getR() {
+ return this.m_r;
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public void calcGoodFeature(ImageXM imxm,
+ ImageYM imym) {
+ float[] dX, dY;
+ int sizeX, sizeY, rowY, colY;
+ int i, j;
+ float[] xx, yy, xy, image;
+ int rows_xx, cols_xx, rows_yy, cols_yy, rows_xy, cols_xy;
+ float[] tr, det, c_xx, c_xy, c_yy;
+ int rows_tr, cols_tr, rows_det, cols_det, rows_cxx, cols_cxx;
+ int rows_cxy, cols_cxyrows_cyy, cols_cyy;
+
+ dX = imxm.getImage();
+ dY = imym.getImage();
+ sizeX = imxm.getRows();
+ sizeY = imxm.getCols();
+ rowY = imym.getRows();
+ colY = imym.getCols();
+
+ rows_xx = sizeX;
+ cols_xx = sizeY;
+ xx = new float[rows_xx * cols_xx];
+ rows_xy = sizeX;
+ cols_xy = sizeY;
+ xy = new float[rows_xy * cols_xy];
+ rows_yy = sizeX;
+ cols_yy = sizeY;
+ yy = new float[rows_yy * cols_yy];
+
+ for( i=0; i<sizeX; i++) {
+ for( j=0; j<sizeY; j++) {
+ xx[i * sizeY + j] = (float)(dX[i * sizeY + j] * dX[i * sizeY + j]);
+ xy[i * sizeY + j] = (float)(dX[i * sizeY + j] * dY[i * sizeY + j]);
+ yy[i * sizeY + j] = (float)(dY[i * sizeY + j] * dY[i * sizeY + j]);
+ }
+ }
+
+ c_xx = calcAreaSum(xx, sizeY, sizeX);
+ c_xy = calcAreaSum(xy, sizeY, sizeX);
+ c_yy = calcAreaSum(yy, sizeY, sizeX);
+
+ rows_tr = sizeX;
+ cols_tr = sizeY;
+ tr = new float[rows_tr * cols_tr];
+ rows_det = sizeX;
+ cols_det = sizeY;
+ det = new float[rows_det * cols_det];
+ this.m_rows = sizeX;
+ this.m_cols = sizeY;
+ image = this.m_image = new float[this.m_rows * this.m_cols];
+
+ for( i=0; i<sizeX; i++) {
+ for( j=0; j<sizeY; j++) {
+ tr[i * sizeY + j] = c_xx[i * sizeY + j] + c_yy[i * sizeY + j];
+ det[i * sizeY + j] = c_xx[i * sizeY + j] * c_yy[i * sizeY + j]
+ - c_xy[i * sizeY + j] * c_xy[i * sizeY + j];
+// lambda[i * sizeY + j] = (float)(det[i * sizeY + j]/(tr[i * sizeY + j]) + 0.00001);
+ image[i * sizeY + j] = (float)((det[i * sizeY + j]*100000)
+ /((tr[i * sizeY + j]*100000) + 0.1));
+ }
+ }
+ }
+
+ public float[] calcAreaSum(float[] src,
+ int sizeY,
+ int sizeX) {
+ int nave, nave_half, i, j, k;
+ float[] ret, a1;
+ int rows_ret, cols_ret, rows_a1, cols_a1;
+ float a1sum;
+
+ nave = this.WINSZ;
+ nave_half = (int)(Math.floor((nave+1)/2))-1;
+
+ rows_ret = sizeX;
+ cols_ret = sizeY;
+ ret = new float[rows_ret * cols_ret];
+
+ for(i=0; i<sizeX; i++) {
+ rows_a1 = 1;
+ cols_a1 = sizeY+nave;
+ a1 = new float[rows_a1 * cols_a1];
+
+ for(j=0; j<sizeY; j++) {
+ a1[j+nave_half] = src[i*sizeY+j];
+ }
+
+ a1sum = 0;
+ for(k=0; k<nave; k++) {
+ a1sum += a1[k];
+ }
+
+ for(j=0; j<sizeY; j++) {
+ ret[i*sizeY+j] = a1sum;
+ a1sum += a1[j+nave] - a1[j];
+ }
+ }
+ a1 = null;
+
+ for(i=0; i<sizeY; i++) {
+ rows_a1 = 1;
+ cols_a1 = sizeX+nave;
+ a1 = new float[rows_a1 * cols_a1];
+
+ for(j=0; j<sizeX; j++) {
+ a1[j+nave_half] = ret[j*sizeY+i];
+ }
+
+ a1sum = 0;
+ for(k=0; k<nave; k++) {
+ a1sum += a1[k];
+ }
+
+ for(j=0; j<sizeX; j++) {
+ ret[j*sizeY+i] = a1sum;
+ a1sum += a1[j+nave] - a1[j];
+ }
+ }
+ a1 = null;
+
+ return ret;
+ }
+
+ public void reshape() {
+ float[] out, image;
+ int i, j, k;
+ int r, c;
+
+ image = this.m_image;
+ r = this.m_rows;
+ c = this.m_cols;
+
+ out = new float[r * c];
+
+ k = 0;
+ for(i=0; i<c; i++) {
+ for(j=0; j<r; j++) {
+ out[k++] = image[j * c + i];
+ }
+ }
+ this.m_image = out;
+ this.m_rows = r * c;
+ this.m_cols = 1;
+ this.m_r= r;
+ }
+
+
+ public void printImage() {
+ // result validation
+ for(int i=0; i<this.m_rows; i++) {
+ for(int j=0; j<this.m_cols; j++) {
+ System.printI((int)(this.m_image[i * this.m_cols + j]*10));
+ }
+ }
+ }
+
+
+}
\ No newline at end of file
--- /dev/null
+public class TrackDemo {
+ /* input data and the counter to record the input to be processed next */
+ int[][] m_inputs;
+ int m_count;
+
+ /* current processing image related */
+ float[] m_image; // Icur/Jpyr1
+ int m_rows;
+ int m_cols;
+ float[] m_image_resized; // Jpyr2
+ int m_rows_r;
+ int m_cols_r;
+
+ /* BP related */
+ int m_num_bp;
+ /* BPL related */
+ int m_num_bpl;
+
+ /* feature related */
+ float[] m_features;
+ int m_rows_f;
+ int m_cols_f;
+
+ /* */
+ float[][] m_3f;
+ int m_rows_3f;
+ int m_cols_3f;
+ int m_counter_3f;
+ int m_num_p;
+
+ /* benchmark constants */
+ public int WINSZ;
+ public int N_FEA;
+ int SUPPRESION_RADIUS;
+ int LK_ITER;
+ int m_counter;
+ float accuracy;
+
+ /* constructor */
+ public TrackDemo(int nump) {
+ this.m_inputs = new int[2][];
+
+ int rows = 10 * 60; // * 2;
+ int cols = 12 * 5;
+ int offset = 0;
+ this.m_inputs[0] = this.makeImage(rows, cols, offset);
+ offset = 100;
+ this.m_inputs[1] = this.makeImage(rows, cols, offset);
+ this.m_count = 0;
+
+ this.m_num_bp = 0;
+ this.m_num_bpl = 0;
+
+ this.WINSZ = 8;
+ this.N_FEA = 16; // 00;
+ this.SUPPRESION_RADIUS = 10;
+ this.LK_ITER = 20;
+ this.accuracy = (float) 0.03;
+ this.m_counter = 2;
+ // #ifdef test
+ /*
+ * this.WINSZ = 2; this.N_FEA = 10; this.LK_ITER = 1; this.m_counter = 2;
+ * this.accuracy = (float)0.1; /* //#ifdef sim_fast this.WINSZ = 4;
+ * this.N_FEA = 10; this.LK_ITER = 2; this.counter = 2;
+ *
+ * //#ifdef sim this.WINSZ = 4; this.N_FEA = 20; this.LK_ITER = 4;
+ * this.counter = 2;
+ */
+ this.m_3f = new float[3][this.N_FEA];
+ this.m_rows_3f = this.N_FEA;
+ this.m_cols_3f = this.N_FEA;
+ this.m_cols_3f = 1;
+// this.m_counter_3f = 3;
+ this.m_num_p = nump;
+
+ this.m_rows = 0;
+ this.m_cols = 0;
+ this.m_image = null;
+ this.m_image_resized = null;
+ this.m_rows_r = 0;
+ this.m_cols_r = 0;
+
+ this.m_features = null;
+ this.m_rows_f = 0;
+ this.m_cols_f = 0;
+ }
+
+ public int getNumP() {
+ return this.m_num_p;
+ }
+
+ public boolean isFinish() {
+ return (this.m_count == this.m_counter);
+ }
+
+ public int getRows() {
+ return this.m_rows;
+ }
+
+ public int getCols() {
+ return this.m_cols;
+ }
+
+ public float[] getImage() {
+ return this.m_image;
+ }
+
+ public int getRowsR() {
+ return this.m_rows_r;
+ }
+
+ public int getColsR() {
+ return this.m_cols_r;
+ }
+
+ public float[] getImageR() {
+ return this.m_image_resized;
+ }
+
+ public int[] getInput(boolean isadvance) {
+ int[] input = this.m_inputs[this.m_count];
+ if (isadvance) {
+ this.m_count++;
+ }
+
+ return input;
+ }
+
+ public void setBPNum(int num) {
+ this.m_num_bp = num;
+ }
+
+ public void setBPLNum(int num) {
+ this.m_num_bpl = num;
+ }
+
+ public int[] makeImage(int rows, int cols, int offset) {
+ int k, i, j;
+ int[] out;
+
+ out = new int[rows * cols + 4];
+ out[0] = rows;
+ out[1] = cols;
+ out[2] = rows * cols;
+ out[3] = 2;
+
+ k = offset;
+ for (i = 0; i < rows; i++) {
+ for (j = 0; j < cols; j++) {
+ out[i * cols + j + 4] = ((k++) * rows) % 255;
+ }
+ }
+
+ return out;
+ }
+
+ public boolean addBP(BlurPiece bp) {
+ int startRow = bp.getRowsRS();
+ int endRow = bp.getRowsRE();
+ int i, j, k, cols;
+ float[] image, input;
+
+ if (this.m_image == null) {
+ this.m_rows = bp.getRows();
+ this.m_cols = bp.getCols();
+ this.m_image = new float[this.m_rows * this.m_cols];
+ }
+ image = this.m_image;
+ cols = this.m_cols;
+
+ input = bp.getResult();
+ k = 0;
+ for (i = startRow; i < endRow; i++) {
+ for (j = 0; j < cols; j++) {
+ image[i * cols + j] = input[k * cols + j];
+ }
+ k++;
+ }
+
+ this.m_num_bp--;
+ return (0 == this.m_num_bp);
+ }
+
+ public boolean addBPL(BlurPieceL bpl) {
+ int startRow = bpl.getRowsRS();
+ int endRow = bpl.getRowsRE();
+ int i, j, k, cols;
+ float[] image, input;
+
+ if (this.m_image == null) {
+ this.m_rows = bpl.getRows();
+ this.m_cols = bpl.getCols();
+ this.m_image = new float[this.m_rows * this.m_cols];
+ }
+ image = this.m_image;
+ cols = this.m_cols;
+
+ input = bpl.getResult();
+ k = 0;
+ for (i = startRow; i < endRow; i++) {
+ for (j = 0; j < cols; j++) {
+ image[i * cols + j] = input[k * cols + j];
+ }
+ k++;
+ }
+
+ this.m_num_bpl--;
+ return (0 == this.m_num_bpl);
+ }
+
+ public void postBlur() {
+ int rows, cols;
+ float temp;
+ int[] kernel;
+ int rows_k, cols_k;
+ int k, i, j;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow, kernelSum;
+ float[] image;
+
+ rows = this.m_rows;
+ cols = this.m_cols;
+ image = this.m_image;
+
+ kernel = new int[5];
+ rows_k = 1;
+ cols_k = 5;
+
+ kernel[0] = 1;
+ kernel[1] = 4;
+ kernel[2] = 6;
+ kernel[3] = 4;
+ kernel[4] = 1;
+
+ kernelSize = 5;
+ kernelSum = 16;
+
+ startCol = 2; // ((kernelSize)/2);
+ endCol = cols - 2; // round(cols - (kernelSize/2));
+ halfKernel = 2; // (kernelSize-1)/2;
+
+ startRow = 2; // (kernelSize)/2;
+ endRow = rows - 2; // (rows - (kernelSize)/2);
+
+ for (i = startRow; i < endRow; i++) {
+ for (j = startCol; j < endCol; j++) {
+ temp = 0;
+ for (k = -halfKernel; k <= halfKernel; k++) {
+ temp += (float) ((image[(i + k) * cols + j] * (float) (kernel[k + halfKernel])));
+ }
+ image[i * cols + j] = (float) (temp / kernelSum);
+ }
+ }
+ }
+
+ public float[] resize(float image[]){
+ int m, k, i, j;
+ int kernel[];
+ int rows_k, cols_k;
+ float tempVal;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow, kernelSum;
+ int outputRows, outputCols;
+ float temp[];
+ int rows_t;
+ int cols_t;
+ float[] resized;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ // level 1 is the base image.
+
+ outputRows = (int) (Math.floor((rows + 1) / 2));
+ outputCols = (int) (Math.floor((cols + 1) / 2));
+
+ rows_t = rows;
+ cols_t = outputCols;
+ temp = new float[rows_t * cols_t];
+
+ this.m_rows_r = outputRows;
+ this.m_cols_r = outputCols;
+ resized =new float[this.m_rows_r * this.m_cols_r];
+
+ rows_k = 1;
+ cols_k = 5;
+ kernel = new int[rows_k * cols_k];
+
+ kernel[0] = 1;
+ kernel[1] = 4;
+ kernel[2] = 6;
+ kernel[3] = 4;
+ kernel[4] = 1;
+
+ kernelSize = 5;
+ kernelSum = 16;
+
+ startCol = 2; // (kernelSize/2);
+ endCol = cols - 2; // (int)(cols - (kernelSize/2));
+ halfKernel = 2; // (kernelSize-1)/2;
+
+ startRow = 2; // kernelSize/2;
+ endRow = rows - 2; // (rows - (kernelSize)/2);
+
+ for (i = startRow; i < endRow; i++) {
+ m = 0;
+ for (j = startCol; j < endCol; j += 2) {
+ tempVal = 0;
+ for (k = -halfKernel; k <= halfKernel; k++) {
+ tempVal += (float) (image[i * cols + (j + k)] * (float) (kernel[k + halfKernel]));
+ }
+ temp[i * outputCols + m] = (float) (tempVal / kernelSum);
+ m = m + 1;
+ }
+ }
+
+ m = 0;
+ for (i = startRow; i < endRow; i += 2) {
+ for (j = 0; j < outputCols; j++) {
+ tempVal = 0;
+ for (k = -halfKernel; k <= halfKernel; k++) {
+ tempVal += (float) (temp[(i + k) * outputCols + j] * (float) (kernel[k + halfKernel]));
+ }
+ resized[m * outputCols + j] = (float) (tempVal / kernelSum);
+ }
+ m = m + 1;
+ }
+ return resized;
+ }
+
+ public void resize() {
+ int m, k, i, j;
+ int kernel[];
+ int rows_k, cols_k;
+ float tempVal;
+ int kernelSize, startCol, endCol, halfKernel, startRow, endRow, kernelSum;
+ int outputRows, outputCols;
+ float temp[];
+ int rows_t;
+ int cols_t;
+ float[] image, resized;
+ int rows = this.m_rows;
+ int cols = this.m_cols;
+
+ // level 1 is the base image.
+
+ outputRows = (int) (Math.floor((rows + 1) / 2));
+ outputCols = (int) (Math.floor((cols + 1) / 2));
+
+ rows_t = rows;
+ cols_t = outputCols;
+ temp = new float[rows_t * cols_t];
+
+ this.m_rows_r = outputRows;
+ this.m_cols_r = outputCols;
+ resized = this.m_image_resized = new float[this.m_rows_r * this.m_cols_r];
+ image = this.m_image;
+
+ rows_k = 1;
+ cols_k = 5;
+ kernel = new int[rows_k * cols_k];
+
+ kernel[0] = 1;
+ kernel[1] = 4;
+ kernel[2] = 6;
+ kernel[3] = 4;
+ kernel[4] = 1;
+
+ kernelSize = 5;
+ kernelSum = 16;
+
+ startCol = 2; // (kernelSize/2);
+ endCol = cols - 2; // (int)(cols - (kernelSize/2));
+ halfKernel = 2; // (kernelSize-1)/2;
+
+ startRow = 2; // kernelSize/2;
+ endRow = rows - 2; // (rows - (kernelSize)/2);
+
+ for (i = startRow; i < endRow; i++) {
+ m = 0;
+ for (j = startCol; j < endCol; j += 2) {
+ tempVal = 0;
+ for (k = -halfKernel; k <= halfKernel; k++) {
+ tempVal += (float) (image[i * cols + (j + k)] * (float) (kernel[k + halfKernel]));
+ }
+ temp[i * outputCols + m] = (float) (tempVal / kernelSum);
+ m = m + 1;
+ }
+ }
+
+ m = 0;
+ for (i = startRow; i < endRow; i += 2) {
+ for (j = 0; j < outputCols; j++) {
+ tempVal = 0;
+ for (k = -halfKernel; k <= halfKernel; k++) {
+ tempVal += (float) (temp[(i + k) * outputCols + j] * (float) (kernel[k + halfKernel]));
+ }
+ resized[m * outputCols + j] = (float) (tempVal / kernelSum);
+ }
+ m = m + 1;
+ }
+ }
+
+ public boolean addIDX(IDX idx) {
+ float[][] m3f = this.m_3f;
+ int rows = idx.getRowsRS();
+ int rowe = idx.getRowsRE();
+ int threshold = this.N_FEA;
+ int[] ind = idx.getInd();
+ float[] image = idx.getImage();
+ int r = idx.getR();
+ int nfea = this.N_FEA;
+ int length = this.m_rows * this.m_cols;
+ int[] h_ind = new int[this.N_FEA];
+ boolean[] f_ind = new boolean[this.N_FEA];
+ for (int i = 0; i < this.N_FEA; i++) {
+ f_ind[i] = false;
+ }
+
+ int j = 0;
+ int localindex = 0;
+ int rindex = 0;
+ for (int i = rows; i < rowe; i++) {
+ rindex = length - ind[j];
+ if (rindex < nfea) {
+ localindex = j + rows;
+ if (!f_ind[rindex]) {
+ // empty
+ m3f[2][rindex] = image[localindex];
+ h_ind[rindex] = localindex;
+ localindex++;
+ m3f[0][rindex] = Math.ceilf((float) (localindex / (float) r));
+ m3f[1][rindex] = (float) localindex - (m3f[0][rindex] - 1) * (float) r * (float) 1.0;
+ f_ind[rindex] = true;
+ } else {
+ // previously held by some others with the same value
+ int k = rindex; // the place to insert
+ int k1 = rindex; // the first one which is not set
+ for (; k1 < nfea; k1++) {
+ if (h_ind[k1] > localindex) {
+ k = k1;
+ }
+ if (!f_ind[k1]) {
+ break;
+ }
+ }
+ if (k == nfea) {
+ // System.printI(77777777);
+ return false;
+ } else if (k == rindex) {
+ k = k1;
+ }
+ if (f_ind[k] && (m3f[2][k] != image[localindex])) {
+ // System.printI(88888888);
+ return false;
+ }
+ // move all things after k behind
+ int p = k1;
+ for (; p > k; p--) {
+ m3f[2][p] = m3f[2][p - 1];
+ h_ind[p] = h_ind[p - 1];
+ m3f[0][p] = m3f[0][p - 1];
+ m3f[1][p] = m3f[1][p - 1];
+ f_ind[p] = true;
+ }
+ // insert
+ m3f[2][p] = image[localindex];
+ h_ind[p] = localindex;
+ localindex++;
+ m3f[0][p] = Math.ceilf((float) (localindex / (float) r));
+ m3f[1][p] = (float) localindex - (m3f[0][p] - 1) * (float) r * (float) 1.0;
+ f_ind[p] = true;
+ }
+ }
+ j++;
+ }
+
+ this.m_num_p--;
+
+ return (0 == this.m_num_p);
+ }
+
+ public void calcFeatures() {
+ float[] f1, f2, f3;
+ int rows_f1, cols_f1, rows_f2, cols_f2, rows_f3, cols_f3;
+ float[] interestPnts;
+ int[] rows_ip, cols_ip;
+ int rows_ipt, cols_ipt;
+ rows_ip = new int[1];
+ cols_ip = new int[1];
+
+ f1 = this.m_3f[0];
+ f2 = this.m_3f[1];
+ f3 = this.m_3f[2];
+ rows_f1 = this.m_rows_3f;
+ rows_f2 = this.m_rows_3f;
+ rows_f3 = this.m_rows_3f;
+ cols_f1 = this.m_cols_3f;
+ cols_f2 = this.m_cols_3f;
+ cols_f3 = this.m_cols_3f;
+
+ interestPnts =
+ this.getANMs(f1, rows_f1, cols_f1, f2, rows_f2, cols_f2, f3, rows_f3, cols_f3, rows_ip,
+ cols_ip);
+ rows_ipt = rows_ip[0];
+ cols_ipt = cols_ip[0];
+ rows_ip = cols_ip = null;
+
+ // fTranspose(interestPnts)
+ float[] trans;
+ int i, j, k, rows_trans, cols_trans;
+
+ rows_trans = cols_ipt;
+ cols_trans = rows_ipt;
+ trans = new float[rows_trans * cols_trans];
+
+ k = 0;
+ for (i = 0; i < cols_ipt; i++) {
+ for (j = 0; j < rows_ipt; j++) {
+ trans[k++] = interestPnts[j * cols_ipt + i];
+ }
+ }
+
+ // fDeepCopyRange(interestPnt, 0, 2, 0, cols_ip[0])
+ int rows, cols;
+ int numberRows = 2;
+ int startRow = 0;
+ int numberCols = cols_trans;
+ int startCol = 0;
+
+ rows = numberRows + startRow;
+ cols = numberCols + startCol;
+
+ rows_ipt = numberRows;
+ cols_ipt = numberCols;
+ interestPnts = new float[rows_ipt * cols_ipt];
+
+ k = 0;
+ for (i = startRow; i < rows; i++) {
+ for (j = startCol; j < cols; j++) {
+ interestPnts[k++] = trans[i * cols_trans + j];
+ }
+ }
+
+ float[] features;
+ this.m_rows_f = 2;
+ this.m_cols_f = cols_ipt;
+
+ features = this.m_features = new float[this.m_rows_f * this.m_cols_f];
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < cols_ipt; j++) {
+ features[i * cols_ipt + j] = interestPnts[i * cols_ipt + j];
+ }
+ }
+ }
+
+ public float[] horzcat(float[] f1, int rows_f1, int cols_f1, float[] f2, int rows_f2,
+ int cols_f2, float[] f3, int rows_f3, int cols_f3) {
+ float[] out;
+ int rows = 0, cols = 0, i, j, k, c_1, c_2, r_3, c_3;
+
+ c_1 = cols_f1;
+ cols += c_1;
+
+ c_2 = cols_f2;
+ cols += c_2;
+
+ r_3 = rows_f3;
+ c_3 = cols_f3;
+ cols += c_3;
+
+ rows = r_3;
+
+ out = new float[rows * cols];
+
+ for (i = 0; i < rows; i++) {
+ k = 0;
+ for (j = 0; j < c_1; j++) {
+ out[i * cols + k] = f1[i * c_1 + j];
+ k++;
+ }
+ for (j = 0; j < c_2; j++) {
+ out[i * cols + k] = f2[i * c_2 + j];
+ k++;
+ }
+ for (j = 0; j < c_3; j++) {
+ out[i * cols + k] = f3[i * c_3 + j];
+ k++;
+ }
+ }
+
+ return out;
+ }
+
+ public int[] fSortIndices(float[] input, int rows, int cols) {
+ float[] in;
+ int i, j, k;
+ int[] ind;
+
+ // fDeepCopy
+ in = new float[input.length];
+ for (i = 0; i < input.length; i++) {
+ in[i] = input[i];
+ }
+
+ ind = new int[rows * cols];
+
+ for (k = 0; k < cols; k++) {
+ for (i = 0; i < rows; i++) {
+ float localMax = in[i * cols + k];
+ int localIndex = i;
+ ind[i * cols + k] = i;
+ for (j = 0; j < rows; j++) {
+ if (localMax < in[j * cols + k]) {
+ ind[i * cols + k] = j;
+ localMax = in[j * cols + k];
+ localIndex = j;
+ }
+ }
+ in[localIndex * cols + k] = 0;
+ }
+ }
+
+ return ind;
+ }
+
+ public float[] ffVertcat(float[] matrix1, int rows_m1, int cols_m1, float[] matrix2, int rows_m2,
+ int cols_m2) {
+ float[] outMatrix;
+ int rows_o, cols_o, i, j, k;
+
+ rows_o = rows_m1 + rows_m2;
+ cols_o = cols_m1;
+ outMatrix = new float[rows_o * cols_o];
+
+ for (i = 0; i < cols_m1; i++) {
+ for (j = 0; j < rows_m1; j++) {
+ outMatrix[j * cols_m1 + i] = matrix1[j * cols_m1 + i];
+ }
+ for (k = 0; k < rows_m2; k++) {
+ outMatrix[(k + rows_m1) * cols_m1 + i] = matrix2[k * cols_m2 + i];
+ }
+ }
+
+ return outMatrix;
+
+ }
+
+ public float[] getANMs(float[] f1, int rows_f1, int cols_f1, float[] f2, int rows_f2,
+ int cols_f2, float[] f3, int rows_f3, int cols_f3, int[] rows_ip, int[] cols_ip) {
+ float MAX_LIMIT = (float) 100000000;
+ float C_ROBUST = (float) 1.0;
+ float[] suppressR, points, srtdPnts, tempF, srtdV, interestPnts, temp;
+ int rows_sr, cols_sr, rows_p, cols_p, rows_sp, cols_sp, rows_tf, cols_tf;
+ int rows_sv, cols_sv, rows_tmp, cols_tmp;
+ int[] srtdVIdx, supId;
+ int rows_svi, cols_svi, rows_si, cols_si;
+ float t, t1, r_sq;
+ int n, i, j, k, validCount, cnt, end, iter, rows, cols;
+ int supIdPtr = 0;
+
+ r_sq = (float) (this.SUPPRESION_RADIUS ^ 2);
+ points = this.horzcat(f1, rows_f1, cols_f1, f2, rows_f2, cols_f2, f3, rows_f3, cols_f3);
+ rows_p = rows_f3;
+ cols_p = cols_f1 + cols_f2 + cols_f3;
+ n = rows_f3;
+
+ /** sort() arg 2 is for descend = 1, arg3 = indices. Returns sorted values **/
+
+ srtdVIdx = this.fSortIndices(f3, rows_f3, cols_f3);
+ rows_svi = rows_f3;
+ cols_svi = cols_f3;
+
+ rows_sp = rows_svi;
+ cols_sp = cols_p;
+ srtdPnts = new float[rows_sp * cols_sp];
+
+ for (i = 0; i < rows_sp; i++) {
+ for (j = 0; j < cols_sp; j++) {
+ srtdPnts[i * cols_sp + j] = points[srtdVIdx[i] * cols_sp + j];
+ }
+ }
+
+ rows_tmp = 1;
+ cols_tmp = 3;
+ temp = new float[rows_tmp * cols_tmp];
+ rows_sr = n;
+ cols_sr = 1;
+ suppressR = new float[rows_sr * cols_sr];
+ for (i = 0; i < rows_sr; i++) {
+ for (j = 0; j < cols_sr; j++) {
+ suppressR[i * cols_sr + j] = MAX_LIMIT;
+ }
+ }
+
+ validCount = 0;
+ iter = 0;
+ for (i = 0; i < rows_sr; i++) {
+ if (suppressR[i] > r_sq) {
+ validCount++;
+ }
+ }
+
+ k = 0;
+ rows_si = validCount;
+ cols_si = 1;
+ supId = new int[rows_si * cols_si];
+ for (i = 0; i < (rows_sr * cols_sr); i++) {
+ if (suppressR[i] > r_sq) {
+ supId[k++] = i;
+ }
+ }
+
+
+ while (validCount > 0) {
+ float[] tempp, temps;
+ int rows_tpp, cols_tpp, rows_tps, cols_tps;
+ temp[0] = srtdPnts[supId[0] * cols_sp + 0];
+ temp[1] = srtdPnts[supId[0] * cols_sp + 1];
+ temp[2] = srtdPnts[supId[0] * cols_sp + 2];
+
+ if (iter == 0) {
+ interestPnts = temp;
+ rows_ip[0] = rows_tmp;
+ cols_ip[0] = cols_tmp;
+ } else {
+ interestPnts =
+ this.ffVertcat(interestPnts, rows_ip[0], cols_ip[0], temp, rows_tmp, cols_tmp);
+ rows_ip[0] = rows_ip[0] + rows_tmp;
+ cols_ip[0] = cols_ip[0];
+ }
+
+ iter++;
+
+ // fDeepCopy
+ rows_tpp = rows_sp;
+ cols_tpp = cols_sp;
+ tempp = new float[rows_tpp * cols_tpp];
+ for (i = 0; i < rows_tpp * cols_tpp; i++) {
+ tempp[i] = srtdPnts[i];
+ }
+ // fDeepCopy
+ rows_tps = rows_sr;
+ cols_tps = cols_sr;
+ temps = new float[rows_tps * cols_tps];
+ for (i = 0; i < rows_tps * cols_tps; i++) {
+ temps[i] = suppressR[i];
+ }
+
+ rows_sp = validCount - 1;
+ cols_sp = 3;
+ srtdPnts = new float[rows_sp * cols_sp];
+ rows_sr = validCount - 1;
+ cols_sr = 1;
+ suppressR = new float[rows_sr * cols_sr];
+
+ k = 0;
+ for (i = 0; i < (validCount - 1); i++) {
+ srtdPnts[i * cols_sp + 0] = tempp[supId[i + 1] * cols_sp + 0];
+ srtdPnts[i * cols_sp + 1] = tempp[supId[i + 1] * cols_sp + 1];
+ srtdPnts[i * cols_sp + 2] = tempp[supId[i + 1] * cols_sp + 2];
+ suppressR[i * cols_sr + 0] = temps[supId[i + 1] * cols_sr + 0];
+ }
+
+ int rows1 = rows_ip[0] - 1;
+ int cols1 = cols_ip[0];
+ for (i = 0; i < rows_sp; i++) {
+ t = (float) 0;
+ t1 = (float) 0;
+ if ((C_ROBUST * interestPnts[rows1 * cols1 + 2]) >= srtdPnts[supId[i] * cols_sp + 2]) {
+ t = srtdPnts[supId[i] * cols_sp + 0] - interestPnts[rows1 * cols1 + 0];
+ t1 = srtdPnts[supId[i] * cols_sp + 1] - interestPnts[rows1 * cols1 + 1];
+ t = t * t + t1 * t1;
+ t1 = (float) 0;
+ }
+
+ if ((C_ROBUST * interestPnts[rows1 * cols1 + 2]) < srtdPnts[supId[i] * cols_sp + 2]) {
+ t1 = (float) 1 * (float) MAX_LIMIT;
+ }
+
+ if (suppressR[supId[i]] > (t + t1)) {
+ suppressR[supId[i]] = t + t1;
+ }
+ }
+
+ validCount = 0;
+ for (i = 0; i < rows_sr; i++) {
+ if (suppressR[i] > r_sq) {
+ validCount++;
+ }
+ }
+
+ k = 0;
+ rows_si = validCount;
+ cols_si = 1;
+ supId = new int[rows_si * cols_si];
+
+ for (i = 0; i < rows_sr * cols_sr; i++) {
+ if (suppressR[i] > r_sq) {
+ supId[k++] = i;
+ }
+ }
+ }
+
+ return interestPnts;
+ }
+
+ public void startTrackingLoop() {
+ this.m_image = null;
+ this.m_image_resized = null;
+ }
+
+ public float[] getInterpolatePatch(float[] src, int rows, int cols, float centerX, float centerY) {
+ float[] dst;
+ int rows_d, cols_d;
+ float a, b, a11, a12, a21, a22;
+ int i, j, srcIdxX, dstIdxX, srcIdy, dstIdy, dstIndex;
+
+ a = centerX - (float) (Math.floor(centerX));
+ b = centerY - (float) (Math.floor(centerY));
+
+ a11 = (1 - a) * (1 - b);
+ a12 = a * (1 - b);
+ a21 = (1 - a) * b;
+ a22 = a * b;
+
+ rows_d = 1;
+ cols_d = 2 * this.WINSZ * 2 * this.WINSZ;
+ dst = new float[rows_d * cols_d];
+
+ for (i = -this.WINSZ; i <= (this.WINSZ - 1); i++) {
+ srcIdxX = (int) (Math.floor(centerX)) + i;
+ dstIdxX = i + this.WINSZ;
+
+ for (j = -this.WINSZ; j <= (this.WINSZ - 1); j++) {
+ srcIdy = (int) (Math.floor(centerY)) + j;
+ dstIdy = j + this.WINSZ;
+ dstIndex = dstIdy * 2 * this.WINSZ + dstIdxX;
+ // printf("%f\t%f\t%d\t%d\n", centerX, centerY, srcIdxX, srcIdy);
+ dst[dstIndex] =
+ src[srcIdy * cols + srcIdxX] * a11 + src[(srcIdy + 1) * cols + srcIdxX] * a12
+ + src[srcIdy * cols + (srcIdxX + 1)] * a21
+ + src[(srcIdy + 1) * cols + (srcIdxX + 1)] * a22;
+ }
+ }
+
+ return dst;
+ }
+
+ public int[] calcPyrLKTrack(float[][] Ipyrs, int[] rows, int[] cols, float[] newPnt) {
+ float[] ip1, ip2, idxp1, idxp2, idyp1, idyp2, jp1, jp2, fPnt;
+ int k = 0;
+
+ ip1 = Ipyrs[k++];
+ ip2 = Ipyrs[k++];
+ idxp1 = Ipyrs[k++];
+ idyp1 = Ipyrs[k++];
+ idxp2 = Ipyrs[k++];
+ idyp2 = Ipyrs[k++];
+ jp1 = this.m_image;
+ jp2 = this.m_image_resized;
+ fPnt = this.m_features;
+
+ int idx, level, pLevel, i, winSizeSq;
+ int[] valid, imgDims;
+ int rows_v, cols_v, rows_id, cols_id;
+ float[] rate, iPatch, jPatch, iDxPatch, iDyPatch;
+ int rows_r, cols_r, rows_ip, cols_ip, rows_jp, cols_jp;
+ int rows_idxp, cols_idxp, rows_idyp, cols_idyp;
+ float x, y, dX, dY, c_xx, c_yy, c_xy, tr;
+ int imgSize_1, /* max_iter, */imgSize_2;
+ float mX, mY, dIt, eX, eY, c_det;
+ int nFeatures = this.m_cols_f;
+
+ rows_id = 4;
+ cols_id = 1;
+ imgDims = new int[rows_id * cols_id];
+
+ imgDims[0] = rows[0];
+ imgDims[1] = cols[0];
+ imgDims[2] = rows[1];
+ imgDims[3] = cols[1];
+
+ pLevel = 2;
+ rows_r = 1;
+ cols_r = 6;
+ rate = new float[rows_r * cols_r];
+
+ rate[0] = (float) 1;
+ rate[1] = (float) 0.5;
+ rate[2] = (float) 0.25;
+ rate[3] = (float) 0.125;
+ rate[4] = (float) 0.0625;
+ rate[5] = (float) 0.03125;
+
+ winSizeSq = 4 * this.WINSZ * this.WINSZ;
+ rows_ip = 1;
+ cols_ip = winSizeSq;
+ iPatch = new float[rows_ip * cols_ip];
+ rows_jp = 1;
+ cols_jp = winSizeSq;
+ jPatch = new float[rows_jp * cols_jp];
+ rows_idxp = 1;
+ cols_idxp = winSizeSq;
+ iDxPatch = new float[rows_idxp * cols_idxp];
+ rows_idyp = 1;
+ cols_idyp = winSizeSq;
+ iDyPatch = new float[rows_idyp * cols_idyp];
+
+ rows_v = 1;
+ cols_v = nFeatures;
+ valid = new int[rows_v * cols_v];
+ for(int valid_idx=0;valid_idx<valid.length;valid_idx++){
+ valid[valid_idx]=1;
+ }
+
+ for (i = 0; i < nFeatures; i++) {
+ dX = (float) 0;
+ dY = (float) 0;
+ x = fPnt[i * 2 + 0] * rate[pLevel];
+ y = fPnt[i * 2 + 1] * rate[pLevel];
+ c_det = (float) 0;
+
+ for (level = pLevel - 1; level >= 0; level--) {
+ x = x + x;
+ y = y + y;
+ dX = dX + dX;
+ dY = dY + dY;
+ imgSize_1 = imgDims[level * 2];
+ imgSize_2 = imgDims[level * 2 + 1];
+
+ c_xx = (float) 0;
+ c_xy = (float) 0;
+ c_yy = (float) 0;
+
+ if ((x - (float) this.WINSZ) < (float) 0 || (y - (float) this.WINSZ) < (float) 0
+ || (y + (float) this.WINSZ) >= (float) imgSize_1
+ || (x + (float) this.WINSZ) >= (float) imgSize_2) {
+ valid[i] = 0;
+ break;
+ }
+
+ if (level == 0) {
+ iPatch = getInterpolatePatch(ip1, rows[0], cols[0], x, y);
+ iDxPatch = getInterpolatePatch(idxp1, rows[2], cols[2], x, y);
+ iDyPatch = getInterpolatePatch(idyp1, rows[3], cols[3], x, y);
+ }
+ if (level == 1) {
+ iPatch = getInterpolatePatch(ip2, rows[1], cols[1], x, y);
+ iDxPatch = getInterpolatePatch(idxp2, rows[4], cols[4], x, y);
+ iDyPatch = getInterpolatePatch(idyp2, rows[5], cols[5], x, y);
+ }
+ rows_ip = rows_idxp = rows_idyp = 1;
+ cols_ip = cols_idxp = cols_idyp = 2 * this.WINSZ * 2 * this.WINSZ;
+
+ for (idx = 0; idx < this.WINSZ; idx++) {
+ c_xx += iDxPatch[idx] * iDxPatch[idx];
+ c_xy += iDxPatch[idx] * iDyPatch[idx];
+ c_yy += iDyPatch[idx] * iDyPatch[idx];
+ }
+
+ c_det = (c_xx * c_yy - c_xy * c_xy);
+ tr = c_xx + c_yy;
+
+ if (c_det == (float) 0) {
+ break;
+ }
+
+ if ((float) (c_det / (tr + (float) 0.00001)) < (float) this.accuracy) {
+ valid[i] = 0;
+ break;
+ }
+
+ c_det = (float) (1 / c_det);
+ for (k = 0; k < this.LK_ITER; /* max_iter; */k++) {
+ if ((x + dX - (float) this.WINSZ) < (float) 0
+ || (y + dY - (float) this.WINSZ) < (float) 0
+ || (y + dY + (float) this.WINSZ) >= (float) imgSize_1
+ || (x + dX + (float) this.WINSZ) >= (float) imgSize_2) {
+ valid[i] = 0;
+ break;
+ }
+
+ // printf("x and dx = %d\t%d\t%f\t%f\t%f\t%f\n", i, level, x, dX, y,
+ // dY);
+ if (level == 0) {
+ jPatch = getInterpolatePatch(jp1, this.m_rows, this.m_cols, x + dX, y + dY);
+ }
+ if (level == 1) {
+ jPatch = getInterpolatePatch(jp2, this.m_rows_r, this.m_cols_r, x + dX, y + dY);
+ }
+ rows_jp = 1;
+ cols_jp = 2 * this.WINSZ * 2 * this.WINSZ;
+
+ eX = 0;
+ eY = 0;
+ for (idx = 0; idx < winSizeSq; idx++) {
+ dIt = iPatch[idx] - jPatch[idx];
+ eX += dIt * iDxPatch[idx];
+ eY += dIt * iDyPatch[idx];
+ }
+
+ mX = c_det * (eX * c_yy - eY * c_xy);
+ mY = c_det * (-eX * c_xy + eY * c_xx);
+ // printf("mx = %d\t%d\t%f\t%f\t%f\t%f\t%f\n", i, level, mX, mY,
+ // c_det, eX, eY);
+ dX = dX + mX;
+ dY = dY + mY;
+
+ if ((mX * mX + mY + mY) < this.accuracy) {
+ break;
+ }
+ }
+ }
+
+ newPnt[i] = fPnt[i * 2] + dX;
+ newPnt[1 * nFeatures + i] = fPnt[i * 2 + 1] + dY;
+
+ }
+
+ return valid;
+ }
+
+ public void calcTrack(IXLM ixlm, IYLM iylm, IXLMR ixlmr, IYLMR iylmr) {
+ float[][] Ipyrs = new float[6][];
+ int[] rows = new int[6];
+ int[] cols = new int[6];
+ float[] newpoints, features, np_temp;
+ int rows_n, cols_n, rows_np, cols_np, i, j, k, m, n, numFind;
+ int[] status;
+ int rows_s, cols_s;
+
+ Ipyrs[0] = ixlm.getImage();
+ rows[0] = ixlm.getRows();
+ cols[0] = ixlm.getCols();
+ Ipyrs[2] = ixlm.getResult();
+ rows[2] = ixlm.getRowsR();
+ cols[2] = ixlm.getColsR();
+ Ipyrs[3] = iylm.getResult();
+ rows[3] = iylm.getRowsR();
+ cols[3] = iylm.getColsR();
+
+ Ipyrs[1] = ixlmr.getImage();
+ rows[1] = ixlmr.getRows();
+ cols[1] = ixlmr.getCols();
+ Ipyrs[4] = ixlmr.getResult();
+ rows[4] = ixlmr.getRowsR();
+ cols[4] = ixlmr.getColsR();
+ Ipyrs[5] = iylmr.getResult();
+ rows[5] = iylmr.getRowsR();
+ cols[5] = iylmr.getColsR();
+
+ features = this.m_features;
+ rows_n = 2;
+ cols_n = this.m_cols_f;
+ newpoints = new float[rows_n * cols_n];
+
+ // status_ = calcPyrLKTrack(...)
+ status = this.calcPyrLKTrack(Ipyrs, rows, cols, newpoints);
+ rows_s = 1;
+ cols_s = this.m_cols_f;
+
+ // fDeepCopy
+ np_temp = new float[newpoints.length];
+ rows_np = rows_n;
+ cols_np = cols_n;
+ for (i = 0; i < newpoints.length; i++) {
+ np_temp[i] = newpoints[i];
+ }
+ if (rows_s * cols_s > 0) {
+ int[] findInd;
+ int rows_f, cols_f;
+ rows_f = rows_s * cols_s;
+ cols_f = 1;
+ findInd = new int[rows_f * cols_f];
+
+ k = 0;
+ m = 0;
+ numFind = 0;
+ for (i = 0; i < cols_s; i++) {
+ for (j = 0; j < rows_s; j++) {
+ if (status[j * cols_s + i] != 0) {
+ findInd[k] = m;
+ numFind++;
+ } else {
+ findInd[k] = 0;
+ }
+
+ m++;
+ k++;
+ }
+ }
+
+ rows_n = rows_np;
+ cols_n = numFind;
+ newpoints = new float[rows_n * cols_n];
+
+ k = 0;
+ n = 0;
+ for (i = 0; i < rows_np; i++) {
+ for (j = 0; j < cols_np; j++) {
+ m = findInd[j];
+ if (m > 0) {
+ newpoints[k++] = np_temp[i * cols_np + m];
+ }
+ }
+ }
+ }
+
+ // features_ = fDeepCopy(newpoints_);
+ this.m_rows_f = rows_n;
+ this.m_cols_f = cols_n;
+ features = this.m_features = new float[newpoints.length];
+ for (k = 0; k < newpoints.length; k++) {
+ features[k] = newpoints[k];
+ }
+ }
+
+ public void printImage() {
+ // result validation
+ for (int i = 0; i < this.m_rows; i++) {
+ for (int j = 0; j < this.m_cols; j++) {
+ System.printI((int) (this.m_image[i * this.m_cols + j] * 10));
+ }
+ }
+ }
+
+ public void print3f() {
+ // result validation
+ System.out.println(11111111);
+ for (int j = 0; j < this.N_FEA; j++) {
+ System.out.println((int) (this.m_3f[0][j] * 10));
+ }
+ System.printI(22222222);
+ for (int j = 0; j < this.N_FEA; j++) {
+ System.out.println((int) (this.m_3f[1][j] * 10));
+ }
+ System.printI(33333333);
+ for (int j = 0; j < this.N_FEA; j++) {
+ System.out.println((int) (this.m_3f[2][j] * 10));
+ }
+ }
+
+ public void printFeatures() {
+ // result validation
+ System.out.println("this.m_rows_f="+this.m_rows_f);
+ System.out.println("this.m_cols_="+this.m_cols_f);
+ System.out.println("m_features.length="+this.m_features.length);
+ for (int i = 0; i < this.m_rows_f; i++) {
+ for (int j = 0; j < this.m_cols_f; j++) {
+ System.out.println((int) (this.m_features[i * this.m_cols_f + j] * 10));
+ }
+ }
+ }
+
+ public void run() {
+
+
+ ImageReader imageReader=new ImageReader();
+
+// int[] input = getInput(false);
+ int[] input=imageReader.readImage("1.bmp");
+
+ int pnum = 32; // 60;
+ setBPNum(pnum);
+ int range = (input[0]) / pnum;
+ for (int i = 0; i < pnum; i++) {
+ BlurPiece bp = new BlurPiece(i, range, input);
+ bp.blur();
+ addBP(bp);
+ }
+ postBlur();
+
+
+ float[] Icur = getImage();
+
+ pnum = 16; // 30;
+ range = getRows() / pnum;
+ int rows = getRows();
+ int cols = getCols();
+
+ // create ImageX to calc Sobel_dX
+ ImageXM imageXM = new ImageXM(pnum, rows, cols);
+ for (int i = 0; i < pnum; i++) {
+ ImageX imageX = new ImageX(i, range, Icur, rows, cols);
+ imageX.calcSobel_dX();
+ imageXM.addCalcSobelResult(imageX);
+ }
+ imageXM.calcSobel_dX();
+
+
+ // create ImageY to calc Sobel_dY
+ ImageYM imageYM = new ImageYM(pnum, rows, cols);
+ for (int i = 0; i < pnum; i++) {
+ ImageY imageY = new ImageY(i, range, Icur, rows, cols);
+ imageY.calcSobel_dY();
+ imageYM.addCalcSobelResult(imageY);
+ }
+ imageYM.calcSobel_dY();
+
+
+ // create a Lambda to aggregate results from the ImageXs
+ Lambda lda = new Lambda(WINSZ, N_FEA, pnum, getNumP());
+ lda.calcGoodFeature(imageXM, imageYM);
+// lda.calcGoodFeature(eom_imageXM, eom_imageYM);
+ // validation
+ // lda.printImage();
+ lda.reshape();
+ // validation
+ // lda.printImage();
+
+ // TASK: calcInd
+ int r = lda.getR();
+ float[] data = lda.getImage();
+ int c_rows = lda.getRows();
+ int c_cols = lda.getCols();
+ int c_pnum = lda.getNumP();
+ int c_range = c_rows / c_pnum;
+
+ IDX IDXarray[]=new IDX[c_pnum];
+ for (int i = 0; i < c_pnum; i++) {
+ IDX idx = new IDX(lda.N_FEA, i, c_range, data, c_rows, c_cols, r);
+ idx.fSortIndices();
+ // validation
+ // idx.printInd();
+ IDXarray[i]=idx;
+ }
+
+ resize();
+
+ for (int i = 0; i < c_pnum; i++) {
+ addIDX(IDXarray[i]);
+ }
+
+ // TASK:calcFeatures
+ calcFeatures();
+
+ // TASK:startTrackingLoop
+ do{
+
+ int pnum1 = 8; // 15; // * 2;
+ data = getImage();
+ rows = getRows();
+ cols = getCols();
+ range = rows / pnum1;
+
+ IXLM ixlm = new IXLM(pnum1, data, rows, cols);
+ IYLM iylm = new IYLM(pnum1, data, rows, cols);
+ for (int i = 0; i < pnum1; i++) {
+ IXL ixl = new IXL(i, range, data, rows, cols);
+ ixl.calcSobel_dX();
+ ixlm.addCalcSobelResult(ixl);
+ IYL iyl = new IYL(i, range, data, rows, cols);
+ iyl.calcSobel_dY();
+ iylm.addCalcSobelResult(iyl);
+ }
+ ixlm.calcSobel_dX();
+ iylm.calcSobel_dY();
+
+ data = getImageR();
+ rows = getRowsR();
+ cols = getColsR();
+ range = rows / pnum1;
+ IXLMR ixlmr = new IXLMR(pnum1, data, rows, cols);
+ IYLMR iylmr = new IYLMR(pnum1, data, rows, cols);
+
+ for (int i = 0; i < pnum1; i++) {
+ IXLR ixl = new IXLR(i, range, data, rows, cols);
+ ixl.calcSobel_dX();
+ ixlmr.addCalcSobelResult(ixl);
+ IYLR imy = new IYLR(i, range, data, rows, cols);
+ imy.calcSobel_dY();
+ iylmr.addCalcSobelResult(imy);
+ }
+ ixlmr.calcSobel_dX();
+ iylmr.calcSobel_dY();
+
+ int pnum2 = 32; // 60; // * 2;
+// input = getInput(true);
+ input = imageReader.readImage("1.bmp");
+ this.m_count++;
+
+
+// float ip1[]=new float[getRows()*getCols()];
+// for(int ip1idx=0;ip1idx<getRows()*getCols();ip1idx++){
+// ip1[ip1idx]=(float)input[ip1idx+4];
+// }
+// float[] ip2=resize(ip1);
+//
+
+ range = (input[0]) / pnum2;
+ BlurPieceL bplArray[]=new BlurPieceL[pnum2];
+ for (int i = 0; i < pnum2; i++) {
+ BlurPieceL bpl = new BlurPieceL(i, range, input);
+ bpl.blur();
+ bplArray[i]=bpl;
+ }
+ setBPLNum(pnum2);
+ startTrackingLoop();
+
+ //task addBPL
+ for(int i=0;i<pnum2;i++){
+ addBPL( bplArray[i]);
+ }
+ postBlur();
+
+ resize();
+
+ //task calcTrack
+
+ calcTrack(ixlm, iylm, ixlmr, iylmr);
+
+ }while(!isFinish());
+
+ printFeatures();
+ }
+
+}
--- /dev/null
+public class TrackingBench {
+
+ public static void main(String args[]) {
+ int nump = 32; // 60;
+ TrackDemo tdmo = new TrackDemo(nump);
+ tdmo.run();
+ }
+}
--- /dev/null
+package Benchmarks.oooJava.tracking;
+/** Bamboo version
+ * Ported form SD_VBS 1.0
+ *
+ * @author jzhou
+ *
+ */
+
+task startup(StartupObject s{initialstate}) {
+ //System.printString("task startup\n");
+
+ int nump = 32; //60;
+ TrackDemo tdmo = new TrackDemo(nump){toaddBP};
+
+ int[] input = tdmo.getInput(false);
+ int pnum = 32; //60;
+ int range = (input[0]) / pnum;
+ for(int i = 0; i < pnum; i++) {
+ BlurPiece bp = new BlurPiece(i,
+ range,
+ input){toblur};
+ }
+ tdmo.setBPNum(pnum);
+
+ taskexit(s{!initialstate});
+}
+
+task blur(BlurPiece bp{toblur}) {
+ //System.printString("task blur\n");
+
+ //bp.printImage();
+ bp.blur();
+
+ taskexit(bp{!toblur, toaddBP});
+}
+
+task addBP(TrackDemo tdmo{toaddBP},
+ BlurPiece bp{toaddBP}) {
+ //System.printString("task addBP\n");
+
+ boolean isfinished = tdmo.addBP(bp);
+
+ if(isfinished) {
+ tdmo.postBlur();
+ //tdmo.printImage();
+ taskexit(tdmo{!toaddBP, topreresize},
+ bp{!toaddBP, finish});
+ } else {
+ taskexit(bp{!toaddBP, finish});
+ }
+}
+
+task preresize(TrackDemo tdmo{topreresize}) {
+//System.printString("task preresize\n");
+
+ float[] Icur = tdmo.getImage();
+
+ int pnum = 16; //30;
+ int range = (tdmo.getRows()) / pnum;
+ int rows = tdmo.getRows();
+ int cols = tdmo.getCols();
+//create ImageX to calc Sobel_dX
+ for(int i = 0; i < pnum; i++) {
+ ImageX imageX = new ImageX(i,
+ range,
+ Icur,
+ rows,
+ cols){toprocess};
+ }
+ ImageXM imageXM = new ImageXM(pnum,
+ rows,
+ cols){tomergeX};
+// create ImageY to calc Sobel_dY
+ for(int i = 0; i < pnum; i++) {
+ ImageY imageY = new ImageY(i,
+ range,
+ Icur,
+ rows,
+ cols){toprocess};
+ }
+ ImageYM imageYM = new ImageYM(pnum,
+ rows,
+ cols){tomergeY};
+//create a Lambda to aggregate results from the ImageXs
+ Lambda lda = new Lambda(tdmo.WINSZ,
+ tdmo.N_FEA,
+ pnum,
+ tdmo.getNumP()){tocalcGF};
+
+ taskexit(tdmo{!topreresize, toresize});
+}
+
+task resize(TrackDemo tdmo{toresize}) {
+ //System.printString("task resize\n");
+
+ tdmo.resize();
+
+ taskexit(tdmo{!toresize, tomergeIDX});
+}
+
+task processImageX(ImageX imx{toprocess}) {
+//System.printString("task processImageX\n");
+
+ imx.calcSobel_dX();
+ //imx.printResult();
+
+ taskexit(imx{!toprocess, tomergeX});
+}
+
+task processImageY(ImageY imy{toprocess}) {
+//System.printString("task processImageY\n");
+
+ imy.calcSobel_dY();
+ //imy.printResult();
+
+ taskexit(imy{!toprocess, tomergeY});
+}
+
+task mergeX(ImageXM imxm{tomergeX},
+ ImageX imx{tomergeX}) {
+//System.printString("task mergeX\n");
+
+ boolean isfinished = imxm.addCalcSobelResult(imx);
+
+ if(isfinished) {
+ imxm.calcSobel_dX();
+ taskexit(imxm{!tomergeX, tocalcGF},
+ imx{!tomergeX, finish});
+ } else {
+ taskexit(imx{!tomergeX, finish});
+ }
+}
+
+task mergeY(ImageYM imym{tomergeY},
+ ImageY imy{tomergeY}) {
+//System.printString("task mergeY\n");
+
+ boolean isfinished = imym.addCalcSobelResult(imy);
+
+ if(isfinished) {
+ imym.calcSobel_dY();
+ taskexit(imym{!tomergeY, tocalcGF},
+ imy{!tomergeY, finish});
+ } else {
+ taskexit(imy{!tomergeY, finish});
+ }
+}
+
+task calcGoodFeatureTask(Lambda lda{tocalcGF},
+ ImageXM imxm{tocalcGF},
+ ImageYM imym{tocalcGF}) {
+//System.printString("task calcGoodFeature\n");
+
+ lda.calcGoodFeature(imxm, imym);
+ // validation
+ //lda.printImage();
+ lda.reshape();
+ // validation
+ //lda.printImage();
+
+ taskexit(lda{!tocalcGF, tocalcInd},
+ imxm{!tocalcGF, finish},
+ imym{!tocalcGF, finish});
+}
+
+task calcInd(Lambda lda{tocalcInd}) {
+//System.printString("task calcInd\n");
+
+ int r = lda.getR();
+ float[] data = lda.getImage();
+ int rows = lda.getRows();
+ int cols = lda.getCols();
+ int pnum = lda.getNumP();
+ int range = rows / pnum;
+ for(int i = 0; i < pnum; i++) {
+ IDX idx = new IDX(lda.N_FEA,
+ i,
+ range,
+ data,
+ rows,
+ cols,
+ r){toprocess};
+ }
+
+ taskexit(lda{!tocalcInd, finish});
+}
+
+task processIDX(IDX idx{toprocess}) {
+//System.printString("task processIDX\n");
+
+ idx.fSortIndices();
+ // validation
+ //idx.printInd();
+
+ taskexit(idx{!toprocess, tomergeIDX});
+}
+
+task addIDX(TrackDemo tdmo{tomergeIDX},
+ IDX idx{tomergeIDX}) {
+//System.printString("task addIDX\n");
+
+ boolean isfinished = tdmo.addIDX(idx);
+ //validation
+ //idx.printInd();tdmo.print3f();
+
+ if(isfinished) {
+ //tdmo.print3f();
+ taskexit(tdmo{!tomergeIDX, tocalcF},
+ idx{!tomergeIDX, finish});
+ } else {
+ taskexit(idx{!tomergeIDX, finish});
+ }
+}
+
+task calcFeatures(TrackDemo tdmo{tocalcF}) {
+//System.printString("task calcFeatures\n");
+
+ tdmo.calcFeatures();
+
+ taskexit(tdmo{!tocalcF, tostartL});
+}
+
+task startTrackingLoop(TrackDemo tdmo{tostartL}) {
+//System.printString("task startTrackingLoop\n");
+
+ int pnum1 = 8; //15; // * 2;
+ float[] data = tdmo.getImage();
+ int rows = tdmo.getRows();
+ int cols = tdmo.getCols();
+ int range = rows / pnum1;
+
+ for(int i = 0; i < pnum1; i++) {
+ IXL ixl = new IXL(i,
+ range,
+ data,
+ rows,
+ cols){toprocess};
+ IYL iyl = new IYL(i,
+ range,
+ data,
+ rows,
+ cols){toprocess};
+ }
+ IXLM ixlm1 = new IXLM(pnum1,
+ data,
+ rows,
+ cols){tomergeIXL};
+ IYLM iylm1 = new IYLM(pnum1,
+ data,
+ rows,
+ cols){tomergeIYL};
+
+ data = tdmo.getImageR();
+ rows = tdmo.getRowsR();
+ cols = tdmo.getColsR();
+ range = rows / pnum1;
+ for(int i = 0; i < pnum1; i++) {
+ IXLR ixl = new IXLR(i,
+ range,
+ data,
+ rows,
+ cols){toprocess};
+ IYLR imy = new IYLR(i,
+ range,
+ data,
+ rows,
+ cols){toprocess};
+ }
+ IXLMR ixlm2 = new IXLMR(pnum1,
+ data,
+ rows,
+ cols){tomergeIXLR};
+ IYLMR iylm2 = new IYLMR(pnum1,
+ data,
+ rows,
+ cols){tomergeIYLR};
+
+ int pnum2 = 32; //60; // * 2;
+ int[] input = tdmo.getInput(true);
+ range = (input[0]) / pnum2;
+ for(int i = 0; i < pnum2; i++) {
+ BlurPieceL bpl = new BlurPieceL(i,
+ range,
+ input){toblur};
+ }
+ tdmo.setBPLNum(pnum2);
+ tdmo.startTrackingLoop();
+
+ taskexit(tdmo{!tostartL, toaddBP2});
+}
+
+task blurL(BlurPieceL bpl{toblur}) {
+ //System.printString("task blurL\n");
+
+ //bpl.printImage();
+ bpl.blur();
+
+ taskexit(bpl{!toblur, toaddBP});
+}
+
+task addBPL(TrackDemo tdmo{toaddBP2},
+ BlurPieceL bpl{toaddBP}) {
+//System.printString("task addBPL\n");
+
+ boolean isfinished = tdmo.addBPL(bpl);
+
+ if(isfinished) {
+ tdmo.postBlur();
+ taskexit(tdmo{!toaddBP2, toresize2},
+ bpl{!toaddBP, finish});
+ } else {
+ taskexit(bpl{!toaddBP, finish});
+ }
+}
+
+task resizeL(TrackDemo tdmo{toresize2}) {
+//System.printString("task resizeL\n");
+
+ tdmo.resize();
+
+ taskexit(tdmo{!toresize2, tocalcT});
+}
+
+task processIXL(IXL ixl{toprocess}) {
+//System.printString("task processIXL\n");
+
+ ixl.calcSobel_dX();
+
+ taskexit(ixl{!toprocess, tomergeIXL});
+}
+
+task processIYL(IYL iyl{toprocess}) {
+//System.printString("task processIYL\n");
+
+ iyl.calcSobel_dY();
+
+ taskexit(iyl{!toprocess, tomergeIYL});
+}
+
+task mergeIXL(IXLM ixlm{tomergeIXL},
+ IXL ixl{tomergeIXL}) {
+//System.printString("task mergeIXL\n");
+
+ boolean isfinished = ixlm.addCalcSobelResult(ixl);
+
+ if(isfinished) {
+ ixlm.calcSobel_dX();
+ taskexit(ixlm{!tomergeIXL, tocalcT},
+ ixl{!tomergeIXL, finish});
+ } else {
+ taskexit(ixl{!tomergeIXL, finish});
+ }
+}
+
+task mergeIYL(IYLM iylm{tomergeIYL},
+ IYL iyl{tomergeIYL}) {
+//System.printString("task mergeIYL\n");
+
+ boolean isfinished = iylm.addCalcSobelResult(iyl);
+
+ if(isfinished) {
+ iylm.calcSobel_dY();
+ taskexit(iylm{!tomergeIYL, tocalcT},
+ iyl{!tomergeIYL, finish});
+ } else {
+ taskexit(iyl{!tomergeIYL, finish});
+ }
+}
+
+task processIXLR(IXLR ixl{toprocess}) {
+//System.printString("task processIXLR\n");
+
+ ixl.calcSobel_dX();
+
+ taskexit(ixl{!toprocess, tomergeIXLR});
+}
+
+task processIYLR(IYLR iyl{toprocess}) {
+//System.printString("task processIYLR\n");
+
+ iyl.calcSobel_dY();
+
+ taskexit(iyl{!toprocess, tomergeIYLR});
+}
+
+task mergeIXLR(IXLMR ixlm{tomergeIXLR},
+ IXLR ixl{tomergeIXLR}) {
+//System.printString("task mergeIXLR\n");
+
+ boolean isfinished = ixlm.addCalcSobelResult(ixl);
+
+ if(isfinished) {
+ ixlm.calcSobel_dX();
+ taskexit(ixlm{!tomergeIXLR, tocalcT},
+ ixl{!tomergeIXLR, finish});
+ } else {
+ taskexit(ixl{!tomergeIXLR, finish});
+ }
+}
+
+task mergeIYLR(IYLMR iylm{tomergeIYLR},
+ IYLR iyl{tomergeIYLR}) {
+//System.printString("task mergeIYLR\n");
+
+ boolean isfinished = iylm.addCalcSobelResult(iyl);
+
+ if(isfinished) {
+ iylm.calcSobel_dY();
+ taskexit(iylm{!tomergeIYLR, tocalcT},
+ iyl{!tomergeIYLR, finish});
+ } else {
+ taskexit(iyl{!tomergeIYLR, finish});
+ }
+}
+
+task calcTrack(TrackDemo tdmo{tocalcT},
+ IXLM ixlm{tocalcT},
+ IYLM iylm{tocalcT},
+ IXLMR ixlmr{tocalcT},
+ IYLMR iylmr{tocalcT}) {
+//System.printString("task calcTrack()\n");
+
+ tdmo.calcTrack(ixlm, iylm, ixlmr, iylmr);
+
+ if(tdmo.isFinish()) {
+ //tdmo.printFeatures();
+ // finished
+ taskexit(tdmo{!tocalcT, finish},
+ ixlm{!tocalcT, finish},
+ iylm{!tocalcT, finish},
+ ixlmr{!tocalcT, finish},
+ iylmr{!tocalcT, finish});
+ } else {
+ taskexit(tdmo{!tocalcT, tostartL},
+ ixlm{!tocalcT, finish},
+ iylm{!tocalcT, finish},
+ ixlmr{!tocalcT, finish},
+ iylmr{!tocalcT, finish});
+ }
+}
\ No newline at end of file
--- /dev/null
+PROGRAM=TrackingBench
+
+SOURCE_FILES=TrackingBench.java
+
+BUILDSCRIPT=../../../buildscript
+
+#USEOOO= -ooojava 24 2 -ooodebug
+#BSFLAGS= -64bit -mainclass $(PROGRAM) -garbagestats #-joptimize -noloop -optimize
+USEOOO= -ooojava 8 2 -ooodebug
+BSFLAGS= -64bit -nooptimize -mainclass $(PROGRAM) -debug -garbagestats
+-joptimize
+DISJOINT= -disjoint -disjoint-k 1 -enable-assertions
+
+default:
+ $(BUILDSCRIPT) -nojava $(USEOOO) $(BSFLAGS) $(DISJOINT) -o $(PROGRAM)p $(SOURCE_FILES) -builddir par
+
+single:
+ $(BUILDSCRIPT) $(BSFLAGS) -thread -o $(PROGRAM)s -builddir sing $(SOURCE_FILES)
+
+ooo:
+ $(BUILDSCRIPT) $(USEOOO) $(BSFLAGS) $(DISJOINT) -o $(PROGRAM)p -builddir par $(SOURCE_FILES)
+
+clean:
+ rm -f $(PROGRAM)p.bin $(PROGRAM)s.bin
+ rm -fr par sing
+ rm -f *~
+ rm -f *.dot
+ rm -f *.png
+ rm -f *.txt
+ rm -f aliases.txt
+ rm -f mlpReport*txt
+ rm -f results*txt