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 --- .../src/c/script_texture_synthesis.c | 197 ++++++++++ .../benchmarks/texture_synthesis/src/c/texture.c | 396 +++++++++++++++++++++ .../benchmarks/texture_synthesis/src/c/texture.h | 48 +++ 3 files changed, 641 insertions(+) create mode 100644 SD-VBS/benchmarks/texture_synthesis/src/c/script_texture_synthesis.c create mode 100644 SD-VBS/benchmarks/texture_synthesis/src/c/texture.c create mode 100644 SD-VBS/benchmarks/texture_synthesis/src/c/texture.h (limited to 'SD-VBS/benchmarks/texture_synthesis/src/c') diff --git a/SD-VBS/benchmarks/texture_synthesis/src/c/script_texture_synthesis.c b/SD-VBS/benchmarks/texture_synthesis/src/c/script_texture_synthesis.c new file mode 100644 index 0000000..01ddefd --- /dev/null +++ b/SD-VBS/benchmarks/texture_synthesis/src/c/script_texture_synthesis.c @@ -0,0 +1,197 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "texture.h" +#include +#include "extra.h" +#define TEXTURE_MEM 1<<28 +int WIDTHin,HEIGHTin; +F2D *target, *result; +int WIDTH,HEIGHT; +int localx, localy,targetin=0; +int *atlas; +int *xloopin, *yloopin; +int *xloopout, *yloopout; + +int main(int argc, char **argv) +{ + SET_UP + mallopt(M_TOP_PAD, TEXTURE_MEM); + mallopt(M_MMAP_MAX, 0); + params* data; + I2D *im; + F2D* image; + data = malloc(sizeof(params)); + im = parse_flags(argc, argv); + image = fiDeepCopy(im); + init_params(data); + + printf("start.\n"); + for_each_job{ + create_texture(image, data); + } + printf("end..\n"); +#ifdef CHECK +{ + int ret=0; +#ifdef GENERATE_OUTPUT + fWriteMatrix(result, argv[1]); +#endif + ret = fSelfCheck(result, "expected_C.txt", 1.0); + if(ret < 0) + printf("Error in Texture Synthesis\n"); +} +#endif + iFreeHandle(im); + fFreeHandle(image); + free(data); + fFreeHandle(target); + fFreeHandle(result); + free(atlas); + WRITE_TO_FILE + return 0; +} + +I2D* parse_flags(int argc, char ** argv) +{ + int i, tsx,tsy; + I2D* image; + char fileNm[256]; + + printf("Input image: "); + scanf("%s", fileNm); + image = readImage(fileNm); + WIDTHin = image->width; + HEIGHTin = image->height; + + localx = 3; + localy = 3; + +#ifdef test + WIDTH = WIDTHin*2; + HEIGHT = HEIGHTin*2; + localx = 2; + localy = 2; +#endif +#ifdef sim_fast + WIDTH = WIDTHin*2; + HEIGHT = HEIGHTin*2; + localx = 3; + localy = 3; +#endif +#ifdef sim + WIDTH = WIDTHin*3; + HEIGHT = HEIGHTin*3; + localx = 2; + localy = 2; +#endif +#ifdef sqcif + WIDTH = WIDTHin*6; + HEIGHT = HEIGHTin*6; + localx = 2; + localy = 2; +#endif +#ifdef qcif + WIDTH = WIDTHin*10; + HEIGHT = HEIGHTin*10; + localx = 2; + localy = 2; +#endif +#ifdef cif + WIDTH = WIDTHin*10; + HEIGHT = HEIGHTin*10; + localx = 3; + localy = 3; +#endif +#ifdef vga + WIDTH = WIDTHin*20; + HEIGHT = HEIGHTin*20; + localx = 3; + localy = 3; +#endif +#ifdef fullhd + WIDTH = WIDTHin*20; + HEIGHT = HEIGHTin*20; + localx = 15; + localy = 15; +#endif +#ifdef wuxga + WIDTH = WIDTHin*20; + HEIGHT = HEIGHTin*20; + localx = 5; + localy = 5; +#endif + printf("Input size\t\t- (%dx%d)\n", HEIGHTin, WIDTHin); + +// xloopin = malloc(2*WIDTHin*sizeof(int)); +// yloopin = malloc(2*HEIGHTin*sizeof(int)); +// +// for(i=-WIDTHin/2;ilocalx = localx; data->localy = localy; + data->widthin = WIDTHin; data->widthout = WIDTH; + data->heightin = HEIGHTin; data->heightout = HEIGHT; + + + if(!targetin) + { + for(i=0;iheightout;i++) + { + for(j=0;jwidthout;j++) + { + asubsref(target,a(j,i,data->widthout)+R) = 1.0; +// asubsref(target,a(j,i,data->widthout)+G) = 1.0; +// asubsref(target,a(j,i,data->widthout)+B) = 1.0; + } + } + } + + for(i=0;iheightout;i++) + { + for(j=0;jwidthout;j++) + { + asubsref(result,a(j,i,data->widthout)+R) = 1.0; +// asubsref(result,a(j,i,data->widthout)+G) = 1.0; +// asubsref(result,a(j,i,data->widthout)+B) = 1.0; + } + } +} diff --git a/SD-VBS/benchmarks/texture_synthesis/src/c/texture.c b/SD-VBS/benchmarks/texture_synthesis/src/c/texture.c new file mode 100644 index 0000000..fb0f1ae --- /dev/null +++ b/SD-VBS/benchmarks/texture_synthesis/src/c/texture.c @@ -0,0 +1,396 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include "texture.h" +#include + +int vrstartx, vrfinishx, vrstarty, vrfinishy; +extern params data; +int* candlistx, *candlisty; +int *atlas; +int anotherpass=0,maxcand = 40; +F2D *target, *result; +int *xloopout, *yloopout; +int *xloopin, *yloopin; + +double compare_rest(F2D *image,int x, int y, F2D *tar,int x1, int y1, params* data); + +/********************************* +This is the main texture synthesis function. Called just once +from main to generate image from 'image' into 'result'. +Synthesis parameters (image and neighborhood sizes) are in global +'data-> structure. +*********************************/ + +//void create_texture(F2D *image, F2D *result, params *data) +void create_texture(F2D *image, params *data) +{ + + int i,j,k, ncand, bestx,besty; + double diff,curdiff; + int tsx,tsy; + srand48(1); + candlistx = (int*)malloc(sizeof(int)*(data->localx*(data->localy+1)+1)); + candlisty = (int*)malloc(sizeof(int)*(data->localx*(data->localy+1)+1)); +// if(!anotherpass) init(result, image,data); + if(!anotherpass) init(image,data); + + for(i=0;iheightout-data->localy/2;i++) + { + for(j=0;jwidthout;j++) + { + // First, create a list of candidates for particular pixel. + if(anotherpass) ncand = create_all_candidates(j,i, data); + else ncand = create_candidates(j,i, data); + + // If there are multiple candidates, choose the best based on L_2 norm + + if(ncand > 1) + { + diff = 1e10; + for(k=0;kwidthout)+R) = asubsref(image,a(bestx,besty,data->widthin)+R); +// asubsref(result,a(j,i,data->widthout)+G) = asubsref(image,a(bestx,besty,data->widthin)+G); +// asubsref(result,a(j,i,data->widthout)+B) = asubsref(image,a(bestx,besty,data->widthin)+B); + arrayref(atlas,aa(j,i)) = bestx; + arrayref(atlas,aa(j,i)+1) = besty; + } + } + + // Use full neighborhoods for the last few rows. This is a small + // fraction of total area - can be ignored for optimization purposes. + + for(;iheightout;i++) + { + for(j=0;jwidthout;j++) + { + ncand = create_all_candidates(j,i,data); + if(ncand > 1) + { + diff = 1e10; + for(k=0;kwidthout)+R) = asubsref(image,a(bestx,besty,data->widthin)+R); +// asubsref(result,a(j,i,data->widthout)+G) = asubsref(image,a(bestx,besty,data->widthin)+G); +// asubsref(result,a(j,i,data->widthout)+B) = asubsref(image,a(bestx,besty,data->widthin)+B); + arrayref(atlas,aa(j,i)) = bestx; + arrayref(atlas,aa(j,i)+1) = besty; + } + } + + /********************************* + End of main texture synthesis loop + *********************************/ + + for(i=0;ilocaly/2;i++) + { + for(j=0;jwidthout;j++) + { + ncand = create_all_candidates(j,i,data); + if(ncand > 1) + { + diff = 1e10; + for(k=0;kwidthout)+R) = asubsref(image,a(bestx,besty,data->widthin)+R); +// asubsref(result,a(j,i,data->widthout)+G) = asubsref(image,a(bestx,besty,data->widthin)+G); +// asubsref(result,a(j,i,data->widthout)+B) = asubsref(image,a(bestx,besty,data->widthin)+B); + arrayref(atlas,aa(j,i)) = bestx; + arrayref(atlas,aa(j,i)+1) = besty; + } + } +} + +// Creates a list of valid candidates for given pixel using only L-shaped causal area + +int create_candidates(int x,int y, params* data) +{ + int address,i,j,k,n = 0; + for(i=0;i<=data->localy/2;i++) + { + for(j=-data->localx/2;j<=data->localx/2;j++) + { + if(i==0 && j>=0) + continue; + address = aa( arrayref(xloopout,x+j), arrayref(yloopout,y-i) ); + arrayref(candlistx,n) = arrayref(atlas,address) - j; + arrayref(candlisty,n) = arrayref(atlas,address+1) + i; + + if( arrayref(candlistx,n) >= vrfinishx || arrayref(candlistx,n) < vrstartx) + { + arrayref(candlistx,n) = vrstartx + (int)(drand48()*(vrfinishx-vrstartx)); + arrayref(candlisty,n) = vrstarty + (int)(drand48()*(vrfinishy-vrstarty)); + n++; + continue; + } + + if( arrayref(candlisty,n) >= vrfinishy ) + { + arrayref(candlisty,n) = vrstarty + (int)(drand48()*(vrfinishy-vrstarty)); + arrayref(candlistx,n) = vrstartx + (int)(drand48()*(vrfinishx-vrstartx)); + n++; + continue; + } + + for(k=0;klocaly/2;i<=data->localy/2;i++) + { + for(j=-data->localx/2;j<=data->localx/2;j++) + { + if(i==0 && j>=0) + continue; +// printf("Entering = (%d,%d)\n", i,j); + address = aa( arrayref(xloopout,x+j), arrayref(yloopout,y-i) ); + arrayref(candlistx,n) = arrayref(atlas,address)-j; + arrayref(candlisty,n) = arrayref(atlas,address+1)+i; + + if( arrayref(candlistx,n) >= vrfinishx || arrayref(candlistx,n) < vrstartx) + { + arrayref(candlistx,n) = vrstartx + (int)(drand48()*(vrfinishx-vrstartx)); + arrayref(candlisty,n) = vrstarty + (int)(drand48()*(vrfinishy-vrstarty)); + n++; +// printf("1: (%d,%d)\t%d\n", i,j,n); + continue; + } + + if( arrayref(candlisty,n) >= vrfinishy || arrayref(candlisty,n) < vrstarty) + { + arrayref(candlisty,n) = vrstarty + (int)(drand48()*(vrfinishy-vrstarty)); + arrayref(candlistx,n) = vrstartx + (int)(drand48()*(vrfinishx-vrstartx)); + n++; +// printf("2: (%d,%d)\t%d\n", i,j,n); + continue; + } + + for(k=0;klocalx/2; vrstarty = data->localy/2; + vrfinishx = data->widthin-data->localx/2; + vrfinishy = data->heightin-data->localy/2; + for(i=0;iheightout;i++) + { + for(j=0;jwidthout;j++) + { + if( + asubsref(target,a(j,i,data->widthout)+R) == 1.0 +// && asubsref(target,a(j,i,data->widthout)+G) == 1.0 +// && asubsref(target,a(j,i,data->widthout)+B) == 1.0 + ) + { + tmpx = vrstartx + (int)(drand48()*(vrfinishx-vrstartx)); + tmpy = vrstarty + (int)(drand48()*(vrfinishy-vrstarty)); + if(!anotherpass) + { + arrayref(atlas,aa(j,i)) = tmpx; + arrayref(atlas,aa(j,i)+1) = tmpy; + asubsref(result,a(j,i,data->widthout)+R) = asubsref(image,a(tmpx,tmpy,data->widthin)+R); +// asubsref(result,a(j,i,data->widthout)+G) = asubsref(image,a(tmpx,tmpy,data->widthin)+G); +// asubsref(result,a(j,i,data->widthout)+B) = asubsref(image,a(tmpx,tmpy,data->widthin)+B); + } + } + } + } + + return; +} + + +// Compares two square neighborhoods, returns L_2 difference + +double compare_full_neighb(F2D *image,int x, int y, F2D *image1,int x1, int y1, params* data) +{ + double tmp,res = 0; + int i,j,addr,addr1; + for(i=-(data->localy/2);i<=data->localy/2;i++) + { + for(j=-(data->localx/2);j<=data->localx/2;j++) + { + if( !( i > 0 && y1 > data->localy && y1+i < data->heightout) ) + { + addr = a(x+j,y+i,data->widthin); + addr1 = a( arrayref(xloopout,x1+j), arrayref(yloopout,y1+i), data->widthout); + + tmp = asubsref(image,addr+R) - asubsref(image1,addr1+R); + res += tmp*tmp; +// tmp = asubsref(image,addr+G) - asubsref(image1,addr1+G); +// res += tmp*tmp; +// tmp = asubsref(image,addr+B) - asubsref(image1,addr1+B); +// res += tmp*tmp; + } + } + } + + return res; +} + +// Compares two L-shaped neighborhoods, returns L_2 difference + +double compare_neighb(F2D *image,int x, int y, F2D *image1,int x1, int y1, params* data) +{ + double tmp,res = 0; + int i,j,addr1,addr; + for(i=-(data->localy/2);i<0;i++) + { + for(j=-(data->localx/2);j<=data->localx/2;j++) + { + addr = a(x+j,y+i,data->widthin); + addr1 = a( arrayref(xloopout,x1+j), arrayref(yloopout,y1+i), data->widthout); + + tmp = asubsref(image,addr+R) - asubsref(image1,addr1+R); + res += tmp*tmp; +// tmp = asubsref(image,addr+G) - asubsref(image1,addr1+G); +// res += tmp*tmp; +// tmp = asubsref(image,addr+B) - asubsref(image1,addr1+B); +// res += tmp*tmp; + } + } + + for(j=-(data->localx/2);j<0;j++) + { + addr = a(x+j,y,data->widthin); + addr1 = a( arrayref(xloopout,x1+j), y1, data->widthout); + + tmp = asubsref(image,addr+R) - asubsref(image1,addr1+R); + res += tmp*tmp; +// tmp = asubsref(image,addr+G) - asubsref(image1,addr1+G); +// res += tmp*tmp; +// tmp = asubsref(image,addr+B) - asubsref(image1,addr1+B); +// res += tmp*tmp; + } + + return res; +} + +double compare_rest(F2D *image,int x, int y, F2D *tar,int x1, int y1, params* data) +{ + double tmp,res = 0; + int i,j,addr,addr1; + + for(i=(data->localy/2);i>0;i--) + { + for(j=-(data->localx/2);j<=data->localx/2;j++) + { + addr = a(x+j,y+i,data->widthin); + addr1 = a( arrayref(xloopout,x1+j), arrayref(yloopout,y1+i), data->widthout); + + if( asubsref(tar,addr1+R) != 1.0) //KVS? + { + tmp = asubsref(image,addr+R) - asubsref(tar,addr1+R); + res += tmp*tmp; +// tmp = asubsref(image,addr+G) - asubsref(tar,addr1+G); +// res += tmp*tmp; +// tmp = asubsref(image,addr+B) - asubsref(tar,addr1+B); +// res += tmp*tmp; + } + } + } + + for(j=(data->localx/2);j>0;j--) + { + addr = a(x+j,y,data->widthin); + addr1 = a( arrayref(xloopout,x1+j), y1, data->widthout); + if( asubsref(tar,addr1+R) != 1.0) // KVS? + { + tmp = asubsref(image,addr+R) - asubsref(tar,addr1+R); + res += tmp*tmp; +// tmp = asubsref(image,addr+G) - asubsref(tar,addr1+G); +// res += tmp*tmp; +// tmp = asubsref(image,addr+B) - asubsref(tar,addr1+B); +// res += tmp*tmp; + } + } + + return res; +} + diff --git a/SD-VBS/benchmarks/texture_synthesis/src/c/texture.h b/SD-VBS/benchmarks/texture_synthesis/src/c/texture.h new file mode 100644 index 0000000..9819c03 --- /dev/null +++ b/SD-VBS/benchmarks/texture_synthesis/src/c/texture.h @@ -0,0 +1,48 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#ifndef _TEXTURE_ +#define _TEXTURE_ + +#include "sdvbs_common.h" + +#define R 0 +#define G 1 +#define B 2 +#define a(x,y,W) (1*((y)*(W)+(x))) +#define aa(x,y) (2*((y)*data->widthout+(x))) + +typedef float pixelvalue; + +typedef struct +{ + double sign, diff; + int x,y; + int secondx, secondy; +}signature; + +typedef struct{ + int localx, localy, localz; + int widthin, widthout; + int heightin, heightout; + int nfin, nfout; +}params; + +void *SIGNATURES; + +//void create_texture(F2D *image, F2D *result, params *data); +void create_texture(F2D *image, params *data); +I2D* parse_flags(int argc, char ** argv); +void init_params(params *data); +//void init(F2D *result, F2D *image, params* data); +void init(F2D *image, params* data); +double compare_full_neighb(F2D *image,int x, int y, F2D *image1,int x1, int y1, params* data); +double compare_neighb(F2D *image,int x, int y, F2D *image1,int x1, int y1, params* data); +int create_candidates(int x,int y, params* data); +int create_all_candidates(int x,int y, params* data); + +#endif + + + -- cgit v1.2.2