diff options
| author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
|---|---|---|
| committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
| commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
| tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/benchmarks/disparity/src | |
| parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff) | |
initial sd-vbs
initial sd-vbs
add sd-vbs
sd-vbs
Diffstat (limited to 'SD-VBS/benchmarks/disparity/src')
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/computeSAD.c | 27 | ||||
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/correlateSAD_2D.c | 34 | ||||
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/disparity.h | 24 | ||||
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/finalSAD.c | 28 | ||||
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/findDisparity.c | 29 | ||||
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/getDisparity.c | 43 | ||||
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/integralImage2D2D.c | 31 | ||||
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/padarray2.c | 33 | ||||
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/padarray4.c | 41 | ||||
| -rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/script_disparity.c | 132 | ||||
| -rwxr-xr-x | SD-VBS/benchmarks/disparity/src/matlab/getDisparity.m | 54 | ||||
| -rwxr-xr-x | SD-VBS/benchmarks/disparity/src/matlab/refineDisparity.m | 31 | ||||
| -rwxr-xr-x | SD-VBS/benchmarks/disparity/src/matlab/script_run_profile.m | 43 |
13 files changed, 550 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/disparity/src/c/computeSAD.c b/SD-VBS/benchmarks/disparity/src/c/computeSAD.c new file mode 100644 index 0000000..e12bd55 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/computeSAD.c | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "disparity.h" | ||
| 8 | |||
| 9 | void computeSAD(I2D *Ileft, I2D* Iright_moved, F2D* SAD) | ||
| 10 | { | ||
| 11 | int rows, cols, i, j, diff; | ||
| 12 | |||
| 13 | rows = Ileft->height; | ||
| 14 | cols = Ileft->width; | ||
| 15 | |||
| 16 | for(i=0; i<rows; i++) | ||
| 17 | { | ||
| 18 | for(j=0; j<cols; j++) | ||
| 19 | { | ||
| 20 | diff = subsref(Ileft,i,j) - subsref(Iright_moved,i,j); | ||
| 21 | subsref(SAD,i,j) = diff * diff; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | return; | ||
| 26 | } | ||
| 27 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/correlateSAD_2D.c b/SD-VBS/benchmarks/disparity/src/c/correlateSAD_2D.c new file mode 100644 index 0000000..6b43cbd --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/correlateSAD_2D.c | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "disparity.h" | ||
| 8 | |||
| 9 | void correlateSAD_2D(I2D* Ileft, I2D* Iright, I2D* Iright_moved, int win_sz, int disparity, F2D* SAD, F2D* integralImg, F2D* retSAD, I2D* range) | ||
| 10 | { | ||
| 11 | int rows, cols; | ||
| 12 | int i, j, endRM; | ||
| 13 | //I2D *range; | ||
| 14 | |||
| 15 | //iResetArray(range,1,2,0); | ||
| 16 | subsref(range,0,0) = 0; | ||
| 17 | subsref(range,0,1) = disparity; | ||
| 18 | |||
| 19 | rows = Iright_moved->height; | ||
| 20 | cols = Iright_moved->width; | ||
| 21 | |||
| 22 | for(i=0; i<rows*cols; i++) | ||
| 23 | asubsref(Iright_moved,i) = 0; | ||
| 24 | |||
| 25 | padarray4(Iright, range, -1, Iright_moved); | ||
| 26 | |||
| 27 | computeSAD(Ileft, Iright_moved, SAD); | ||
| 28 | integralImage2D2D(SAD, integralImg); | ||
| 29 | finalSAD(integralImg, win_sz, retSAD); | ||
| 30 | |||
| 31 | //iFreeHandle(range); | ||
| 32 | return; | ||
| 33 | } | ||
| 34 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/disparity.h b/SD-VBS/benchmarks/disparity/src/c/disparity.h new file mode 100644 index 0000000..8617a87 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/disparity.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #ifndef _DISP_ | ||
| 6 | #define _DISP_ | ||
| 7 | |||
| 8 | #include "sdvbs_common.h" | ||
| 9 | void computeSAD(I2D *Ileft, I2D* Iright_moved, F2D* SAD); | ||
| 10 | I2D* getDisparity(I2D* Ileft, I2D* Iright, int win_sz, int max_shift, | ||
| 11 | I2D* minSAD, I2D* retDisp, I2D* halfWin, | ||
| 12 | I2D* IrightPadded, I2D* IleftPadded, I2D* Iright_moved, | ||
| 13 | F2D* retSAD, F2D* SAD, F2D* integralImg, | ||
| 14 | I2D* range); | ||
| 15 | void finalSAD(F2D* integralImg, int win_sz, F2D* retSAD); | ||
| 16 | void findDisparity(F2D* retSAD, F2D* minSAD, I2D* retDisp, int level, int nr, int nc); | ||
| 17 | void integralImage2D2D(F2D* SAD, F2D* integralImg); | ||
| 18 | void correlateSAD_2D(I2D* Ileft, I2D* Iright, I2D* Iright_moved, int win_sz, int disparity, F2D* SAD, F2D* integralImg, F2D* retSAD, I2D* range); | ||
| 19 | I2D* padarray2(I2D* inMat, I2D* borderMat); | ||
| 20 | void padarray4(I2D* inMat, I2D* borderMat, int dir, I2D* paddedArray); | ||
| 21 | |||
| 22 | #endif | ||
| 23 | |||
| 24 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/finalSAD.c b/SD-VBS/benchmarks/disparity/src/c/finalSAD.c new file mode 100644 index 0000000..8155820 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/finalSAD.c | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "disparity.h" | ||
| 8 | |||
| 9 | void finalSAD(F2D* integralImg, int win_sz, F2D* retSAD) | ||
| 10 | { | ||
| 11 | int endR, endC; | ||
| 12 | int i, j, k; | ||
| 13 | |||
| 14 | endR = integralImg->height; | ||
| 15 | endC = integralImg->width; | ||
| 16 | |||
| 17 | k = 0; | ||
| 18 | for(j=0; j<(endC-win_sz); j++) | ||
| 19 | { | ||
| 20 | for(i=0; i<(endR-win_sz); i++) | ||
| 21 | { | ||
| 22 | subsref(retSAD,i,j) = subsref(integralImg,(win_sz+i),(j+win_sz)) + subsref(integralImg,(i+1) ,(j+1)) - subsref(integralImg,(i+1),(j+win_sz)) - subsref(integralImg,(win_sz+i),(j+1)); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | return; | ||
| 27 | } | ||
| 28 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/findDisparity.c b/SD-VBS/benchmarks/disparity/src/c/findDisparity.c new file mode 100644 index 0000000..6335daf --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/findDisparity.c | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "disparity.h" | ||
| 8 | |||
| 9 | void findDisparity(F2D* retSAD, F2D* minSAD, I2D* retDisp, int level, int nr, int nc) | ||
| 10 | { | ||
| 11 | int i, j, a, b; | ||
| 12 | |||
| 13 | for(i=0; i<nr; i++) | ||
| 14 | { | ||
| 15 | for(j=0; j<nc; j++) | ||
| 16 | { | ||
| 17 | a = subsref(retSAD,i,j); | ||
| 18 | b = subsref(minSAD,i,j); | ||
| 19 | if(a<b) | ||
| 20 | { | ||
| 21 | subsref(minSAD,i,j) = a; | ||
| 22 | subsref(retDisp,i,j) = level; | ||
| 23 | } | ||
| 24 | } | ||
| 25 | } | ||
| 26 | return; | ||
| 27 | } | ||
| 28 | |||
| 29 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/getDisparity.c b/SD-VBS/benchmarks/disparity/src/c/getDisparity.c new file mode 100644 index 0000000..3246e97 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/getDisparity.c | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "disparity.h" | ||
| 8 | |||
| 9 | I2D* getDisparity(I2D* Ileft, I2D* Iright, int win_sz, int max_shift, | ||
| 10 | I2D* minSAD, I2D* retDisp, I2D* halfWin, | ||
| 11 | I2D* IrightPadded, I2D* IleftPadded, I2D* Iright_moved, | ||
| 12 | F2D* retSAD, F2D* SAD, F2D* integralImg, | ||
| 13 | I2D* range) | ||
| 14 | { | ||
| 15 | int nr, nc, k; | ||
| 16 | int half_win_sz, rows, cols; | ||
| 17 | |||
| 18 | nr = Ileft->height; | ||
| 19 | nc = Ileft->width; | ||
| 20 | half_win_sz=win_sz/2; | ||
| 21 | |||
| 22 | |||
| 23 | fResetArray(minSAD, nr, nc, 255.0*255.0); | ||
| 24 | iResetArray(retDisp, nr, nc,max_shift); | ||
| 25 | iResetArray(halfWin, 1,2,half_win_sz); | ||
| 26 | |||
| 27 | rows = IleftPadded->height; | ||
| 28 | cols = IleftPadded->width; | ||
| 29 | fResetArray(SAD, rows, cols,255); | ||
| 30 | fResetArray(integralImg, rows, cols,0); | ||
| 31 | //fResetArray(retSAD,rows-win_sz, cols-win_sz, 0); | ||
| 32 | iResetArray(Iright_moved, rows, cols, 0); | ||
| 33 | |||
| 34 | for( k=0; k<max_shift; k++) | ||
| 35 | { | ||
| 36 | correlateSAD_2D(IleftPadded, IrightPadded, Iright_moved, win_sz, k, SAD, integralImg, retSAD, range); | ||
| 37 | findDisparity(retSAD, minSAD, retDisp, k, nr, nc); | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | return retDisp; | ||
| 42 | } | ||
| 43 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/integralImage2D2D.c b/SD-VBS/benchmarks/disparity/src/c/integralImage2D2D.c new file mode 100644 index 0000000..cc964d1 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/integralImage2D2D.c | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "disparity.h" | ||
| 8 | |||
| 9 | void integralImage2D2D(F2D* SAD, F2D* integralImg) | ||
| 10 | { | ||
| 11 | int nr, nc, i, j; | ||
| 12 | |||
| 13 | nr = SAD->height; | ||
| 14 | nc = SAD->width; | ||
| 15 | |||
| 16 | for(i=0; i<nc; i++) | ||
| 17 | subsref(integralImg,0,i) = subsref(SAD,0,i); | ||
| 18 | |||
| 19 | for(i=1; i<nr; i++) | ||
| 20 | for(j=0; j<nc; j++) | ||
| 21 | { | ||
| 22 | subsref(integralImg,i,j) = subsref(integralImg, (i-1), j) + subsref(SAD,i,j); | ||
| 23 | } | ||
| 24 | |||
| 25 | for(i=0; i<nr; i++) | ||
| 26 | for(j=1; j<nc; j++) | ||
| 27 | subsref(integralImg,i,j) = subsref(integralImg, i, (j-1)) + subsref(integralImg,i,j); | ||
| 28 | |||
| 29 | return; | ||
| 30 | |||
| 31 | } | ||
diff --git a/SD-VBS/benchmarks/disparity/src/c/padarray2.c b/SD-VBS/benchmarks/disparity/src/c/padarray2.c new file mode 100644 index 0000000..49f1938 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/padarray2.c | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "disparity.h" | ||
| 8 | |||
| 9 | I2D* padarray2(I2D* inMat, I2D* borderMat) | ||
| 10 | { | ||
| 11 | int rows, cols, bRows, bCols, newRows, newCols; | ||
| 12 | I2D *paddedArray; | ||
| 13 | int i, j; | ||
| 14 | |||
| 15 | rows = inMat->height; | ||
| 16 | cols = inMat->width; | ||
| 17 | |||
| 18 | bRows = borderMat->data[0]; | ||
| 19 | bCols = borderMat->data[1]; | ||
| 20 | |||
| 21 | newRows = rows + bRows*2; | ||
| 22 | newCols = cols + bCols*2; | ||
| 23 | |||
| 24 | paddedArray = iSetArray(newRows, newCols, 0); | ||
| 25 | |||
| 26 | for(i=0; i<rows; i++) | ||
| 27 | for(j=0; j<cols; j++) | ||
| 28 | subsref(paddedArray, (bRows+i), (bCols+j)) = subsref(inMat, i, j); | ||
| 29 | |||
| 30 | return paddedArray; | ||
| 31 | |||
| 32 | } | ||
| 33 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/padarray4.c b/SD-VBS/benchmarks/disparity/src/c/padarray4.c new file mode 100644 index 0000000..321cad9 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/padarray4.c | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <math.h> | ||
| 8 | #include "disparity.h" | ||
| 9 | |||
| 10 | void padarray4(I2D* inMat, I2D* borderMat, int dir, I2D* paddedArray) | ||
| 11 | { | ||
| 12 | int rows, cols, bRows, bCols, newRows, newCols; | ||
| 13 | int i, j; | ||
| 14 | int adir; | ||
| 15 | |||
| 16 | adir = abs(dir); | ||
| 17 | rows = inMat->height; | ||
| 18 | cols = inMat->width; | ||
| 19 | |||
| 20 | bRows = borderMat->data[0]; | ||
| 21 | bCols = borderMat->data[1]; | ||
| 22 | |||
| 23 | newRows = rows + bRows; | ||
| 24 | newCols = cols + bCols; | ||
| 25 | |||
| 26 | if(dir ==1) | ||
| 27 | { | ||
| 28 | for(i=0; i<rows; i++) | ||
| 29 | for(j=0; j<cols; j++) | ||
| 30 | subsref(paddedArray, i, j) = subsref(inMat,i,j); | ||
| 31 | } | ||
| 32 | else | ||
| 33 | { | ||
| 34 | for(i=0; i<rows-bRows; i++) | ||
| 35 | for(j=0; j<cols-bCols; j++) | ||
| 36 | subsref(paddedArray, (bRows+i), (bCols+j)) = subsref(inMat,i,j); | ||
| 37 | } | ||
| 38 | |||
| 39 | return; | ||
| 40 | } | ||
| 41 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/script_disparity.c b/SD-VBS/benchmarks/disparity/src/c/script_disparity.c new file mode 100644 index 0000000..431c02c --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/script_disparity.c | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "disparity.h" | ||
| 8 | #include <malloc.h> | ||
| 9 | #include "extra.h" | ||
| 10 | #define DISPARITY_MEM 1<<24 | ||
| 11 | int main(int argc, char* argv[]) | ||
| 12 | { | ||
| 13 | SET_UP | ||
| 14 | mallopt(M_TOP_PAD, DISPARITY_MEM); | ||
| 15 | mallopt(M_MMAP_MAX, 0); | ||
| 16 | int rows = 32; | ||
| 17 | int cols = 32; | ||
| 18 | I2D *imleft, *imright; | ||
| 19 | volatile I2D* retDisparity; | ||
| 20 | I2D *IrightPadded, *IleftPadded, *Iright_moved; | ||
| 21 | I2D *retDisp, *halfWin; | ||
| 22 | I2D *range; | ||
| 23 | F2D *retSAD, *minSAD, *SAD, *integralImg; | ||
| 24 | unsigned int *start, *endC, *elapsed; | ||
| 25 | |||
| 26 | int i, j; | ||
| 27 | char im1[100], im2[100], timFile[100]; | ||
| 28 | int WIN_SZ=8, SHIFT=64; | ||
| 29 | FILE* fp; | ||
| 30 | |||
| 31 | printf("Image 1: "); | ||
| 32 | scanf("%s", im1); | ||
| 33 | printf("Image 2: "); | ||
| 34 | scanf("%s", im2); | ||
| 35 | #ifdef CHECK | ||
| 36 | char checkFile[100] = "./expected_C.txt"; | ||
| 37 | #endif | ||
| 38 | imleft = readImage(im1); | ||
| 39 | imright = readImage(im2); | ||
| 40 | |||
| 41 | rows = imleft->height; | ||
| 42 | cols = imleft->width; | ||
| 43 | |||
| 44 | #ifdef test | ||
| 45 | WIN_SZ = 2; | ||
| 46 | SHIFT = 1; | ||
| 47 | #endif | ||
| 48 | #ifdef sim_fast | ||
| 49 | WIN_SZ = 4; | ||
| 50 | SHIFT = 4; | ||
| 51 | #endif | ||
| 52 | #ifdef sim | ||
| 53 | WIN_SZ = 4; | ||
| 54 | SHIFT = 8; | ||
| 55 | #endif | ||
| 56 | |||
| 57 | |||
| 58 | int nr, nc, k; | ||
| 59 | int half_win_sz; | ||
| 60 | nr = imleft->height; | ||
| 61 | nc = imleft->width; | ||
| 62 | half_win_sz = WIN_SZ / 2; | ||
| 63 | |||
| 64 | minSAD = fSetArray(nr, nc, 255.0*255.0); | ||
| 65 | retDisp = iSetArray(nr, nc, SHIFT); | ||
| 66 | halfWin = iSetArray(1,2,half_win_sz); | ||
| 67 | |||
| 68 | |||
| 69 | if(WIN_SZ > 1) | ||
| 70 | { | ||
| 71 | IleftPadded = padarray2(imleft, halfWin); | ||
| 72 | IrightPadded = padarray2(imright, halfWin); | ||
| 73 | } | ||
| 74 | else | ||
| 75 | { | ||
| 76 | IleftPadded = imleft; | ||
| 77 | IrightPadded = imright; | ||
| 78 | } | ||
| 79 | |||
| 80 | int paddedRows, paddedCols; | ||
| 81 | paddedRows = IleftPadded->height; | ||
| 82 | paddedCols = IleftPadded->width; | ||
| 83 | SAD = fSetArray(paddedRows, paddedCols,255); | ||
| 84 | integralImg = fSetArray(paddedRows, paddedCols,0); | ||
| 85 | retSAD = fMallocHandle(paddedRows- WIN_SZ, paddedCols - WIN_SZ); | ||
| 86 | Iright_moved = iSetArray(paddedRows, paddedCols, 0); | ||
| 87 | |||
| 88 | range = iMallocHandle(1, 2); | ||
| 89 | printf("starting..\n"); | ||
| 90 | for_each_job{ | ||
| 91 | retDisparity = getDisparity(imleft, imright, WIN_SZ, SHIFT, | ||
| 92 | minSAD, retDisp, halfWin, | ||
| 93 | IrightPadded, IleftPadded, Iright_moved, | ||
| 94 | retSAD, SAD, integralImg, | ||
| 95 | range); | ||
| 96 | } | ||
| 97 | printf("ending\n"); | ||
| 98 | |||
| 99 | #ifdef CHECK | ||
| 100 | /** Self checking - use expected.txt from data directory **/ | ||
| 101 | { | ||
| 102 | int tol, ret=0; | ||
| 103 | tol = 2; | ||
| 104 | #ifdef GENERATE_OUTPUT | ||
| 105 | writeMatrix(retDisparity, argv[1]); | ||
| 106 | #endif | ||
| 107 | ret = selfCheck(retDisparity, checkFile, tol); | ||
| 108 | if (ret == -1) | ||
| 109 | printf("Error in Disparity Map\n"); | ||
| 110 | } | ||
| 111 | /** Self checking done **/ | ||
| 112 | #endif | ||
| 113 | |||
| 114 | //end of benchmark | ||
| 115 | fFreeHandle(minSAD); | ||
| 116 | fFreeHandle(SAD); | ||
| 117 | fFreeHandle(integralImg); | ||
| 118 | iFreeHandle(IrightPadded); | ||
| 119 | iFreeHandle(IleftPadded); | ||
| 120 | iFreeHandle(Iright_moved); | ||
| 121 | fFreeHandle(retSAD); | ||
| 122 | iFreeHandle(imleft); | ||
| 123 | iFreeHandle(imright); | ||
| 124 | iFreeHandle(retDisparity); | ||
| 125 | iFreeHandle(halfWin); | ||
| 126 | iFreeHandle(range); | ||
| 127 | free(start); | ||
| 128 | free(endC); | ||
| 129 | free(elapsed); | ||
| 130 | WRITE_TO_FILE; | ||
| 131 | return 0; | ||
| 132 | } | ||
diff --git a/SD-VBS/benchmarks/disparity/src/matlab/getDisparity.m b/SD-VBS/benchmarks/disparity/src/matlab/getDisparity.m new file mode 100755 index 0000000..db64cac --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/matlab/getDisparity.m | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | function [retDisparity retSAD minSAD]=getDisparity(Ileft, Iright, win_sz, max_shift) | ||
| 2 | Ileft=double(Ileft); | ||
| 3 | Iright=double(Iright); | ||
| 4 | [nr,nc,nb]=size(Ileft); | ||
| 5 | retSAD=zeros(nr, nc, max_shift); | ||
| 6 | |||
| 7 | if(win_sz > 1) | ||
| 8 | half_win_sz=win_sz/2; | ||
| 9 | IleftPadded=padarray(Ileft, [half_win_sz, half_win_sz]); | ||
| 10 | IrightPadded=padarray(Iright, [half_win_sz, half_win_sz]); | ||
| 11 | for i=1:max_shift | ||
| 12 | retSAD(:,:,i)=correlateSAD(IleftPadded,IrightPadded, win_sz, i-1); | ||
| 13 | end | ||
| 14 | [minSAD retDisparity]=min(retSAD,[],3); | ||
| 15 | else | ||
| 16 | IleftPadded = Ileft; | ||
| 17 | IrightPadded = Iright; | ||
| 18 | retSAD=correlateSAD(IleftPadded,IrightPadded, win_sz, 0); | ||
| 19 | [minSAD retDisparity]=min(retSAD,[],3); | ||
| 20 | end | ||
| 21 | end | ||
| 22 | |||
| 23 | function retSAD=correlateSAD(Ileft, Iright, win_sz, disparity) | ||
| 24 | |||
| 25 | Iright_moved=padarray(Iright, [0,disparity], 'pre'); | ||
| 26 | Iright_moved=Iright_moved(:, 1:end-disparity,:); | ||
| 27 | |||
| 28 | [rows, cols] = size(Ileft); | ||
| 29 | for i=1:rows | ||
| 30 | for j=1:cols | ||
| 31 | diff = Ileft(i,j) - Iright_moved(i,j); | ||
| 32 | SAD(i,j) = diff * diff; | ||
| 33 | end | ||
| 34 | end | ||
| 35 | |||
| 36 | %2D scan. | ||
| 37 | integralImg=integralImage2D(SAD); | ||
| 38 | retSAD=integralImg(win_sz+1:end,win_sz+1:end,:) +integralImg(2:end-win_sz+1,2:end-win_sz+1,:)-integralImg(2:end-win_sz+1,win_sz+1:end,:)-integralImg(win_sz+1:end,2:end-win_sz+1,:); | ||
| 39 | |||
| 40 | end | ||
| 41 | |||
| 42 | function retImg=integralImage2D(I) | ||
| 43 | [nr,nc,nb]=size(I); | ||
| 44 | retImg=zeros(nr,nc,nb); | ||
| 45 | retImg(1,:,:)=I(1,:,:); | ||
| 46 | for i=2:nr | ||
| 47 | retImg(i,:,:)=retImg(i-1,:,:)+I(i,:,:); | ||
| 48 | end | ||
| 49 | %vtuneResumeMex; | ||
| 50 | for j=2:nc | ||
| 51 | retImg(:,j,:)=retImg(:,j-1,:)+retImg (:,j,:); | ||
| 52 | end | ||
| 53 | %vtunePauseMex; | ||
| 54 | end | ||
diff --git a/SD-VBS/benchmarks/disparity/src/matlab/refineDisparity.m b/SD-VBS/benchmarks/disparity/src/matlab/refineDisparity.m new file mode 100755 index 0000000..f303236 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/matlab/refineDisparity.m | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | function retDisparity=refineDisparity(Idisp, DispSAD, Ileft, Iright) | ||
| 2 | [nr nc ndist]=size(DispSAD); | ||
| 3 | retDisparity=zeros(nr, nc); | ||
| 4 | |||
| 5 | IdispNext=padarray(Idisp, [0 1], 'replicate', 'post'); | ||
| 6 | IdispNext=IdispNext(:,2:end); | ||
| 7 | |||
| 8 | |||
| 9 | IdispDiff=abs(Idisp-IdispNext); | ||
| 10 | idx=find(IdispDiff>1); | ||
| 11 | [idxI idxJ]=ind2sub([nr, nc], idx); | ||
| 12 | |||
| 13 | %if(Idisp(idx) | ||
| 14 | %sideFlag= | ||
| 15 | checkedResult= (abs( DispSAD(sub2ind( [nr, nc, ndist], idxI, idxJ, Idisp(idx))) - ... | ||
| 16 | DispSAD(sub2ind( [nr, nc, ndist], idxI, idxJ+1, Idisp(idx))) ) < 1 )+1; | ||
| 17 | checkedResult= checkedResult + (abs( DispSAD(sub2ind( [nr, nc, ndist], idxI, idxJ, Idisp(idx+nr))) - ... | ||
| 18 | DispSAD(sub2ind( [nr, nc, ndist], idxI, idxJ+1, Idisp(idx+nr))) ) < 1 ); | ||
| 19 | retDisparity(idx)=checkedResult; | ||
| 20 | |||
| 21 | |||
| 22 | % IdispDiff=(Idisp-IdispNext); | ||
| 23 | % idx=find(IdispDiff<-1); | ||
| 24 | % [idxI idxJ]=ind2sub([nr, nc], idx); | ||
| 25 | % | ||
| 26 | % checkedResult= abs( DispSAD(sub2ind( [nr, nc, ndist], idxI, idxJ, Idisp(idx+nr))) - ... | ||
| 27 | % DispSAD(sub2ind( [nr, nc, ndist], idxI, idxJ+1, Idisp(idx+nr))) ) < 0.5; | ||
| 28 | % retDisparity(idx)=checkedResult; | ||
| 29 | |||
| 30 | |||
| 31 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/matlab/script_run_profile.m b/SD-VBS/benchmarks/disparity/src/matlab/script_run_profile.m new file mode 100755 index 0000000..6e0386d --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/matlab/script_run_profile.m | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | function script_run_profile(dataDir, resultDir, type, common, tooldir) | ||
| 2 | |||
| 3 | path(path,common); | ||
| 4 | |||
| 5 | tol = 2; | ||
| 6 | elapsed = [0, 0]; | ||
| 7 | |||
| 8 | WIN_SZ = 8; | ||
| 9 | SHIFT = 64; | ||
| 10 | |||
| 11 | if(strcmp(type,'test')) | ||
| 12 | WIN_SZ = 2; | ||
| 13 | SHIFT = 1; | ||
| 14 | elseif(strcmp(type, 'sim_fast')) | ||
| 15 | WIN_SZ = 4; | ||
| 16 | SHIFT = 4; | ||
| 17 | elseif(strcmp(type,'sim')) | ||
| 18 | WIN_SZ = 4; | ||
| 19 | SHIFT = 8; | ||
| 20 | end | ||
| 21 | |||
| 22 | outFile = [resultDir, '/', 'out', '.bmp']; | ||
| 23 | |||
| 24 | file = [dataDir, '/1.bmp']; | ||
| 25 | imleft = readImage(file); | ||
| 26 | imright = readImage([dataDir, '/2.bmp']); | ||
| 27 | [rows, cols] = size(imright); | ||
| 28 | |||
| 29 | fprintf(1,'Input size\t\t- (%dx%d)\n', rows, cols); | ||
| 30 | |||
| 31 | start = photonStartTiming; | ||
| 32 | [imDispOwn, DispSAD, minSAD]=getDisparity(double(imleft), double(imright), WIN_SZ, SHIFT); | ||
| 33 | stop = photonEndTiming; | ||
| 34 | elapsed = photonReportTiming(start, stop); | ||
| 35 | |||
| 36 | writeMatrix(imDispOwn, dataDir); | ||
| 37 | imwrite(uint8(minSAD), outFile, 'bmp'); | ||
| 38 | |||
| 39 | photonPrintTiming(elapsed); | ||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | |||
