MCPcopy Create free account
hub / github.com/colmap/colmap / BitmapToInputTensor

Function BitmapToInputTensor

src/colmap/feature/aliked.cc:56–77  ·  view source on GitHub ↗

Convert bitmap to row-major [C, H, W] float tensor, normalized to [0, 1].

Source from the content-addressed store, hash-verified

54
55// Convert bitmap to row-major [C, H, W] float tensor, normalized to [0, 1].
56std::vector<float> BitmapToInputTensor(const Bitmap& bitmap) {
57 THROW_CHECK(bitmap.IsRGB());
58
59 const int width = bitmap.Width();
60 const int height = bitmap.Height();
61 const int pitch = bitmap.Pitch();
62 const int num_pixels = width * height;
63
64 std::vector<float> input(num_pixels * 3);
65 const std::vector<uint8_t>& data = bitmap.RowMajorData();
66 for (int y = 0; y < height; ++y) {
67 for (int x = 0; x < width; ++x) {
68 for (int c = 0; c < 3; ++c) {
69 constexpr float kImageNormalization = 1.0f / 255.0f;
70 input[c * num_pixels + y * width + x] =
71 kImageNormalization * data[y * pitch + 3 * x + c];
72 }
73 }
74 }
75
76 return input;
77}
78
79// Pads image dimensions to be divisible by a given factor.
80struct InputPadder {

Callers 1

ExtractMethod · 0.85

Calls 4

IsRGBMethod · 0.80
PitchMethod · 0.80
WidthMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected