From f618466c25d43f3bae9e40920273bf77de1e1149 Mon Sep 17 00:00:00 2001 From: leochanj105 Date: Mon, 19 Oct 2020 23:09:30 -0400 Subject: initial sd-vbs initial sd-vbs add sd-vbs sd-vbs --- SD-VBS/benchmarks/stitch/src/c/dist2.c | 76 +++++++++ SD-VBS/benchmarks/stitch/src/c/extractFeatures.c | 181 +++++++++++++++++++++ SD-VBS/benchmarks/stitch/src/c/getANMS.c | 145 +++++++++++++++++ SD-VBS/benchmarks/stitch/src/c/harris.c | 141 ++++++++++++++++ SD-VBS/benchmarks/stitch/src/c/matchFeatures.c | 55 +++++++ SD-VBS/benchmarks/stitch/src/c/maxWindow.c | 51 ++++++ SD-VBS/benchmarks/stitch/src/c/script_stitch.c | 65 ++++++++ SD-VBS/benchmarks/stitch/src/c/stitch.h | 22 +++ SD-VBS/benchmarks/stitch/src/c/supress.c | 29 ++++ SD-VBS/benchmarks/stitch/src/matlab/calculateH.m | 24 +++ SD-VBS/benchmarks/stitch/src/matlab/dist2.m | 31 ++++ .../benchmarks/stitch/src/matlab/extractFeatures.m | 56 +++++++ SD-VBS/benchmarks/stitch/src/matlab/getANMS.m | 25 +++ .../stitch/src/matlab/getDirParamLocal.m | 4 + SD-VBS/benchmarks/stitch/src/matlab/harris.m | 37 +++++ SD-VBS/benchmarks/stitch/src/matlab/main.m | 47 ++++++ .../benchmarks/stitch/src/matlab/matchFeatures.m | 13 ++ .../stitch/src/matlab/pics/matched_base_cur.jpg | Bin 0 -> 22688 bytes .../stitch/src/matlab/pics/ransaced_feat.jpg | Bin 0 -> 19198 bytes SD-VBS/benchmarks/stitch/src/matlab/printImage.m | 2 + SD-VBS/benchmarks/stitch/src/matlab/ransac.m | 19 +++ SD-VBS/benchmarks/stitch/src/matlab/readData.m | 9 + .../stitch/src/matlab/script_run_profile.m | 38 +++++ .../stitch/src/matlab/showInterestPoints.m | 7 + SD-VBS/benchmarks/stitch/src/matlab/transformH.m | 13 ++ 25 files changed, 1090 insertions(+) create mode 100644 SD-VBS/benchmarks/stitch/src/c/dist2.c create mode 100644 SD-VBS/benchmarks/stitch/src/c/extractFeatures.c create mode 100644 SD-VBS/benchmarks/stitch/src/c/getANMS.c create mode 100644 SD-VBS/benchmarks/stitch/src/c/harris.c create mode 100644 SD-VBS/benchmarks/stitch/src/c/matchFeatures.c create mode 100644 SD-VBS/benchmarks/stitch/src/c/maxWindow.c create mode 100644 SD-VBS/benchmarks/stitch/src/c/script_stitch.c create mode 100644 SD-VBS/benchmarks/stitch/src/c/stitch.h create mode 100644 SD-VBS/benchmarks/stitch/src/c/supress.c create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/calculateH.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/dist2.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/extractFeatures.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/getANMS.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/getDirParamLocal.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/harris.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/main.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/matchFeatures.m create mode 100644 SD-VBS/benchmarks/stitch/src/matlab/pics/matched_base_cur.jpg create mode 100644 SD-VBS/benchmarks/stitch/src/matlab/pics/ransaced_feat.jpg create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/printImage.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/ransac.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/readData.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/script_run_profile.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/showInterestPoints.m create mode 100755 SD-VBS/benchmarks/stitch/src/matlab/transformH.m (limited to 'SD-VBS/benchmarks/stitch/src') diff --git a/SD-VBS/benchmarks/stitch/src/c/dist2.c b/SD-VBS/benchmarks/stitch/src/c/dist2.c new file mode 100644 index 0000000..d76fcb2 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/dist2.c @@ -0,0 +1,76 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "stitch.h" + +F2D* dist2(I2D* x, F2D* c) +{ + int ndata, dimx, ncentres, dimc, i, j, k; + F2D *n2, *t1, *t2; + float temp; + F2D *s1, *s2, *ctrans; + F2D *mult1, *mult2, *mult3; + + ndata = x->height; + dimx = x->width; + + ncentres = c->height; + dimc = c->width; + + if(dimx != dimc) + return NULL; + + s1 = fSetArray(ncentres, 1, 1); + s2 = fSetArray(ndata, 1, 1); + t1 = fMallocHandle(1, x->height); + + for(j=0; jwidth; j++) + { + temp = 0; + for(i=0; iheight; i++) + { + temp += subsref(x,j,i) * subsref(x,j,i); + } + + asubsref(t1,j) = temp; + } + + mult1 = fMtimes(s1, t1); + t2 = fMallocHandle(1, c->height); + + for(j=0; jwidth; j++) + { + temp = 0; + for(i=0; iheight; i++) + { + temp += subsref(c,j,i) * subsref(c,j,i); + } + + asubsref(t2,j) = temp; + } + + mult2 = fMtimes(s2, t2); + ctrans = fTranspose(c); + mult3 = ifMtimes(x, ctrans); + + for(i=0; i<(mult3->height * mult3->width); i++) + asubsref(mult3,i) = asubsref(mult3,i) * 2; + + free(t1); + free(t2); + free(s1); + free(s2); + free(ctrans); + + n2 = fMallocHandle(ndata, ncentres); + for(i=0; i<(ndata*ncentres); i++) + asubsref(n2,i) = asubsref(mult1,i) + asubsref(mult2,i) - asubsref(mult3,i); + + free(mult1); + free(mult2); + free(mult3); + + return n2; + +} diff --git a/SD-VBS/benchmarks/stitch/src/c/extractFeatures.c b/SD-VBS/benchmarks/stitch/src/c/extractFeatures.c new file mode 100644 index 0000000..ea574e4 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/extractFeatures.c @@ -0,0 +1,181 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "stitch.h" +#include + +#define min(a,b) (aheight; + + vecF = fMallocHandle(n, 64); + I1 = fiDeepCopy(I); + + Iconv = ffConv2(I1, g); + fFreeHandle(I1); + I1 = ffConv2(Iconv, g); + fFreeHandle(Iconv); + Iconv = fDeepCopy(I1); + + { + int i = (Iconv->height/5); + int j = (Iconv->width/5); + Isub = fMallocHandle(i, j); + } + + for(i=0, m=0; mheight; i+=5, m++) + { + for(j=0, k=0; kwidth; j+=5, k++) + { + subsref(Isub,m,k) = subsref(Iconv,i,j); + } + } + + fFreeHandle(Iconv); + fFreeHandle(g1); + fFreeHandle(g); + fFreeHandle(I1); + + nr = Isub->height; + nc = Isub->width; + + Xsub = iMallocHandle(x->height, x->width); + Ysub = iMallocHandle(y->height, y->width); + +// printf("Sizes = %d\t%d\t%d\t%d\n", Isub->height, Isub->width, x->height, x->width); + + for(i=0; i<(x->height*x->width); i++) + { + asubsref(Xsub,i) = min( ( asubsref(x,i) /5), nc-4 ); + asubsref(Ysub,i) = min( ( asubsref(y,i) /5), nr-4 ); + } + + { + int maxX, maxY; + maxX = Xsub->height>Xsub->width?Xsub->height:Xsub->width; + maxY = Ysub->height>Ysub->width?Ysub->height:Ysub->width; + if(maxX < 6 || maxY < 10) + { + fFreeHandle(vecF); + vecF = fSetArray(n,2,0); + for(i=0; i<(x->height); i++) + { + subsref(vecF, i, 0) = asubsref(Xsub,i)*1.0; + subsref(vecF, i, 1) = asubsref(Ysub,i)*1.0; + } + + fFreeHandle(Isub); + iFreeHandle(Xsub); + iFreeHandle(Ysub); + return vecF; + } + } + + { + int newSize = 4; + if(I->height > 32 && I->width >32) + newSize = 64; + fFreeHandle(vecF); + vecF = fMallocHandle(n, newSize); + } + +// printf("Size of Isub = %d\t%d\n", Isub->height, Isub->width); + for(i=0; i= (Isub->height-4)) + asubsref(Ysub,i) = Isub->height-5; + if( asubsref(Xsub,i) >= (Isub->width-4)) + asubsref(Xsub,i) = Isub->width-5; + + m = 0; + temp = 0; +// printf("SUBS %d\t%d\n", asubsref(Ysub,i), asubsref(Xsub,i)); + + for(k= asubsref(Xsub,i)-3; k<=( asubsref(Xsub,i)+4); k++) + { + for(j= asubsref(Ysub,i)-3; j<=( asubsref(Ysub,i)+4); j++) + { +// printf("%d\t%d\n", j, k); + subsref(vecF,i,m) = subsref(Isub,j,k); + temp += subsref(vecF,i,m); + m++; + } + } + mean = temp/64.0; + + std = 0; + for(j=0; j<64; j++) + { + subsref(vecF,i,j) = subsref(vecF,i,j) - mean; + std += subsref(vecF,i,j) * subsref(vecF,i,j); + } + + std = std/64; + std = sqrt(std); + for(j=0; j<64; j++) + { + subsref(vecF,i,j) = subsref(vecF,i,j)/std; + } + } + + iFreeHandle(Xsub); + fFreeHandle(Isub); + iFreeHandle(Ysub); + return vecF; +} + + + diff --git a/SD-VBS/benchmarks/stitch/src/c/getANMS.c b/SD-VBS/benchmarks/stitch/src/c/getANMS.c new file mode 100644 index 0000000..fa03a85 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/getANMS.c @@ -0,0 +1,145 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "stitch.h" + +F2D* getANMS (F2D *points, int r) +{ + unsigned int MAX_LIMIT = 10000000; + F2D *suppressR; + float C_ROBUST = 0.9; + F2D *srtdPnts; + int n, k; + I2D *srtdVIdx, *supId; + float r_sq, t, t1; + F2D *tempF, *srtdV, *interestPnts; + int i, j, validCount=0, cnt, end; + F2D *v; + int iter, rows, cols; + F2D* temp; + int supIdPtr = 0; + + v = fMallocHandle(points->height, 1); + for(i=0; iheight; i++) + asubsref(v,i) = subsref(points,i,2); + + r_sq = r * r * 1.0; + n = v->height; + + srtdVIdx = fSortIndices (v, 1); + srtdPnts = fMallocHandle (srtdVIdx->height, points->width); + + for (i = 0; i < srtdVIdx->height; i++) + for(j=0; jwidth; j++) + subsref(srtdPnts,i,j) = subsref(points, asubsref(srtdVIdx,i), j); + + temp = fSetArray (1, 3, 0); + suppressR = fSetArray(n, 1, MAX_LIMIT); + + validCount = 0; + iter = 0; + for (i = 0; i < suppressR->height; i++) + { + if ( asubsref(suppressR,i) > r_sq) + { + validCount++; + } + } + + k = 0; + supId = iMallocHandle(validCount, 1); + for (i = 0; i < (suppressR->height*suppressR->width); i++) + { + if ( asubsref(suppressR,i) > r_sq) + { + asubsref(supId,k++) = i; + } + } + + while (validCount > 0) + { + F2D *tempp, *temps; + asubsref(temp,0) = subsref(srtdPnts, asubsref(supId,0), 0); + asubsref(temp,1) = subsref(srtdPnts, asubsref(supId,0), 1); + asubsref(temp,2) = subsref(srtdPnts, asubsref(supId,0), 2); + + if(iter == 0) + interestPnts = fDeepCopy(temp); + else + { + tempp = fDeepCopy(interestPnts); + fFreeHandle(interestPnts); + interestPnts = ffVertcat(tempp, temp); + fFreeHandle(tempp); + } + iter++; + + tempp = fDeepCopy(srtdPnts); + temps = fDeepCopy(suppressR); + + fFreeHandle(srtdPnts); + fFreeHandle(suppressR); + + srtdPnts = fMallocHandle(supId->height-1, 3); + suppressR = fMallocHandle(supId->height-1, 1); + + k=0; + for(i=1; iheight; i++) + { + subsref(srtdPnts,k,0) = subsref(tempp, asubsref(supId,i) ,0); + subsref(srtdPnts,k,1) = subsref(tempp, asubsref(supId,i) ,1); + subsref(srtdPnts,k,2) = subsref(tempp, asubsref(supId,i) ,2); + subsref(suppressR,k,0) = subsref(temps, asubsref(supId,i) ,0); + k++; + } + + fFreeHandle(tempp); + fFreeHandle(temps); + rows = interestPnts->height-1; + cols = interestPnts->width; + for (i = 0; i < srtdPnts->height; i++) + { + t = 0; + t1 = 0; + + if ((C_ROBUST * subsref(interestPnts,rows,2)) >= subsref(srtdPnts, i,2)) + { + t = subsref(srtdPnts, i,0) - subsref(interestPnts,rows,0); + t1 = subsref(srtdPnts, i,1) - subsref(interestPnts,rows,1); + t = t * t + t1 * t1; + t1 = 0; + } + + if ((C_ROBUST * subsref(interestPnts,rows,2)) < subsref(srtdPnts, i,2)) + t1 = 1 * MAX_LIMIT; + + if ( asubsref(suppressR, i) > (t + t1)) + { + asubsref(suppressR, i) = t + t1; + } + } + + validCount=0; + for (i = 0; i < suppressR->height; i++) + if ( asubsref(suppressR,i) > r_sq) + validCount++; + + k = 0; + iFreeHandle(supId); + supId = iMallocHandle(validCount, 1); + + for (i = 0; i < suppressR->height*suppressR->width; i++) + if ( asubsref(suppressR,i) > r_sq) + asubsref(supId,k++) = i; + } + + iFreeHandle(supId); + iFreeHandle(srtdVIdx); + fFreeHandle(srtdPnts); + fFreeHandle(temp); + fFreeHandle(suppressR); + fFreeHandle(v); + + return interestPnts; +} diff --git a/SD-VBS/benchmarks/stitch/src/c/harris.c b/SD-VBS/benchmarks/stitch/src/c/harris.c new file mode 100644 index 0000000..a24c2b4 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/harris.c @@ -0,0 +1,141 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "stitch.h" + +F2D* harris(I2D* im) +{ + F2D *img1; + F2D *g1, *g2, *g; + F2D *Ix, *Iy; + F2D *Ix2, *Iy2, *IxIy; + F2D *v, *R, *Rmax, *Rnm; + float eps; + F2D *sobel, *sob, *temp, *temp1; + I2D *win, *x, *y; + int i; + + g1 = fSetArray(5,5,0); + g2 = fSetArray(3,3,0); + + asubsref(g1,0) = 1; + asubsref(g1,1) = 4; + asubsref(g1,2) = 6; + asubsref(g1,3) = 4; + asubsref(g1,4) = 1; + + asubsref(g1,5) = 4; + asubsref(g1,6) = 16; + asubsref(g1,7) = 24; + asubsref(g1,8) = 16; + asubsref(g1,9) = 4; + + asubsref(g1,10) = 6; + asubsref(g1,11) = 24; + asubsref(g1,12) = 36; + asubsref(g1,13) = 24; + asubsref(g1,14) = 6; + + asubsref(g1,15) = 4; + asubsref(g1,16) = 16; + asubsref(g1,17) = 24; + asubsref(g1,18) = 16; + asubsref(g1,19) = 4; + + asubsref(g1,20) = 1; + asubsref(g1,21) = 4; + asubsref(g1,22) = 6; + asubsref(g1,23) = 4; + asubsref(g1,24) = 1; + + asubsref(g2,0) = 1; + asubsref(g2,1) = 2; + asubsref(g2,2) = 1; + + asubsref(g2,3) = 2; + asubsref(g2,4) = 4; + asubsref(g2,5) = 2; + + asubsref(g2,6) = 1; + asubsref(g2,7) = 2; + asubsref(g2,8) = 1; + + g = fDivide(g1, 256); + sob = fMallocHandle(1,3); + asubsref(sob,0) = -0.5; + asubsref(sob,1) = 0; + asubsref(sob,2) = 0.5; + + { + F2D* imf; + imf = fiDeepCopy(im); + img1 = ffConv2(imf, g); + fFreeHandle(imf); + } + + Ix = ffConv2(img1, sob); + fFreeHandle(sob); + sob = fMallocHandle(3,1); + asubsref(sob,0) = -0.5; + asubsref(sob,1) = 0; + asubsref(sob,2) = 0.5; + Iy = ffConv2(img1, sob); + + fFreeHandle(g); + g = fDivide(g2, 16); + eps = 2.2204e-16; + sobel = fTimes(Ix, Ix); + Ix2 = ffConv2(sobel, g); + fFreeHandle(sobel); + + sobel = fTimes(Iy, Iy); + Iy2 = ffConv2(sobel, g); + fFreeHandle(sobel); + + sobel = fTimes(Ix, Iy); + IxIy = ffConv2(sobel, g); + fFreeHandle(sobel); + + temp = fTimes(Ix2, Iy2); + temp1 = fTimes(IxIy, IxIy); + sobel = fMinus(temp, temp1); + + fFreeHandle(temp); + temp = fPlus(Ix2, Iy2); + + for(i=0; i<(temp->height*temp->width); i++) + asubsref(temp,i) += eps; + + R = ffDivide(sobel, temp); + + win = iSetArray(1,2,3); + Rmax = maxWindow(R, win); + Rnm = supress(R, Rmax); + + v = fFind3(Rnm); + + iFreeHandle(win); + fFreeHandle(Rmax); + fFreeHandle(Rnm); + fFreeHandle(R); + + fFreeHandle(img1); + fFreeHandle(g1); + fFreeHandle(g2); + fFreeHandle(g); + fFreeHandle(Ix); + fFreeHandle(Iy); + fFreeHandle(Ix2); + fFreeHandle(Iy2); + fFreeHandle(IxIy); + fFreeHandle(sobel); + fFreeHandle(sob); + fFreeHandle(temp); + fFreeHandle(temp1); +// iFreeHandle(x); +// iFreeHandle(y); + + return v; +} + diff --git a/SD-VBS/benchmarks/stitch/src/c/matchFeatures.c b/SD-VBS/benchmarks/stitch/src/c/matchFeatures.c new file mode 100644 index 0000000..5450eb9 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/matchFeatures.c @@ -0,0 +1,55 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "stitch.h" + +I2D* matchFeatures(F2D* vecF1, F2D* vecF2) +{ + int m, n, n1, n2, n1c, n2c, i, j; + I2D *id, *retMatch, *t; + F2D *val, *temp; + int rows, cols; + + n1 = vecF1->height; + n1c = vecF1->width; + n2 = vecF2->height; + n2c = vecF2->width; + + retMatch = iMallocHandle(1, 2); + + for(i=0; iheight + 1; + cols = t->width; + retMatch = iMallocHandle(rows, cols); + n = 0; + + for(m=0; m<(t->height*t->width); m++) + { + asubsref(retMatch,n++) = asubsref(t,m); + } + + asubsref(retMatch,n++) = i; + asubsref(retMatch,n) = asubsref(id,0); + } + } + + return retMatch; +} diff --git a/SD-VBS/benchmarks/stitch/src/c/maxWindow.c b/SD-VBS/benchmarks/stitch/src/c/maxWindow.c new file mode 100644 index 0000000..07f8dc9 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/maxWindow.c @@ -0,0 +1,51 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "stitch.h" + +F2D* maxWindow(F2D* im, I2D* window) +{ + int exR, exC, rows, cols, tr, tc, i, j, k; + F2D *out, *temp; + float t; + int m; + + exR = asubsref(window,0)/2; + exC = asubsref(window,1)/2; + + rows = im->height; + cols = im->width; + + tr = rows+exR-1; + tc = cols+exC-1; + temp = fDeepCopy(im); + out = fMallocHandle(rows, cols); + + for(i=0; i= rows || (j+m) < 0 || (j+m) >= cols) + continue; + if( subsref(temp,(i+k),(j+m)) > t) + t = subsref(temp,(i+k),(j+m)); + } + } + subsref(out,i,j) = t; + } + } + + fFreeHandle(temp); + return out; +} + + + + + diff --git a/SD-VBS/benchmarks/stitch/src/c/script_stitch.c b/SD-VBS/benchmarks/stitch/src/c/script_stitch.c new file mode 100644 index 0000000..00c9a93 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/script_stitch.c @@ -0,0 +1,65 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "stitch.h" +#include +#include "extra.h" +#define STITCH_MEM 1<<30 +int main(int argc, char* argv[]) +{ + SET_UP + mallopt(M_TOP_PAD, STITCH_MEM); + mallopt(M_MMAP_MAX, 0); + int rows, cols; + F2D *x, *y, *v, *interestPnts, *Fcur, *int1, *int2; + I2D *Icur; + int i, j; + char im1[100], im2[100]; + + + printf("Input image: "); + scanf("%s", im1); + Icur = readImage(im1); + rows = Icur->height; + cols = Icur->width; + + printf("start\n"); + for_each_job{ + v = harris(Icur); + interestPnts = getANMS(v, 24); + int1 = fMallocHandle(interestPnts->height, 1); + int2 = fSetArray(interestPnts->height, 1, 0); + for(i=0; iheight; i++) + { + asubsref(int1,i) = subsref(interestPnts,i,0); + asubsref(int2,i) = subsref(interestPnts,i,1); + } + + Fcur = extractFeatures(Icur, int1, int2); + } + printf("end..\n"); + + +#ifdef CHECK + /** Self checking - use expected.txt from data directory **/ + { + int ret=0; + float tol = 0.02; +#ifdef GENERATE_OUTPUT + fWriteMatrix(Fcur, argv[1]); +#endif + ret = fSelfCheck(Fcur, "expected_C.txt", tol); + if (ret == -1) + printf("Error in Stitch\n"); + } +#endif + iFreeHandle(Icur); + fFreeHandle(v); + fFreeHandle(interestPnts); + fFreeHandle(int1); + fFreeHandle(int2); + fFreeHandle(Fcur); + WRITE_TO_FILE + return 0; +} diff --git a/SD-VBS/benchmarks/stitch/src/c/stitch.h b/SD-VBS/benchmarks/stitch/src/c/stitch.h new file mode 100644 index 0000000..e2202fc --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/stitch.h @@ -0,0 +1,22 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#ifndef _SCRIPT_STITCH_ +#define _SCRIPT_STITCH_ + +#include "sdvbs_common.h" + +F2D* dist2(I2D* x, F2D* c); +F2D* extractFeatures(I2D* I, F2D* x, F2D* y); +F2D* getANMS (F2D *points, int r); +F2D* harris(I2D* im); +I2D* matchFeatures(F2D* vecF1, F2D* vecF2); +F2D* maxWindow(F2D* im, I2D* window); +F2D* supress(F2D* im, F2D* im1); +int script_stitch(); + +#endif + + + diff --git a/SD-VBS/benchmarks/stitch/src/c/supress.c b/SD-VBS/benchmarks/stitch/src/c/supress.c new file mode 100644 index 0000000..6fbdb6c --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/supress.c @@ -0,0 +1,29 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "stitch.h" + +F2D* supress(F2D* im, F2D* im1) +{ + int rows, cols, i, j; + F2D *out; + + rows = im->height; + cols = im->width; + + out = fSetArray(rows, cols, 0); + + for(i=0; i 32 & cols >32) + newSize = 64; +end + +for i=1:n + + minValy = 3; + minValx = 3; + if( Ysub(i) < 4) + Ysub(i) = 4; + end + if( Xsub(i) < 4) + Xsub(i) = 4; + end + + if( Ysub(i) > size(Isub,1)-4) + Ysub(i) = size(Isub,1)-4; + end + if( Xsub(i) > size(Isub,2)-4) + Xsub(i) = size(Isub,2)-4; + end + + vecF(i,:)=reshape(Isub(Ysub(i)-minValy:Ysub(i)+4,Xsub(i)-minValx:Xsub(i)+4),1,newSize); + + %normalization + vecF(i,:)=vecF(i,:)-mean(vecF(i,:)); + vecF(i,:)=vecF(i,:)/std(vecF(i,:)); + %imagesc(reshape(vecF(i,:),8,8)); colormap gray + %drawnow + %pause +end + + diff --git a/SD-VBS/benchmarks/stitch/src/matlab/getANMS.m b/SD-VBS/benchmarks/stitch/src/matlab/getANMS.m new file mode 100755 index 0000000..caece31 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/getANMS.m @@ -0,0 +1,25 @@ +function [interestPnts]=getANMS(x, y, v, r, dataDir) +%interestPnts=[x y v] +MAX_LIMIT=100000000; +C_ROBUST=0.9; +r_sq=r^2; +points=[x y v]; +[n temp]=size(v); +[srtdV srtdVIdx]=sort(v,'descend'); +srtdPnts=points(srtdVIdx,:); + +interestPnts=zeros(0,3); + +suppressR=ones(n,1)*MAX_LIMIT; +supId=find(suppressR>r_sq); + +iter = 0; +while length(supId)>0 + interestPnts=[interestPnts; srtdPnts(supId(1),:)]; + srtdPnts=srtdPnts(supId(2:end),:); + suppressR=suppressR(supId(2:end),:); + + suppressR=min(suppressR,(C_ROBUST*interestPnts(end,3)>srtdPnts(:,3)).*((srtdPnts(:,1)-interestPnts(end,1)).^2 + (srtdPnts(:,2)-interestPnts(end,2)).^2)+(C_ROBUST*interestPnts(end,3)<=srtdPnts(:,3))*MAX_LIMIT); + supId=find(suppressR>r_sq); + iter = iter + 1; +end diff --git a/SD-VBS/benchmarks/stitch/src/matlab/getDirParamLocal.m b/SD-VBS/benchmarks/stitch/src/matlab/getDirParamLocal.m new file mode 100755 index 0000000..7b36886 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/getDirParamLocal.m @@ -0,0 +1,4 @@ +function DIR_PARAM=getDirParam +DIR_PARAM.main_dir=pwd; +DIR_PARAM.data_dir=fullfile(DIR_PARAM.main_dir,'data'); +DIR_PARAM.report_dir=fullfile(DIR_PARAM.main_dir,'report'); diff --git a/SD-VBS/benchmarks/stitch/src/matlab/harris.m b/SD-VBS/benchmarks/stitch/src/matlab/harris.m new file mode 100755 index 0000000..423330e --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/harris.m @@ -0,0 +1,37 @@ + +% Sample code for detecting Harris corners, following +% Brown et al, CVPR 2005 +% by Alyosha Efros, so probably buggy... + +function [x,y,v] = harris(im, dataDir); + +g1 = [1,4,6,4,1; 4,16,24,16,4;6,24,36,24,6;4,16,24,16,4;1,4,6,4,1]/256; +g2 = [1,2,1;2,4,2;1,2,1]/16; + +img1 = conv2(im,g1,'same'); % blur image with sigma_d + +Ix = conv2(img1,[-0.5 0 0.5],'same'); % take x derivative +Iy = conv2(img1,[-0.5;0;0.5],'same'); % take y derivative + +% Compute elements of the Harris matrix H +%%% we can use blur instead of the summing window +Ix2 = conv2(Ix.*Ix,g2,'same'); +Iy2 = conv2(Iy.*Iy,g2,'same'); +IxIy = conv2(Ix.*Iy,g2,'same'); + +R = (Ix2.*Iy2 - IxIy.*IxIy) ... % det(H) + ./ (Ix2 + Iy2 + eps); % trace(H) + epsilon + +% don't want corners close to image border +[rows, cols] = size(im); + +% non-maxima supression within 3x3 windows +nonmax = inline('max(x)'); +Rmax = colfilt(R,[3 3],'sliding',nonmax); % find neighbrhood max +Rnm = R.*(R == Rmax); % supress non-max + +% extract all interest points +[y,x,v] = find(Rnm); + + + diff --git a/SD-VBS/benchmarks/stitch/src/matlab/main.m b/SD-VBS/benchmarks/stitch/src/matlab/main.m new file mode 100755 index 0000000..9be8504 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/main.m @@ -0,0 +1,47 @@ +Icur_list=readData('capitol'); +Icur=Icur_list{1}; +%Icur=Icur(1:150,:,:); +[x y v]=harris(Icur); +interestPntsCur=getANMS(x, y, v, 24); +Fcur=extractFeatures(Icur, interestPntsCur(:,1), interestPntsCur(:,2)); + +for id=2:length(Icur_list) + Iprev=Icur; + Fprev=Fcur; + interestPntsPrev=interestPntsCur; + Icur=Icur_list{id}; + %Icur=Icur(1:150,:,:); + [x y v]=harris(Icur); + %showInterestPoints(I, x, y) + interestPntsCur=getANMS(x, y, v, 16); + %showInterestPoints(I, interestPnts(:,1), interestPnts(:,2)) + Fcur=extractFeatures(Icur, interestPntsCur(:,1), interestPntsCur(:,2)); + matchedPntsIdx=matchFeatures(Fprev, Fcur); + matchedPntsPrev=interestPntsPrev(matchedPntsIdx(:,1),:); + matchedPntsCur=interestPntsCur(matchedPntsIdx(:,2),:); + + %subplot(1,2,1);showInterestPoints(Iprev, matchedPntsPrev(:,1), matchedPntsPrev(:,2));axis image + %subplot(1,2,2);showInterestPoints(Icur, matchedPntsCur(:,1), matchedPntsCur(:,2));axis image + %drawnow + %pause; + %printImage(['featureMatching' int2str(id-1) '_' int2str(id)]); + [retH retPntsIdx]=ransac(matchedPntsPrev, matchedPntsCur, 10000, 100); + subplot(2,2,1);showInterestPoints(Iprev, matchedPntsPrev(retPntsIdx,1), matchedPntsPrev(retPntsIdx,2));axis image + subplot(2,2,2);showInterestPoints(Icur, matchedPntsCur(retPntsIdx,1), matchedPntsCur(retPntsIdx,2));axis image + T=maketform('projective', retH'); + Tfn_Mat=T; + [nr nc nd]=size(Iprev); + Itrans=imtransform(Iprev,T,'XData', [1 nc], 'YData', [1 nr],'FillValues',[0;0;0]); + subplot(2,2,3);imshow(Itrans) + subplot(2,2,4);imagesc(rgb2gray(abs(Icur-Itrans))) + drawnow + pause; + printImage(['ransac' int2str(id-1) '_' int2str(id)]); +end + + %[Itrans2 XData YData]=imtransform(Iprev,T,'FillValues',[0;0;0]); + %for the fast iteration + %[Itrans2 XData2 YData2]=imtransform(Iprev,T,'XData', [-2*nc 2*nc], 'YData', [-2*nr 2*nr],'FillValues',[0;0;0]); + + %h=imshow(Itrans); + diff --git a/SD-VBS/benchmarks/stitch/src/matlab/matchFeatures.m b/SD-VBS/benchmarks/stitch/src/matlab/matchFeatures.m new file mode 100755 index 0000000..7af77e0 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/matchFeatures.m @@ -0,0 +1,13 @@ +function retMatch=matchFeatures(vecF1, vecF2) +[n1 temp]=size(vecF1); +[n2 temp]=size(vecF2); + +retMatch=zeros(0,2); + +for i=1:n1 + [val id]=sort(dist2(vecF1(i,:),vecF2)); + if val(2)~=0 & val(1)/val(2)<0.65 + retMatch=[retMatch; i id(1)]; + end +end + diff --git a/SD-VBS/benchmarks/stitch/src/matlab/pics/matched_base_cur.jpg b/SD-VBS/benchmarks/stitch/src/matlab/pics/matched_base_cur.jpg new file mode 100644 index 0000000..a4bd68b Binary files /dev/null and b/SD-VBS/benchmarks/stitch/src/matlab/pics/matched_base_cur.jpg differ diff --git a/SD-VBS/benchmarks/stitch/src/matlab/pics/ransaced_feat.jpg b/SD-VBS/benchmarks/stitch/src/matlab/pics/ransaced_feat.jpg new file mode 100644 index 0000000..821ca11 Binary files /dev/null and b/SD-VBS/benchmarks/stitch/src/matlab/pics/ransaced_feat.jpg differ diff --git a/SD-VBS/benchmarks/stitch/src/matlab/printImage.m b/SD-VBS/benchmarks/stitch/src/matlab/printImage.m new file mode 100755 index 0000000..82e74f0 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/printImage.m @@ -0,0 +1,2 @@ +function printImage(fname, DIR_PARAM) +print('-djpeg', fullfile(DIR_PARAM, [fname '.jpg'])); diff --git a/SD-VBS/benchmarks/stitch/src/matlab/ransac.m b/SD-VBS/benchmarks/stitch/src/matlab/ransac.m new file mode 100755 index 0000000..4a3c364 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/ransac.m @@ -0,0 +1,19 @@ +function [retH retPntsIdx]=ransac(pntsPrev, pntsCur, k, epsilon) +[n temp]=size(pntsPrev); +pntsPrev=[pntsPrev(:,1:2) ones(n,1)]; +pntsCur=[pntsCur(:,1:2) ones(n,1)]; + +inlierIdx=cell(k,1); +inlierNum=zeros(k,1); +for i=1:k + seed=randperm(n); + H=calculateH(pntsPrev(seed(1:4),:), pntsCur(seed(1:4),:)); + err=(pntsCur-transformH(H,pntsPrev)); + inlierIdx{i}=find(sum(err(:,1:2).^2,2) < epsilon); + inlierNum=length(inlierIdx{i}); +end + +[v maxIdx]=max(inlierNum); +retPntsIdx=inlierIdx{maxIdx}; +retH=calculateH(pntsPrev(retPntsIdx,:), pntsCur(retPntsIdx,:)); + diff --git a/SD-VBS/benchmarks/stitch/src/matlab/readData.m b/SD-VBS/benchmarks/stitch/src/matlab/readData.m new file mode 100755 index 0000000..19643bb --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/readData.m @@ -0,0 +1,9 @@ +function retImgs=readData(imgName, dataDir) +fn=fullfile(dataDir, imgName, '*.jpg'); +filelist=dir(fn); + +retImgs=cell(length(filelist),1); +for i=1:length(filelist) + retImgs{i}=imread(fullfile(dataDir, imgName, filelist(i).name)); +end + diff --git a/SD-VBS/benchmarks/stitch/src/matlab/script_run_profile.m b/SD-VBS/benchmarks/stitch/src/matlab/script_run_profile.m new file mode 100755 index 0000000..f2ca68b --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/script_run_profile.m @@ -0,0 +1,38 @@ +function script_run_profile(dataDir, resultDir, type, common, toolDir) + +path(path, common); +image_list = 1; + +elapsed = zeros(1,2); +for i=1:image_list + Icur = readImage([dataDir, '/', num2str(i) ,'.bmp']); + rows = size(Icur,1); + cols = size(Icur,2); + fprintf(1,'Input size\t\t- (%dx%d)\n', rows, cols); + + %% Self check params + tol = 1; + + %% Timing + start = photonStartTiming; + + [x y v]=harris(Icur,dataDir); + interestPntsCur=getANMS(x, y, v, 24, dataDir); + Fcur=extractFeatures(Icur, interestPntsCur(:,1), interestPntsCur(:,2), dataDir); + + %% Timing + stop = photonEndTiming; + + temp = photonReportTiming(start, stop); + elapsed(1) = elapsed(1) + temp(1); + elapsed(2) = elapsed(2) + temp(2); + + +end + +%% Self checking +fWriteMatrix(Fcur, dataDir); + +%% Timing +photonPrintTiming(elapsed); + diff --git a/SD-VBS/benchmarks/stitch/src/matlab/showInterestPoints.m b/SD-VBS/benchmarks/stitch/src/matlab/showInterestPoints.m new file mode 100755 index 0000000..487cae4 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/showInterestPoints.m @@ -0,0 +1,7 @@ +function showInterestPoints(im, x, y) +% show 'em +imagesc(im); +colormap(gray); +hold on; +plot(x,y,'r.'); +hold off; \ No newline at end of file diff --git a/SD-VBS/benchmarks/stitch/src/matlab/transformH.m b/SD-VBS/benchmarks/stitch/src/matlab/transformH.m new file mode 100755 index 0000000..7a22eb8 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/matlab/transformH.m @@ -0,0 +1,13 @@ +function retPnts=transformH(H, pnts) +MAX_LIMIT=10000000; +[n temp]=size(pnts); + +pntsT = pnts'; +retPnts=(H*pntsT)'; +for i=1:n + if retPnts(i,3)~=0 + retPnts(i,:)=retPnts(i,:)./retPnts(i,3); + else + retPnts(i,:)=[MAX_LIMIT MAX_LIMIT 1]; + end +end -- cgit v1.2.2