/* Use the parameters of this keypoint to sample the gradient images at a set of locations within a circular region around the keypoint. The (scale,row,col) values are relative to current octave sampling. The resulting vector is stored in the key. */ void MakeKeypointSample( keypoint& key, const flimage& grad, float scale, float row, float col,siftPar &par) { /* Produce sample vector. */ KeySampleVec(key, grad, scale, row, col,par); /* Normalize vector. This should provide illumination invariance for planar lambertian surfaces (except for saturation effects). Normalization also improves nearest-neighbor metric by increasing relative distance for vectors with few features. It is also useful to implement a distance threshold and to allow conversion to integer format. */ NormalizeVec(key.vec); /* Now that normalization has been done, threshold elements of index vector to decrease emphasis on large gradient magnitudes. Admittedly, the large magnitude values will have affected the normalization, and therefore the threshold, so this is of limited value. */ bool changed = false; for (int i = 0; i < VecLength; i++) if (key.vec[i] > par.MaxIndexVal) { key.vec[i] = par.MaxIndexVal; changed = true; } if (changed) NormalizeVec(key.vec); /* Convert float vector to integer. Assume largest value in normalized vector is likely to be less than 0.5. */ /// QUESTION: why is the vector quantized to integer int intval; for (int i = 0; i < VecLength; i++) { intval = static_cast<int>(512.0 * key.vec[i]); key.vec[i] = static_cast<float>(std::min(255, intval)); } }
/* Use the parameters of this keypoint to sample the gradient images at a set of locations within a circular region around the keypoint. The (scale,row,col) values are relative to current octave sampling. The resulting vector is stored in the key. */ void MakeKeypointSample(KKeypoint key, Image grad, Image ori, float scale, float row, float col) { int i, intval, changed = FALSE; float vec[VecLength]; /* Produce sample vector. */ KeySampleVec(vec, key, grad, ori, scale, row, col); /* Normalize vector. This should provide illumination invariance for planar lambertian surfaces (except for saturation effects). Normalization also improves nearest-neighbor metric by increasing relative distance for vectors with few features. */ NormalizeVec(vec, VecLength); /* Now that normalization has been done, threshold elements of index vector to decrease emphasis on large gradient magnitudes. Admittedly, the large magnitude values will have affected the normalization, and therefore the threshold, so this is of limited value. */ for (i = 0; i < VecLength; i++) if (vec[i] > MaxIndexVal) { vec[i] = MaxIndexVal; changed = TRUE; } if (changed) NormalizeVec(vec, VecLength); /* Convert float vector to integer. Assume largest value in normalized vector is likely to be less than 0.5. */ key->ivec = (unsigned char*) MallocPool(VecLength * sizeof(unsigned char), KEY_POOL); for (i = 0; i < VecLength; i++) { intval = (int) (512.0 * vec[i]); assert(intval >= 0); key->ivec[i] = (unsigned char) MIN_(255, intval); } }