Debian Codegraph @

src/pycolmap/mvs/normal_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, "NormalMap"),
8 reason="NormalMap not available",
9 )
10
11
12 def test_normal_map_default_init():
13 normal_map = pycolmap.NormalMap()
14 assert normal_map is not None
15
16
17 def test_normal_map_init_with_params():
18 normal_map = pycolmap.NormalMap(64, 48)
19 assert normal_map.width == 64
20 assert normal_map.height == 48
21
22
23 def test_normal_map_readonly_width():
24 normal_map = pycolmap.NormalMap(64, 48)
25 assert isinstance(normal_map.width, int)
26 assert normal_map.width == 64
27
28
29 def test_normal_map_readonly_height():
30 normal_map = pycolmap.NormalMap(64, 48)
31 assert isinstance(normal_map.height, int)
32 assert normal_map.height == 48
33
34
35 def test_normal_map_from_array_to_array_roundtrip():
36 array = np.random.rand(48, 64, 3).astype(np.float32)
37 normal_map = pycolmap.NormalMap.from_array(array)
38 result = normal_map.to_array()
39 np.testing.assert_array_almost_equal(array, result)
40
41
42 def test_normal_map_rescale():
43 normal_map = pycolmap.NormalMap(64, 48)
44 normal_map.rescale(0.5)
45 assert normal_map.width == 32
46 assert normal_map.height == 24
47
48
49 def test_normal_map_downsize():
50 normal_map = pycolmap.NormalMap(64, 48)
51 normal_map.downsize(32, 24)
52 assert normal_map.width <= 32
53 assert normal_map.height <= 24
54
55
56 def test_normal_map_to_bitmap():
57 array = np.random.rand(48, 64, 3).astype(np.float32)
58 normal_map = pycolmap.NormalMap.from_array(array)
59 bitmap = normal_map.to_bitmap()
60 assert bitmap is not None
61
62
63 def test_normal_map_write_read_roundtrip(tmp_path):
64 array = np.random.rand(48, 64, 3).astype(np.float32)
65 normal_map = pycolmap.NormalMap.from_array(array)
66 filepath = str(tmp_path / "normal.bin")
67 normal_map.write(filepath)
68 loaded = pycolmap.NormalMap()
69 loaded.read(filepath)
70 result = loaded.to_array()
71 np.testing.assert_array_almost_equal(array, result)