diff options
| author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
| commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
| tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/benchmarks/sift/src/c/sift.c | |
| parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) | |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/benchmarks/sift/src/c/sift.c')
| -rw-r--r-- | SD-VBS/benchmarks/sift/src/c/sift.c | 314 |
1 files changed, 314 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/sift/src/c/sift.c b/SD-VBS/benchmarks/sift/src/c/sift.c new file mode 100644 index 0000000..ea0d308 --- /dev/null +++ b/SD-VBS/benchmarks/sift/src/c/sift.c | |||
| @@ -0,0 +1,314 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <math.h> | ||
| 6 | #include "sift.h" | ||
| 7 | |||
| 8 | /** SIFT- Scale Invariant Feature Transform. This algorithm is based on | ||
| 9 | David Lowe's implementation of sift. So, we will use the parameter | ||
| 10 | values from Lowe's implementation. | ||
| 11 | See: http://www.cs.ubc.ca/~lowe/keypoints/ | ||
| 12 | |||
| 13 | SIFT extracts from an image a collection of frames or keypoints. These | ||
| 14 | are oriented disks attacked to blob-like structures of the image. As | ||
| 15 | the image translates, rotates and scales, the frames track these blobs | ||
| 16 | and the deformation. | ||
| 17 | |||
| 18 | 'BoundaryPoint' [bool] | ||
| 19 | If set to 1, frames too close to the image boundaries are discarded. | ||
| 20 | |||
| 21 | 'Sigma0' [pixels] | ||
| 22 | Smoothing of the level 0 of octave 0 of the scale space. | ||
| 23 | (Note that Lowe's 1.6 value refers to the level -1 of octave 0.) | ||
| 24 | |||
| 25 | 'SigmaN' [pixels] | ||
| 26 | Nominal smoothing of the input image. Typically set to 0.5. | ||
| 27 | |||
| 28 | 'Threshold' | ||
| 29 | Threshold used to eliminate weak keypoints. Typical values for | ||
| 30 | intensity images in the range [0,1] are around 0.01. Smaller | ||
| 31 | values mean more keypoints. | ||
| 32 | |||
| 33 | **/ | ||
| 34 | |||
| 35 | F2D* sift(F2D* I) | ||
| 36 | { | ||
| 37 | int rows, cols, K; | ||
| 38 | int subLevels, omin, Octaves, r, NBP, NBO, smin, smax, intervals, o; | ||
| 39 | float sigma, sigman, sigma0, thresh, magnif; | ||
| 40 | int discardBoundaryPoints; | ||
| 41 | F2D *descriptors; | ||
| 42 | F2D **gss, *tfr; | ||
| 43 | F2D **dogss; | ||
| 44 | I2D* i_, *j_, *s_; | ||
| 45 | F2D *oframes, *frames; | ||
| 46 | int i, j, k, m, startRow, startCol, endRow, endCol, firstIn=1; | ||
| 47 | float minVal; | ||
| 48 | I2D* tx1, *ty1, *ts1; | ||
| 49 | I2D* x1, *y1, *s1, *txys; | ||
| 50 | |||
| 51 | rows = I->height; | ||
| 52 | cols = I->width; | ||
| 53 | |||
| 54 | /** | ||
| 55 | Lowe's choices | ||
| 56 | Octaves - octave | ||
| 57 | subLevels - sub-level for image | ||
| 58 | sigma - sigma value for gaussian kernel, for smoothing the image | ||
| 59 | At each successive octave, the data is spatially downsampled by half | ||
| 60 | **/ | ||
| 61 | |||
| 62 | subLevels = 3; | ||
| 63 | omin = -1; | ||
| 64 | minVal = log2f(MIN(rows,cols)); | ||
| 65 | Octaves = (int)(floor(minVal))-omin-4; /* Upto 16x16 images */ | ||
| 66 | sigma0 = 1.6 * pow(2, (1.0/subLevels)); | ||
| 67 | sigman = 0.5; | ||
| 68 | thresh = (0.04/subLevels)/2; | ||
| 69 | r = 10; | ||
| 70 | |||
| 71 | #ifdef test | ||
| 72 | subLevels = 1; | ||
| 73 | Octaves = 1; | ||
| 74 | sigma0 = pow(0.6 * 2, 1); | ||
| 75 | sigman = 1.0; | ||
| 76 | thresh = (1/subLevels)/2; | ||
| 77 | r = 1; | ||
| 78 | #endif | ||
| 79 | |||
| 80 | NBP = 4; | ||
| 81 | NBO = 8 ; | ||
| 82 | magnif = 3.0 ; | ||
| 83 | discardBoundaryPoints = 1 ; | ||
| 84 | |||
| 85 | smin = -1; | ||
| 86 | smax = subLevels+1; | ||
| 87 | intervals = smax - smin + 1; | ||
| 88 | |||
| 89 | /** | ||
| 90 | We build gaussian pyramid for the input image. Given image I, | ||
| 91 | we sub-sample the image into octave 'Octaves' number of levels. At | ||
| 92 | each level, we smooth the image with varying sigman values. | ||
| 93 | |||
| 94 | Gaussiam pyramid can be assumed as a 2-D matrix, where each | ||
| 95 | element is an image. Number of rows corresponds to the number | ||
| 96 | of scales of the pyramid (octaves, "Octaves"). Row 0 (scale 0) is the | ||
| 97 | size of the actual image, Row 1 (scale 1) is half the actual | ||
| 98 | size and so on. | ||
| 99 | |||
| 100 | At each scale, the image is smoothened with different sigma values. | ||
| 101 | So, each row has "intervals" number of smoothened images, starting | ||
| 102 | with least blurred. | ||
| 103 | |||
| 104 | gss holds the entire gaussian pyramid. | ||
| 105 | **/ | ||
| 106 | |||
| 107 | gss = gaussianss(I, sigman, Octaves, subLevels, omin, -1, subLevels+1, sigma0); | ||
| 108 | |||
| 109 | /** | ||
| 110 | Once we build the gaussian pyramid, we compute DOG, the | ||
| 111 | Difference of Gaussians. At every scale, we do: | ||
| 112 | |||
| 113 | dogss[fixedScale][0] = gss[fixedScale][1] - gss[fixedScale][0] | ||
| 114 | |||
| 115 | Difference of gaussian gives us edge information, at each scale. | ||
| 116 | In order to detect keypoints on the intervals per octave, we | ||
| 117 | inspect DOG images at highest and lowest scales of the octave, for | ||
| 118 | extrema detection. | ||
| 119 | **/ | ||
| 120 | |||
| 121 | dogss = diffss(gss, Octaves, intervals); | ||
| 122 | |||
| 123 | /** The extraction of keypoints is carried one octave per time **/ | ||
| 124 | for(o=0; o<Octaves; o++) | ||
| 125 | { | ||
| 126 | F2D *temp; | ||
| 127 | F2D *t; | ||
| 128 | F2D *negate; | ||
| 129 | F2D *idxf, *idxft; | ||
| 130 | I2D *idx; | ||
| 131 | int i1, j1; | ||
| 132 | I2D *s, *i, *j, *x, *y; | ||
| 133 | int sizeRows = dogss[o*intervals]->height; | ||
| 134 | int sizeCols = dogss[o*intervals]->width; | ||
| 135 | |||
| 136 | { | ||
| 137 | int i,j,k=0; | ||
| 138 | temp = fMallocHandle(intervals-1, sizeRows*sizeCols); | ||
| 139 | negate = fMallocHandle(intervals-1, sizeRows*sizeCols); | ||
| 140 | |||
| 141 | /** | ||
| 142 | Keypoints are detected as points of local extrema of the | ||
| 143 | DOG pyramid, at a given octave. In softlocalmax function, the | ||
| 144 | keypoints are extracted by looking at 9x9x9 neighborhood samples. | ||
| 145 | |||
| 146 | We populate temp and negate arrays with the values of the DOG | ||
| 147 | pyramid for a given octave, o. Since we are interested in both | ||
| 148 | local maxima and minima, we compute negate matrix, which is the | ||
| 149 | negated values of the DOG pyramid. | ||
| 150 | |||
| 151 | **/ | ||
| 152 | |||
| 153 | for(i1=0; i1<(intervals-1); i1++) | ||
| 154 | { | ||
| 155 | for(j=0; j<sizeCols; j++) | ||
| 156 | { | ||
| 157 | for(i=0; i<sizeRows; i++) | ||
| 158 | { | ||
| 159 | asubsref(temp,k) = subsref(dogss[o*intervals+i1],i,j); | ||
| 160 | asubsref(negate,k++) = -subsref(dogss[o*intervals+i1],i,j); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | /** | ||
| 167 | siftlocalmax returns indices k, that correspond to local maxima and | ||
| 168 | minima. | ||
| 169 | The 80% tricks discards early very weak points before refinement. | ||
| 170 | **/ | ||
| 171 | idxf = siftlocalmax( temp, 0.8*thresh, intervals, sizeRows, sizeCols); | ||
| 172 | t = siftlocalmax( negate, 0.8*thresh, intervals, sizeRows, sizeCols); | ||
| 173 | |||
| 174 | idxft = fHorzcat(idxf, t); | ||
| 175 | |||
| 176 | /** | ||
| 177 | Since indices is the 1-D index of the temp/negate arrays, we compute | ||
| 178 | the x,y and intervals(s) co-ordinates corresponding to each index. | ||
| 179 | **/ | ||
| 180 | |||
| 181 | idx = ifDeepCopy(idxft); | ||
| 182 | |||
| 183 | x = iSetArray(idx->height,idx->width,0); | ||
| 184 | y = iSetArray(idx->height,idx->width,0); | ||
| 185 | s_ = iSetArray(idx->height,idx->width,0); | ||
| 186 | |||
| 187 | { | ||
| 188 | int i, j; | ||
| 189 | for(i=0; i<idx->height; i++) | ||
| 190 | { | ||
| 191 | for(j=0; j<idx->width; j++) | ||
| 192 | { | ||
