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

Function BitmapFromArray

src/pycolmap/sensor/bitmap.cc:39–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39Bitmap BitmapFromArray(py::array_t<uint8_t, py::array::c_style> array,
40 bool linear_colorspace) {
41 int channels = 1;
42 if (array.ndim() == 3) {
43 channels = array.shape(2);
44 } else if (array.ndim() != 2) {
45 throw std::runtime_error("Input array must have 2 or 3 dimensions!");
46 }
47
48 const int width = array.shape(1);
49 const int height = array.shape(0);
50 if (width == 0 || height == 0) {
51 throw std::runtime_error(
52 "Input array must have positive width and height!");
53 }
54
55 if (channels != 1 && channels != 3) {
56 throw std::runtime_error("Input array must have 1 or 3 channels!");
57 }
58
59 const bool as_rgb = channels != 1;
60 Bitmap output(width,
61 height,
62 /*as_rgb=*/as_rgb,
63 /*linear_colorspace=*/linear_colorspace);
64
65 const uint8_t* input_row_ptr = static_cast<uint8_t*>(array.request().ptr);
66 std::memcpy(output.RowMajorData().data(), input_row_ptr, output.NumBytes());
67 return output;
68}
69
70void BindBitmap(pybind11::module& m) {
71 using BitmapRescaleFilter = Bitmap::RescaleFilter;

Callers 1

BindFeatureExtractionFunction · 0.85

Calls 1

NumBytesMethod · 0.45

Tested by

no test coverage detected