55 unsigned int* aBorderSize =
new unsigned int[
_maxScales];
57 unsigned int aMaxima = 0;
67 unsigned int aPixelStep = 1 << o;
68 int aOctaveWidth = iImage.
getWidth() / aPixelStep;
69 int aOctaveHeight = iImage.
getHeight() / aPixelStep;
81 int aEy = aOctaveHeight - aBorderSize[s];
82 int aEx = aOctaveWidth - aBorderSize[s];
84 int aYPS = aBorderSize[s] * aPixelStep;
85 for (
int y = aBorderSize[s]; y < aEy; ++y)
87 aBoxFilter.
setY(aYPS);
88 int aXPS = aBorderSize[s] * aPixelStep;
89 for (
int x = aBorderSize[s]; x < aEx; ++x)
99 for (
unsigned int aSIt = 1; aSIt < (_maxScales - 1); aSIt += 2)
101 const int aBS = aBorderSize[aSIt + 1];
102 for (
int aYIt = aBS + 1; aYIt < aOctaveHeight - aBS - 1; aYIt += 2)
104 for (
int aXIt = aBS + 1; aXIt < aOctaveWidth - aBS - 1; aXIt += 2)
110 aTab[0] = aSH[aSIt][aYIt][aXIt];
111 aTab[1] = aSH[aSIt][aYIt][aXIt + 1];
112 aTab[2] = aSH[aSIt][aYIt + 1][aXIt];
113 aTab[3] = aSH[aSIt][aYIt + 1][aXIt + 1];
114 aTab[4] = aSH[aSIt + 1][aYIt][aXIt];
115 aTab[5] = aSH[aSIt + 1][aYIt][aXIt + 1];
116 aTab[6] = aSH[aSIt + 1][aYIt + 1][aXIt];
117 aTab[7] = aSH[aSIt + 1][aYIt + 1][aXIt + 1];
120 unsigned int a04 = (aTab[0] > aTab[4] ? 0 : 4);
121 unsigned int a15 = (aTab[1] > aTab[5] ? 1 : 5);
122 unsigned int a26 = (aTab[2] > aTab[6] ? 2 : 6);
123 unsigned int a37 = (aTab[3] > aTab[7] ? 3 : 7);
124 unsigned int a0426 = (aTab[a04] > aTab[a26] ? a04 : a26);
125 unsigned int a1537 = (aTab[a15] > aTab[a37] ? a15 : a37);
126 unsigned int aMaxIdx = (aTab[a0426] > aTab[a1537] ? a0426 : a1537);
131 double aScore = aTab[aMaxIdx];
134 if (aScore < aApproxThres)
140 int aXShift = 2 * (aMaxIdx & 1) - 1;
141 int aXAdj = aXIt + (aMaxIdx & 1);
144 int aYShift = 2 * (aMaxIdx & 1) - 1;
145 int aYAdj = aYIt + (aMaxIdx & 1);
148 int aSShift = 2 * (aMaxIdx & 1) - 1;
149 int aSAdj = aSIt + (aMaxIdx & 1);
152 if (aSAdj == (
int)_maxScales - 1)
157 if ((aSH[aSAdj + aSShift][aYAdj - aYShift][aXAdj - 1] > aScore) ||
158 (aSH[aSAdj + aSShift][aYAdj - aYShift][aXAdj] > aScore) ||
159 (aSH[aSAdj + aSShift][aYAdj - aYShift][aXAdj + 1] > aScore) ||
160 (aSH[aSAdj + aSShift][aYAdj][aXAdj - 1] > aScore) ||
161 (aSH[aSAdj + aSShift][aYAdj][aXAdj] > aScore) ||
162 (aSH[aSAdj + aSShift][aYAdj][aXAdj + 1] > aScore) ||
163 (aSH[aSAdj + aSShift][aYAdj + aYShift][aXAdj - 1] > aScore) ||
164 (aSH[aSAdj + aSShift][aYAdj + aYShift][aXAdj] > aScore) ||
165 (aSH[aSAdj + aSShift][aYAdj + aYShift][aXAdj + 1] > aScore) ||
167 (aSH[aSAdj][aYAdj + aYShift][aXAdj - 1] > aScore) ||
168 (aSH[aSAdj][aYAdj + aYShift][aXAdj] > aScore) ||
169 (aSH[aSAdj][aYAdj + aYShift][aXAdj + 1] > aScore) ||
170 (aSH[aSAdj][aYAdj][aXAdj + aXShift] > aScore) ||
171 (aSH[aSAdj][aYAdj - aYShift][aXAdj + aXShift] > aScore) ||
173 (aSH[aSAdj - aSShift][aYAdj + aYShift][aXAdj - 1] > aScore) ||
174 (aSH[aSAdj - aSShift][aYAdj + aYShift][aXAdj] > aScore) ||
175 (aSH[aSAdj - aSShift][aYAdj + aYShift][aXAdj + 1] > aScore) ||
176 (aSH[aSAdj - aSShift][aYAdj][aXAdj + aXShift] > aScore) ||
177 (aSH[aSAdj - aSShift][aYAdj - aYShift][aXAdj + aXShift] > aScore)
188 if (aBorderSize[aSAdj + 1] > aBorderSize[aSAdj])
190 if (aX<aBorderSize[aSAdj + 1] || aX>aOctaveWidth - aBorderSize[aSAdj + 1] - 1)
194 if (aY<aBorderSize[aSAdj + 1] || aY>aOctaveHeight - aBorderSize[aSAdj + 1] - 1)
201 if (!
fineTuneExtrema(aSH, aXAdj, aYAdj, aSAdj, aX, aY, aS, aScore, aOctaveWidth, aOctaveHeight, aBorderSize[aSAdj + 1]))
225 if (!
calcTrace(iImage, aX, aY, aS, aTrace))
250 double& oX,
double& oY,
double& oS,
double& oScore,
251 unsigned int iOctaveWidth,
unsigned int iOctaveHeight,
unsigned int iBorder)
254 const unsigned int kMaxFineTuneIters = 6;
265 double aDx = 0, aDy = 0, aDs = 0;
270 for (
unsigned int aIter = 0; aIter < kMaxFineTuneIters; ++aIter)
280 aDx = (iSH[aS][aY][aX + 1] - iSH[aS][aY][aX - 1]) * 0.5;
281 aDy = (iSH[aS][aY + 1][aX] - iSH[aS][aY - 1][aX]) * 0.5;
282 aDs = (iSH[aS + 1][aY][aX] - iSH[aS - 1][aY][aX]) * 0.5;
289 aM[0][0] = iSH[aS][aY][aX - 1] - 2.0 * iSH[aS][aY][aX] + iSH[aS][aY][aX + 1];
290 aM[1][1] = iSH[aS][aY - 1][aX] - 2.0 * iSH[aS][aY][aX] + iSH[aS][aY + 1][aX];
291 aM[2][2] = iSH[aS - 1][aY][aX] - 2.0 * iSH[aS][aY][aX] + iSH[aS + 1][aY][aX];
293 aM[0][1] = aM[1][0] = (iSH[aS][aY + 1][aX + 1] + iSH[aS][aY - 1][aX - 1] - iSH[aS][aY + 1][aX - 1] - iSH[aS][aY - 1][aX + 1]) * 0.25;
294 aM[0][2] = aM[2][0] = (iSH[aS + 1][aY][aX + 1] + iSH[aS - 1][aY][aX - 1] - iSH[aS + 1][aY][aX - 1] - iSH[aS - 1][aY][aX + 1]) * 0.25;
295 aM[1][2] = aM[2][1] = (iSH[aS + 1][aY + 1][aX] + iSH[aS - 1][aY - 1][aX] - iSH[aS + 1][aY - 1][aX] - iSH[aS - 1][aY + 1][aX]) * 0.25;
306 if (aIter < kMaxFineTuneIters - 1)
311 if (aV[0] > 0.6 && aX < (
int)(iOctaveWidth - iBorder - 2))
315 else if (aV[0] < -0.6 && aX > (
int)iBorder + 1)
320 if (aV[1] > 0.6 && aY < (
int)(iOctaveHeight - iBorder - 2))
324 else if (aV[1] < -0.6 && aY > (
int)iBorder + 1)
329 if (aShiftX == 0 && aShiftY == 0)
337 oScore = iSH[aS][aY][aX] + 0.5 * (aDx * aV[0] + aDy * aV[1] + aDs * aV[2]);
340 if (std::abs(aV[0]) > 1.5 || std::abs(aV[1]) > 1.5 || std::abs(aV[2]) > 1.5)
355 unsigned int aScaleShift = 2 << iOctave;
361 unsigned int aScaleShift = 2 << iOctave;
364 unsigned int aMult = (iOctave == 0 ? 1 : 2);
365 return (
getFilterSize(iOctave, 1) + aMult * aScaleShift) * 3 / aScaleShift + 1;
388 oTrace = (aTrace <= 0.0 ? -1 : 1);
static bool SolveLinearSystem33(double *solution, double sq[3][3])
unsigned int getBorderSize(unsigned int iOctave, unsigned int iScale)
bool calcTrace(Image &iImage, double iX, double iY, double iScale, int &oTrace)
static double ** AllocateImage(unsigned int iWidth, unsigned int iHeight)
bool fineTuneExtrema(double ***iSH, unsigned int iX, unsigned int iY, unsigned int iS, double &oX, double &oY, double &oS, double &oScore, unsigned int iOctaveWidth, unsigned int iOctaveHeight, unsigned int iBorder)
double getDyyWithX(unsigned int x) const
unsigned int _scaleOverlap
unsigned int getFilterSize(unsigned int iOctave, unsigned int iScale)
double getDetWithX(unsigned int x) const
bool checkBounds(int x, int y) const
void setY(unsigned int y)
static const double kBaseSigma
double getDxxWithX(unsigned int x) const
static void DeallocateImage(double **iImagePtr, unsigned int iHeight)
unsigned int _initialBoxFilterSize
void detectKeypoints(Image &iImage, KeyPointInsertor &iInsertor)