/* Same as ConvHorizontal, but apply to vertical columns of image. */ static void ConvVertical(LWImage<flnum>& image, flnum *kernel, int ksize) { flnum buffer[8000]; const int rows = image.h; const int cols = image.w; const int halfsize = ksize / 2; assert(rows + ksize < 8000); /*TANG: this will give a limit of image size*/ for(int comp = 0; comp < image.comps; comp++) { const int deltaComp = comp*image.stepComp(); for (int c = 0; c < cols; c++) { for (int i = 0; i < halfsize; i++) buffer[i] = image.pixel(c,0)[deltaComp]; for (int i = 0; i < rows; i++) buffer[halfsize + i] = image.pixel(c,i)[deltaComp]; for (int i = 0; i < halfsize; i++) buffer[halfsize + rows + i] = image.pixel(c,rows-1)[deltaComp]; ConvBufferFast(buffer, kernel, rows, ksize); for (int r = 0; r < rows; r++) image.pixel(c,r)[deltaComp] = buffer[r]; } } }
/* Convolve image with the 1-D kernel vector along image rows. This is designed to be as efficient as possible. Pixels outside the image are set to the value of the closest image pixel. */ static void ConvHorizontal(LWImage<flnum>& image, flnum *kernel, int ksize) { flnum buffer[8000]; const int rows = image.h; const int cols = image.w; const int halfsize = ksize / 2; assert(cols + ksize < 8000); /*TANG: this will give a limit of image size*/ for(int comp = 0; comp < image.comps; comp++) { const int deltaComp = comp*image.stepComp(); for (int r = 0; r < rows; r++) { /* Copy the row into buffer with pixels at ends replicated for half the mask size. This avoids need to check for ends within inner loop. */ for (int i = 0; i < halfsize; i++) buffer[i] = image.pixel(0,r)[deltaComp]; for (int i = 0; i < cols; i++) buffer[halfsize + i] = image.pixel(i,r)[deltaComp]; for (int i = 0; i < halfsize; i++) buffer[halfsize + cols + i] = image.pixel(cols-1,r)[deltaComp]; ConvBufferFast(buffer, kernel, cols, ksize); for (int c = 0; c < cols; c++) image.pixel(c,r)[deltaComp] = buffer[c]; } } }
/* Create a keypoint at a peak near scale space location (s,r,c), where s is scale (index of DOGs image), and (r,c) is (row, col) location. Add to the list of keys with any new keys added. */ void InterpKeyPoint( const flimage* dogs, int s, int r, int c, const flimage& grad, LWImage<bool>& map, float octSize, keypointslist& keys, int movesRemain,siftPar &par) { /* Fit quadratic to determine offset and peak value. */ std::vector<float> offset(3); float peakval = FitQuadratic(offset, dogs, r, c); if (DEBUG) printf("peakval: %f, of[0]: %f of[1]: %f of[2]: %f\n", peakval, offset[0], offset[1], offset[2]); /* Move to an adjacent (row,col) location if quadratic interpolation is larger than 0.6 units in some direction (we use 0.6 instead of 0.5 to avoid jumping back and forth near boundary). We do not perform move to adjacent scales, as it is seldom useful and we do not have easy access to adjacent scale structures. The movesRemain counter allows only a fixed number of moves to prevent possibility of infinite loops. */ int newr = r, newc = c; if (offset[1] > 0.6 && r < dogs[0].h - 3) newr++; else if (offset[1] < -0.6 && r > 3) newr--; if (offset[2] > 0.6 && c < dogs[0].w - 3) newc++; else if (offset[2] < -0.6 && c > 3) newc--; if (movesRemain > 0 && (newr != r || newc != c)) { InterpKeyPoint(dogs, s, newr, newc, grad, map, octSize, keys,movesRemain - 1,par); return; } /* Do not create a keypoint if interpolation still remains far outside expected limits, or if magnitude of peak value is below threshold (i.e., contrast is too low). */ if (fabs(offset[0]) > 1.5 || fabs(offset[1]) > 1.5 || fabs(offset[2]) > 1.5 || fabs(peakval) < par.PeakThresh) { if (DEBUG) printf("Point not well localized by FitQuadratic\n"); par.noncorrectlylocalized++; return; } /* Check that no keypoint has been created at this location (to avoid duplicates). Otherwise, mark this map location. */ if (*map.pixel(c,r)) return; *map.pixel(c,r) = true; /* The scale relative to this octave is given by octScale. The scale units are in terms of sigma for the smallest of the Gaussians in the DOG used to identify that scale. */ float octScale = par.InitSigma * pow(2.0f, (s + offset[0]) / (float) par.Scales); /// always use histogram of orientations //if (UseHistogramOri) AssignOriHist(grad, octSize, octScale, r + offset[1], c + offset[2], keys, par); //else // AssignOriAvg( // grad, ori, octSize, octScale, // r + offset[1], c + offset[2], keys); }