diff options
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/c/texture.c')
| -rw-r--r-- | SD-VBS/benchmarks/texture_synthesis/src/c/texture.c | 396 |
1 files changed, 0 insertions, 396 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/c/texture.c b/SD-VBS/benchmarks/texture_synthesis/src/c/texture.c deleted file mode 100644 index fb0f1ae..0000000 --- a/SD-VBS/benchmarks/texture_synthesis/src/c/texture.c +++ /dev/null | |||
| @@ -1,396 +0,0 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include "texture.h" | ||
| 6 | #include <math.h> | ||
| 7 | |||
| 8 | int vrstartx, vrfinishx, vrstarty, vrfinishy; | ||
| 9 | extern params data; | ||
| 10 | int* candlistx, *candlisty; | ||
| 11 | int *atlas; | ||
| 12 | int anotherpass=0,maxcand = 40; | ||
| 13 | F2D *target, *result; | ||
| 14 | int *xloopout, *yloopout; | ||
| 15 | int *xloopin, *yloopin; | ||
| 16 | |||
| 17 | double compare_rest(F2D *image,int x, int y, F2D *tar,int x1, int y1, params* data); | ||
| 18 | |||
| 19 | /********************************* | ||
| 20 | This is the main texture synthesis function. Called just once | ||
| 21 | from main to generate image from 'image' into 'result'. | ||
| 22 | Synthesis parameters (image and neighborhood sizes) are in global | ||
| 23 | 'data-> structure. | ||
| 24 | *********************************/ | ||
| 25 | |||
| 26 | //void create_texture(F2D *image, F2D *result, params *data) | ||
| 27 | void create_texture(F2D *image, params *data) | ||
| 28 | { | ||
| 29 | |||
| 30 | int i,j,k, ncand, bestx,besty; | ||
| 31 | double diff,curdiff; | ||
| 32 | int tsx,tsy; | ||
| 33 | srand48(1); | ||
| 34 | candlistx = (int*)malloc(sizeof(int)*(data->localx*(data->localy+1)+1)); | ||
| 35 | candlisty = (int*)malloc(sizeof(int)*(data->localx*(data->localy+1)+1)); | ||
| 36 | // if(!anotherpass) init(result, image,data); | ||
| 37 | if(!anotherpass) init(image,data); | ||
| 38 | |||
| 39 | for(i=0;i<data->heightout-data->localy/2;i++) | ||
| 40 | { | ||
| 41 | for(j=0;j<data->widthout;j++) | ||
| 42 | { | ||
| 43 | // First, create a list of candidates for particular pixel. | ||
| 44 | if(anotherpass) ncand = create_all_candidates(j,i, data); | ||
| 45 | else ncand = create_candidates(j,i, data); | ||
| 46 | |||
| 47 | // If there are multiple candidates, choose the best based on L_2 norm | ||
| 48 | |||
| 49 | if(ncand > 1) | ||
| 50 | { | ||
| 51 | diff = 1e10; | ||
| 52 | for(k=0;k<ncand;k++) | ||
| 53 | { | ||
| 54 | curdiff = compare_neighb(image, arrayref(candlistx,k),arrayref(candlisty,k),result,j,i, data); | ||
| 55 | curdiff += compare_rest(image,arrayref(candlistx,k),arrayref(candlisty,k),target,j,i,data); | ||
| 56 | if(curdiff < diff) | ||
| 57 | { | ||
| 58 | diff = curdiff; | ||
| 59 | bestx = arrayref(candlistx,k); | ||
| 60 | besty = arrayref(candlisty,k); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | else | ||
| 65 | { | ||
| 66 | bestx = arrayref(candlistx,0); | ||
| 67 | besty = arrayref(candlisty,0); | ||
| 68 | } | ||
| 69 | |||
| 70 | // Copy the best candidate to the output image and record its position | ||
| 71 | // in the atlas (atlas is used to create candidates) | ||
| 72 | |||
| 73 | asubsref(result,a(j,i,data->widthout)+R) = asubsref(image,a(bestx,besty,data->widthin)+R); | ||
| 74 | // asubsref(result,a(j,i,data->widthout)+G) = asubsref(image,a(bestx,besty,data->widthin)+G); | ||
| 75 | // asubsref(result,a(j,i,data->widthout)+B) = asubsref(image,a(bestx,besty,data->widthin)+B); | ||
| 76 | arrayref(atlas,aa(j,i)) = bestx; | ||
| 77 | arrayref(atlas,aa(j,i)+1) = besty; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | // Use full neighborhoods for the last few rows. This is a small | ||
| 82 | // fraction of total area - can be ignored for optimization purposes. | ||
| 83 | |||
| 84 | for(;i<data->heightout;i++) | ||
| 85 | { | ||
| 86 | for(j=0;j<data->widthout;j++) | ||
| 87 | { | ||
| 88 | ncand = create_all_candidates(j,i,data); | ||
| 89 | if(ncand > 1) | ||
| 90 | { | ||
| 91 | diff = 1e10; | ||
| 92 | for(k=0;k<ncand;k++) | ||
| 93 | { | ||
| 94 | curdiff = compare_full_neighb(image, arrayref(candlistx,k),arrayref(candlisty,k),result,j,i, data); | ||
| 95 | if(curdiff < diff) | ||
| 96 | { | ||
| 97 | diff = curdiff; | ||
| 98 | bestx = arrayref(candlistx,k); | ||
| 99 | besty = arrayref(candlisty,k); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | bestx = arrayref(candlistx,0); | ||
| 106 | besty = arrayref(candlisty,0); | ||
| 107 | } | ||
| 108 | |||
| 109 | asubsref(result,a(j,i,data->widthout)+R) = asubsref(image,a(bestx,besty,data->widthin)+R); | ||
| 110 | // asubsref(result,a(j,i,data->widthout)+G) = asubsref(image,a(bestx,besty,data->widthin)+G); | ||
| 111 | // asubsref(result,a(j,i,data->widthout)+B) = asubsref(image,a(bestx,besty,data->widthin)+B); | ||
| 112 | arrayref(atlas,aa(j,i)) = bestx; | ||
| 113 | arrayref(atlas,aa(j,i)+1) = besty; | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | /********************************* | ||
| 118 | End of main texture synthesis loop | ||
| 119 | *********************************/ | ||
| 120 | |||
| 121 | for(i=0;i<data->localy/2;i++) | ||
| 122 | { | ||
| 123 | for(j=0;j<data->widthout;j++) | ||
| 124 | { | ||
| 125 | ncand = create_all_candidates(j,i,data); | ||
| 126 | if(ncand > 1) | ||
| 127 | { | ||
| 128 | diff = 1e10; | ||
| 129 | for(k=0;k<ncand;k++) | ||
| 130 | { | ||
| 131 | curdiff = compare_full_neighb(image,arrayref(candlistx,k),arrayref(candlisty,k),result,j,i, data); | ||
| 132 | if(curdiff < diff) | ||
| 133 | { | ||
| 134 | diff = curdiff; | ||
| 135 | bestx = arrayref(candlistx,k); | ||
| 136 | besty = arrayref(candlisty,k); | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
| 140 | else | ||
| 141 | { | ||
| 142 | bestx = arrayref(candlistx,0); | ||
| 143 | besty = arrayref(candlisty,0); | ||
| 144 | } | ||
| 145 | |||
| 146 | asubsref(result,a(j,i,data->widthout)+R) = asubsref(image,a(bestx,besty,data->widthin)+R); | ||
| 147 | // asubsref(result,a(j,i,data->widthout)+G) = asubsref(image,a(bestx,besty,data->widthin)+G); | ||
| 148 | // asubsref(result,a(j,i,data->widthout)+B) = asubsref(image,a(bestx,besty,data->widthin)+B); | ||
| 149 | arrayref(atlas,aa(j,i)) = bestx; | ||
| 150 | arrayref(atlas,aa(j,i)+1) = besty; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | // Creates a list of valid candidates for given pixel using only L-shaped causal area | ||
| 156 | |||
| 157 | int create_candidates(int x,int y, params* data) | ||
| 158 | { | ||
| 159 | int address,i,j,k,n = 0; | ||
| 160 | for(i=0;i<=data->localy/2;i++) | ||
| 161 | { | ||
| 162 | for(j=-data->localx/2;j<=data->localx/2;j++) | ||
| 163 | { | ||
| 164 | if(i==0 && j>=0) | ||
| 165 | continue; | ||
| 166 | address = aa( arrayref(xloopout,x+j), arrayref(yloopout,y-i) ); | ||
| 167 | arrayref(candlistx,n) = arrayref(atlas,address) - j; | ||
| 168 | arrayref(candlisty,n) = arrayref(atlas,address+1) + i; | ||
| 169 | |||
| 170 | if( arrayref(candlistx,n) >= vrfinishx || arrayref(candlistx,n) < vrstartx) | ||
| 171 | { | ||
| 172 | arrayref(candlistx,n) = vrstartx + (int)(drand48()*(vrfinishx-vrstartx)); | ||
| 173 | arrayref(candlisty,n) = vrstarty + (int)(drand48()*(vrfinishy-vrstarty)); | ||
| 174 | n++; | ||
| 175 | continue; | ||
| 176 | } | ||
| 177 | |||
| 178 | if( arrayref(candlisty,n) >= vrfinishy ) | ||
| 179 | { | ||
| 180 | arrayref(candlisty,n) = vrstarty + (int)(drand48()*(vrfinishy-vrstarty)); | ||
| 181 | arrayref(candlistx,n) = vrstartx + (int)(drand48()*(vrfinishx-vrstartx)); | ||
| 182 | n++; | ||
| 183 | continue; | ||
| 184 | } | ||
| 185 | |||
| 186 | for(k=0;k<n;k++) | ||
| 187 | |||
