之前我从没听说过SIFT,真的是从零开始,而且是一个人自学。看了很多文章,下面这两篇不错:
http://www.cnblogs.com/starfire86/p/5735061.html
http://www.cnblogs.com/JiePro/p/sift_1.html
有些理论看多了也还是似懂非懂,真正自己用代码试着去实现,就能发现算法的一些细节问题,然后能更好理解算法。
我尝试用c++描述SIFT的尺度空间。
const double sigma = 0.4;
const double S = 2;
const double k = pow(S, 1/S);
const int scaleSpaceO = 4;
const int scaleSpaceS = S +3;
double scaleSpaceSigma[scaleSpaceO][scaleSpaceS];
Mat scaleSpaceMats[scaleSpaceO][scaleSpaceS];
Mat currentOctaves, nextOctaves;
srcMat.copyTo(currentOctaves);
for (int o = 0; o < scaleSpaceO; o++)
{
for (int s = 0; s < scaleSpaceS; s++)
{
///计算每个octave下高斯模糊的系数
scaleSpaceSigma[o][s] = sigma * pow(k, s);
Mat gaussKernel = getGaussianKernel(7, scaleSpaceSigma[o][s]);
scaleSpaceMats[o][s].create(currentOctaves.size(), currentOctaves.type());
///高斯模糊
filter2D(currentOctaves, scaleSpaceMats[o][s], currentOctaves.depth(), gaussKernel);
}
///把当前octave下的倒数第三曾的图像作为下一个octave的待处理图像
scaleSpaceMats[o][scaleSpaceS - 2].copyTo(currentOctaves);
/// 对其进行降采样
nextOctaves.create(currentOctaves.rows / 2 , currentOctaves.cols / 2, currentOctaves.type());
for (int x = 0; x < currentOctaves.cols; x += 2)
for (int y = 0; y < currentOctaves.rows; y += 2)
{
nextOctaves.at<uchar>(y / 2, x / 2 ) = currentOctaves.at<uchar>(y, x);
}
///降采样厚的图像作为下一个octave的原始图像
nextOctaves.copyTo(currentOctaves);
}