diff options
Diffstat (limited to 'SD-VBS/benchmarks/sift/src/c/gaussianss.c')
| -rw-r--r-- | SD-VBS/benchmarks/sift/src/c/gaussianss.c | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/sift/src/c/gaussianss.c b/SD-VBS/benchmarks/sift/src/c/gaussianss.c new file mode 100644 index 0000000..52dd95b --- /dev/null +++ b/SD-VBS/benchmarks/sift/src/c/gaussianss.c | |||
| @@ -0,0 +1,185 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include "sift.h" | ||
| 6 | |||
| 7 | F2D* resizeArray(F2D* array, int omin) | ||
| 8 | { | ||
| 9 | F2D* prev = NULL; | ||
| 10 | F2D* current = array; | ||
| 11 | int o; | ||
| 12 | if(omin<0) | ||
| 13 | { | ||
| 14 | for(o=1; o>=-omin; o--) | ||
| 15 | { | ||
| 16 | prev = current; | ||
| 17 | current = doubleSize(current); | ||
| 18 | fFreeHandle(prev); | ||
| 19 | } | ||
| 20 | } | ||
| 21 | if(omin>0) | ||
| 22 | { | ||
| 23 | for(o=1; o<= omin; o++) | ||
| 24 | { | ||
| 25 | prev = current; | ||
| 26 | current = halveSize(current); | ||
| 27 | fFreeHandle(prev); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | return current; | ||
| 31 | } | ||
| 32 | |||
| 33 | /** | ||
| 34 | Returns the Gaussian scale space of image I. Image I is assumed to be | ||
| 35 | pre-smoothed at level SIGMAN. O,S,OMIN,SMIN,SMAX,SIGMA0 are the | ||
| 36 | parameters of the scale space. | ||
| 37 | **/ | ||
| 38 | |||
| 39 | F2D** gaussianss(F2D* array, float sigman, int O, int S, int omin, int smin, int smax, float sigma0) | ||
| 40 | { | ||
| 41 | /* We compute the following items in the function | ||
| 42 | 1. Smooth input image per octave | ||
| 43 | 2. Smooth each octave for different intervals | ||
| 44 | 3. Subtract each "interval-1" smooth image from "interval" image per octave. So, per octave, we have "interval" * DOG images. | ||
| 45 | 4. So, octave * intervals * image | ||
| 46 | 5. Note: At each octave, the image is scaled down in both x and y directions | ||
| 47 | */ | ||
| 48 | |||
| 49 | float k, dsigma0, dsigma; | ||
| 50 | int s, i, j, o, so, M, N, sbest; | ||
| 51 | int intervals = smax-smin+1; | ||
| 52 | float temp, target_sigma, prev_sigma; | ||
| 53 | F2D *TMP, **gss; | ||
| 54 | F2D* I = array; | ||
| 55 | |||
| 56 | // Scale multiplicative step | ||
| 57 | k = pow(2, (1.0/S)); | ||
| 58 | dsigma0 = sigma0 * sqrt(1-(1.0/pow(k,2))); // Scale step factor | ||
| 59 | |||
| 60 | // If omin < 0, multiply the size of the image. | ||
| 61 | I = resizeArray(I, omin); | ||
| 62 | M = I->height; | ||
| 63 | N = I->width; | ||
| 64 | so = -smin+1; // Index offset | ||
| 65 | |||
| 66 | gss = malloc(O*intervals*sizeof(F2D*)); | ||
| 67 | if(gss == NULL) | ||
| 68 | { | ||
| 69 | printf("Could not allocate memory\n"); | ||
| 70 | return NULL; | ||
| 71 | } | ||
| 72 | |||
| 73 | /** | ||
| 74 | First octave | ||
| 75 | -------------------------------------------------------------------- | ||
| 76 | |||
| 77 | The first level of the first octave has scale index (o,s) = | ||
| 78 | (omin,smin) and scale coordinate | ||
| 79 | |||
| 80 | sigma(omin,smin) = sigma0 2^omin k^smin | ||
| 81 | |||
| 82 | The input image I is at nominal scale sigman. Thus in order to get | ||
| 83 | the first level of the pyramid we need to apply a smoothing of | ||
| 84 | |||
| 85 | sqrt( (sigma0 2^omin k^smin)^2 - sigman^2 ). | ||
| 86 | |||
| 87 | As we have pre-scaled the image omin octaves (up or down, | ||
| 88 | depending on the sign of omin), we need to correct this value | ||
| 89 | by dividing by 2^omin, getting | ||
| 90 | |||
| 91 | sqrt( (sigma0 k^smin)^2 - (sigman/2^omin)^2 ) | ||
| 92 | |||
| 93 | **/ | ||
| 94 | |||
| 95 | temp = sqrt(pow((sigma0*pow(k,smin)),2) - pow((sigman/pow(2,omin)),2)); | ||
| 96 | |||
| 97 | { | ||
| 98 | gss[0] = fSetArray(I->height, I->width, 0); | ||
| 99 | imsmooth(I, temp, gss[0] ); | ||
| 100 | } | ||
| 101 | |||
| 102 | for(s=smin; s<smax; s++) | ||
| 103 | { | ||
| 104 | |||
| 105 | /** | ||
| 106 | Here we go from (omin,s-1) to (omin,s). The extra smoothing | ||
| 107 | standard deviation is | ||
| 108 | |||
| 109 | (sigma0 2^omin 2^(s/S) )^2 - (simga0 2^omin 2^(s/S-1/S) )^2 | ||
| 110 | |||
| 111 | After dividing by 2^omin (to take into account the fact | ||
| 112 | that the image has been pre-scaled omin octaves), the | ||
| 113 | standard deviation of the smoothing kernel is | ||
| 114 | |||
| 115 | dsigma = sigma0 k^s sqrt(1-1/k^2) | ||
| 116 | **/ | ||
| 117 | |||
| 118 | dsigma = pow(k,s+1) * dsigma0; | ||
| 119 | gss[s+so] = fSetArray(gss[s+so-1]->height, gss[s+so-1]->width, 0); | ||
| 120 | imsmooth( gss[(s+so-1)] , dsigma, gss[(s+so)] ); | ||
| 121 | } | ||
| 122 | |||
| 123 | /** Other octaves **/ | ||
| 124 | |||
| 125 | for(o=1; o<O; o++) | ||
| 126 | { | ||
| 127 | /** | ||
| 128 | We need to initialize the first level of octave (o,smin) from | ||
| 129 | the closest possible level of the previous octave. A level (o,s) | ||
| 130 | in this octave corrsponds to the level (o-1,s+S) in the previous | ||
| 131 | octave. In particular, the level (o,smin) correspnds to | ||
| 132 | (o-1,smin+S). However (o-1,smin+S) might not be among the levels | ||
| 133 | (o-1,smin), ..., (o-1,smax) that we have previously computed. | ||
| 134 | The closest pick is | ||
| 135 | |||
| 136 | / smin+S if smin+S <= smax | ||
| 137 | (o-1,sbest) , sbest = | | ||
| 138 | \ smax if smin+S > smax | ||
| 139 | |||
| 140 | The amount of extra smoothing we need to apply is then given by | ||
| 141 | |||
| 142 | ( sigma0 2^o 2^(smin/S) )^2 - ( sigma0 2^o 2^(sbest/S - 1) )^2 | ||
| 143 | |||
| 144 | As usual, we divide by 2^o to cancel out the effect of the | ||
| 145 | downsampling and we get | ||
| 146 | |||
| 147 | ( sigma 0 k^smin )^2 - ( sigma0 2^o k^(sbest - S) )^2 | ||
| 148 | **/ | ||
| 149 | |||
| 150 | sbest = MIN(smin+S-1, smax-1); | ||
| 151 | TMP = halveSize( gss[(o-1)*intervals+sbest+so]); | ||
| 152 | target_sigma = sigma0 * pow(k,smin); | ||
| 153 | prev_sigma = sigma0 * pow(k, (sbest+1)-S); | ||
| 154 | |||
| 155 | temp = sqrt(pow(target_sigma,2) - pow(prev_sigma, 2)); | ||
| 156 | if(target_sigma > prev_sigma) | ||
| 157 | { | ||
| 158 | gss[o*intervals] = fSetArray(TMP->height, TMP->width, 0); | ||
| 159 | imsmooth(TMP, temp, gss[o*intervals] ); | ||
| 160 | } | ||
| 161 | else | ||
| 162 | { | ||
| 163 | int i; | ||
| 164 | gss[o*intervals] = fSetArray(TMP->height, TMP->width, 0); | ||
| 165 | for(i=0; i<(TMP->height*TMP->width); i++) | ||
| 166 | asubsref(gss[o*intervals],i) = asubsref(TMP,i); | ||
| 167 | } | ||
| 168 | |||
| 169 | M = TMP->height; | ||
| 170 | N = TMP->width; | ||
| 171 | |||
| 172 | fFreeHandle(TMP); | ||
| 173 | |||
| 174 | for(s=smin; s<smax; s++) | ||
| 175 | { | ||
| 176 | // The other levels are determined as above for the first octave. | ||
| 177 | dsigma = pow(k,s+1) * dsigma0; | ||
| 178 | gss[o*intervals+s+so] = fSetArray(gss[o*intervals+s-1+so]->height, gss[o*intervals+s-1+so]->width, 0); | ||
| 179 | imsmooth( gss[o*intervals+s-1+so] , dsigma, gss[o*intervals+s+so]); | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | fFreeHandle(I); | ||
| 184 | return gss; | ||
| 185 | } | ||
