Debian Codegraph @

src/pycolmap/mvs/depth_map_test.py

raw
1 import numpy as np
2 import pytest
3
4 import pycolmap
5
6 pytestmark = pytest.mark.skipif(
7 not hasattr(pycolmap, "DepthMap"),
8 reason="DepthMap not available",
9 )
10
11
12 def test_depth_map_default_init():
13 depth_map = pycolmap.DepthMap()
14 assert depth_map is not None
15
16
17 def test_depth_map_init_with_params():
18 depth_map = pycolmap.DepthMap(64, 48, 0.1, 100.0)
19 assert depth_map.width == 64
20 assert depth_map.height == 48
21 assert depth_map.depth_min == pytest.approx(0.1)
22 assert depth_map.depth_max == pytest.approx(100.0)
23
24
25 def test_depth_map_readonly_width():
26 depth_map = pycolmap.DepthMap(64, 48, 0.1, 100.0)
27 assert isinstance(depth_map.width, int)
28 assert depth_map.width == 64
29
30
31 def test_depth_map_readonly_height():
32 depth_map = pycolmap.DepthMap(64, 48, 0.1, 100.0)
33 assert isinstance(depth_map.height, int)
34 assert depth_map.height == 48
35
36
37 def test_depth_map_readonly_depth_min():
38 depth_map = pycolmap.DepthMap(64, 48, 0.5, 50.0)
39 assert isinstance(depth_map.depth_min, float)
40 assert depth_map.depth_min == pytest.approx(0.5)
41
42
43 def test_depth_map_readonly_depth_max():
44 depth_map = pycolmap.DepthMap(64, 48, 0.5, 50.0)
45 assert isinstance(depth_map.depth_max, float)
46 assert depth_map.depth_max == pytest.approx(50.0)
47
48
49 def test_depth_map_from_array_to_array_roundtrip():
50 array = np.random.rand(48, 64).astype(np.float32)
51 depth_map = pycolmap.DepthMap.from_array(
52 array, depth_min=0.1, depth_max=10.0
53 )
54 result = depth_map.to_array()
55 np.testing.assert_array_almost_equal(array, result)
56
57
58 def test_depth_map_rescale():
59 depth_map = pycolmap.DepthMap(64, 48, 0.1, 100.0)
60 depth_map.rescale(0.5)
61 assert depth_map.width == 32
62 assert depth_map.height == 24
63
64
65 def test_depth_map_downsize():
66 depth_map = pycolmap.DepthMap(64, 48, 0.1, 100.0)
67 depth_map.downsize(32, 24)
68 assert depth_map.width == 32
69 assert depth_map.height == 24
70
71
72 def test_depth_map_to_bitmap():
73 array = np.random.rand(48, 64).astype(np.float32)
74 depth_map = pycolmap.DepthMap.from_array(
75 array, depth_min=0.0, depth_max=1.0
76 )
77 bitmap = depth_map.to_bitmap(5.0, 95.0)
78 assert bitmap is not None
79
80
81 def test_depth_map_write_read_roundtrip(tmp_path):
82 array = np.random.rand(48, 64).astype(np.float32)
83 depth_map = pycolmap.DepthMap.from_array(
84 array, depth_min=0.1, depth_max=10.0
85 )
86 filepath = str(tmp_path / "depth.bin")
87 depth_map.write(filepath)
88 loaded = pycolmap.DepthMap()
89 loaded.read(filepath)
90 result = loaded.to_array()
91 np.testing.assert_array_almost_equal(array, result)