Skip to content

Commit 138119b

Browse files
aswanth-07sarlinpe
andauthored
Keep thin bitmap thumbnails nonempty (colmap#4927)
`Bitmap::Thumbnail` rounds both scaled dimensions to the nearest integer. When a nonempty image is much thinner than its long side, the short side rounds to zero. For example, thumbnailing a 100x1 image to maximum size 10 currently produces an empty 10x0 bitmap. Feature extraction delegates its downscaling to this method. Keep each target dimension at least one pixel. Ordinary thumbnail dimensions, the returned scale, no-upscale behavior and both existing resize filters stay unchanged. The new native regression covers portrait and landscape inputs, grayscale and RGB, both filters, constant pixel values and a repeated thumbnail call. It fails on pristine main and passes with the fix. All 89 bitmap tests pass with MSVC Release and the existing OpenImageIO dependency; all 88 original cases also pass against pristine production. Clang-format and whitespace checks pass. Local Clang-Tidy reports the same six pre-existing source/header diagnostics on base and patch, with none in the changed method. I did not run the full feature-extraction controller, reconstruction datasets, GPU builds or other operating systems locally. AI assistance disclosure: AI-assisted development tools were used during investigation and implementation. The reported tests were run against the final diff. --------- Co-authored-by: Paul-Edouard Sarlin <[email protected]>
1 parent f664d5d commit 138119b

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/colmap/sensor/bitmap.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ double Bitmap::Thumbnail(const int max_image_size, RescaleFilter filter) {
588588
// Fit the down-sampled version exactly into the max dimensions.
589589
const double scale =
590590
static_cast<double>(max_image_size) / std::max(width_, height_);
591-
Rescale(static_cast<int>(std::round(width_ * scale)),
592-
static_cast<int>(std::round(height_ * scale)),
591+
Rescale(std::max(1, static_cast<int>(std::round(width_ * scale))),
592+
std::max(1, static_cast<int>(std::round(height_ * scale))),
593593
filter);
594594
return scale;
595595
}

‎src/colmap/sensor/bitmap_test.cc‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,18 @@ TEST(Bitmap, Thumbnail) {
485485
non_integer.Thumbnail(/*max_image_size=*/100);
486486
EXPECT_EQ(non_integer.Width(), 100);
487487
EXPECT_EQ(non_integer.Height(), 67);
488+
489+
// Thin images: the short side is clamped to at least 1 pixel instead of
490+
// rounding to 0.
491+
Bitmap thin_landscape(100, 1, /*as_rgb=*/true);
492+
EXPECT_DOUBLE_EQ(thin_landscape.Thumbnail(/*max_image_size=*/10), 0.1);
493+
EXPECT_EQ(thin_landscape.Width(), 10);
494+
EXPECT_EQ(thin_landscape.Height(), 1);
495+
496+
Bitmap thin_portrait(1, 100, /*as_rgb=*/true);
497+
EXPECT_DOUBLE_EQ(thin_portrait.Thumbnail(/*max_image_size=*/10), 0.1);
498+
EXPECT_EQ(thin_portrait.Width(), 1);
499+
EXPECT_EQ(thin_portrait.Height(), 10);
488500
}
489501

490502
TEST(Bitmap, ThumbnailNoOp) {

0 commit comments

Comments
 (0)