Spaces:
Paused
Paused
File size: 2,773 Bytes
dfec6e1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | 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()
|