Skip to content

Commit 9371f7b

Browse files
authored
Preserve zero descriptors in RootSIFT normalization (colmap#4891)
L1-Root normalization turns an all-zero descriptor row into NaNs by dividing by its zero L1 norm. The bundled VLFeat descriptor code preserves zero histograms, including those computed from flat gradients, and the sibling L2 normalizer also keeps zero rows finite. Skip normalization for zero-norm rows. Positive rows retain the same arithmetic and byte-descriptor output. The change is in place and leaves descriptor shapes, storage formats and the default normalization choice unchanged. Validation: - All 12 native feature utility tests pass. The new mixed-row regression fails on pristine `main`; all 11 existing cases pass there. - A native probe using the bundled VLFeat implementation fails before the fix and passes afterward. Twelve positive/empty matrix controls preserve exact normalized values and bytes. - `clang-format --dry-run --Werror` passes both changed files. Local Clang-Tidy 23 reports the same five unchanged-header diagnostics on base and patch; upstream uses Clang 18. I ran a focused Windows native build, not a full application or GPU build. AI assistance disclosure: AI-assisted development tools were used during investigation and implementation. The reported tests were run against the final diff.
1 parent 15526bb commit 9371f7b

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎src/colmap/feature/utils.cc‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ void L2NormalizeFeatureDescriptors(FeatureDescriptorsFloatData* descriptors) {
2323
void L1RootNormalizeFeatureDescriptors(
2424
FeatureDescriptorsFloatData* descriptors) {
2525
for (Eigen::Index r = 0; r < descriptors->rows(); ++r) {
26-
descriptors->row(r) *= 1 / descriptors->row(r).lpNorm<1>();
27-
descriptors->row(r) = descriptors->row(r).array().sqrt();
26+
const float norm = descriptors->row(r).lpNorm<1>();
27+
if (norm > 0) {
28+
descriptors->row(r) *= 1 / norm;
29+
descriptors->row(r) = descriptors->row(r).array().sqrt();
30+
}
2831
}
2932
}
3033

‎src/colmap/feature/utils_test.cc‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ TEST(L1RootNormalizeFeatureDescriptors, Nominal) {
3838
}
3939
}
4040

41+
TEST(L1RootNormalizeFeatureDescriptors, ZeroRows) {
42+
FeatureDescriptorsFloatData descriptors =
43+
FeatureDescriptorsFloatData::Zero(3, 128);
44+
descriptors.row(1).setOnes();
45+
46+
L1RootNormalizeFeatureDescriptors(&descriptors);
47+
48+
EXPECT_TRUE(descriptors.allFinite());
49+
EXPECT_TRUE(descriptors.row(0).isZero());
50+
EXPECT_TRUE(descriptors.row(2).isZero());
51+
EXPECT_TRUE(descriptors.row(1).isApprox(
52+
FeatureDescriptorsFloatData::Constant(1, 128, std::sqrt(1.0f / 128))));
53+
}
54+
4155
TEST(FeatureDescriptorsToUnsignedByte, Nominal) {
4256
Eigen::MatrixXf descriptors = RandomEigenMatrixXf(100, 128);
4357
descriptors.array() += 1.0f;

0 commit comments

Comments
 (0)