Spaces:
Paused
Paused
Download test_lighting_transfer.py from modventures/room-visualizer: direct link, hf CLI and curl.
- Browser
- Download file 2.77 kB
-
https://huggingface.co/spaces/modventures/room-visualizer/resolve/main/test_lighting_transfer.py
- Command line
-
hf download hf://spaces/modventures/room-visualizer/test_lighting_transfer.py
-
curl -L -o test_lighting_transfer.py https://huggingface.co/spaces/modventures/room-visualizer/resolve/main/test_lighting_transfer.py
2.77 kB
| import unittest | |
| import numpy as np | |
| from config.lighting import SHADE_MAP_MAX, SHADE_MAP_MIN | |
| from services.lighting.luminance import decode_relative_map | |
| from services.lighting.shading import build_luminance_lighting_maps | |
| class LuminanceLightingTransferTests(unittest.TestCase): | |
| def test_preserves_cast_shadow_and_broad_room_light(self): | |
| height, width = 180, 240 | |
| image = np.full((height, width, 3), 150, dtype=np.uint8) | |
| image[:, :80, :] = 60 | |
| image[:, 170:, :] = 215 | |
| surface_mask = np.ones((height, width), dtype=np.uint8) | |
| maps = build_luminance_lighting_maps(image, surface_mask) | |
| self.assertIsNotNone(maps) | |
| shade = decode_relative_map(maps["shadeMap"], SHADE_MAP_MIN, SHADE_MAP_MAX) | |
| dark = float(np.median(shade[:, 20:60])) | |
| neutral = float(np.median(shade[:, 105:135])) | |
| bright = float(np.median(shade[:, 190:225])) | |
| self.assertLess(dark, neutral * 0.60) | |
| self.assertGreater(bright, neutral * 1.03) | |
| def test_rejects_high_frequency_source_floor_pattern(self): | |
| height, width = 180, 240 | |
| image = np.full((height, width, 3), 165, dtype=np.uint8) | |
| image[:, :90, :] = 78 | |
| for x in range(0, width, 8): | |
| image[:, x:x + 2, :] = np.clip( | |
| image[:, x:x + 2, :].astype(np.int16) - 35, | |
| 0, | |
| 255, | |
| ).astype(np.uint8) | |
| surface_mask = np.ones((height, width), dtype=np.uint8) | |
| maps = build_luminance_lighting_maps(image, surface_mask) | |
| self.assertIsNotNone(maps) | |
| shade = decode_relative_map(maps["shadeMap"], SHADE_MAP_MIN, SHADE_MAP_MAX) | |
| broad_shadow_contrast = float( | |
| np.median(shade[:, 120:180]) - np.median(shade[:, 20:70]) | |
| ) | |
| pattern_contrast = float(np.mean(np.abs(np.diff(shade[:, 120:180], axis=1)))) | |
| self.assertGreater(broad_shadow_contrast, 0.20) | |
| self.assertLess(pattern_contrast, 0.04) | |
| def test_replaced_rug_appearance_is_inpainted(self): | |
| height, width = 180, 240 | |
| image = np.full((height, width, 3), 160, dtype=np.uint8) | |
| image[65:145, 75:175, :] = 45 | |
| surface_mask = np.ones((height, width), dtype=np.uint8) | |
| rug_mask = np.zeros((height, width), dtype=np.uint8) | |
| rug_mask[65:145, 75:175] = 1 | |
| maps = build_luminance_lighting_maps(image, surface_mask, rug_mask) | |
| self.assertIsNotNone(maps) | |
| shade = decode_relative_map(maps["shadeMap"], SHADE_MAP_MIN, SHADE_MAP_MAX) | |
| rug_value = float(np.median(shade[rug_mask > 0])) | |
| surrounding_value = float(np.median(shade[rug_mask == 0])) | |
| self.assertAlmostEqual(rug_value, surrounding_value, delta=0.12) | |
| if __name__ == "__main__": | |
| unittest.main() | |