github-actions[bot] commited on
Commit
7ef7332
·
1 Parent(s): bc8e40d

Automated Deploy: 1faf5c0e857074815809a1f118fb66bc02e2e0fd

Browse files
Files changed (2) hide show
  1. app.py +27 -29
  2. test_floor_geometry.py +18 -2
app.py CHANGED
@@ -365,8 +365,10 @@ SHADE_MAP_MIN = 0.35
365
  SHADE_MAP_MAX = 1.85
366
  SHOWROOM_SHADE_MAP_MIN = 0.85
367
  SHOWROOM_SHADE_MAP_MAX = 1.12
368
- REFLECTION_RELATIVE_FLOOR = 1.04
369
- REFLECTION_RELATIVE_CEILING = 1.95
 
 
370
 
371
 
372
  def hf_offline() -> bool:
@@ -880,7 +882,7 @@ def build_showroom_shade_map_from_luminance(
880
  return build_showroom_shade_map_from_relative(relative, surface_mask)
881
 
882
 
883
- def build_reflection_map(
884
  img_np: np.ndarray,
885
  surface_mask: np.ndarray,
886
  relative_shading: np.ndarray | None = None,
@@ -890,7 +892,7 @@ def build_reflection_map(
890
 
891
  mask = surface_mask.astype(np.uint8)
892
  h, w = mask.shape[:2]
893
- highlight = np.zeros((h, w), dtype=np.float32)
894
 
895
  if relative_shading is not None:
896
  rel = relative_shading.astype(np.float32).copy()
@@ -898,11 +900,7 @@ def build_reflection_map(
898
  broad_sigma = max(6.0, min(h, w) / 44.0)
899
  broad = cv2.GaussianBlur(rel, (0, 0), sigmaX=broad_sigma, sigmaY=broad_sigma)
900
  detail = rel / np.maximum(broad, 1e-3)
901
- highlight = np.maximum(
902
- highlight,
903
- (detail - REFLECTION_RELATIVE_FLOOR)
904
- / max(REFLECTION_RELATIVE_CEILING - REFLECTION_RELATIVE_FLOOR, 1e-6),
905
- )
906
 
907
  luminance = image_luminance(img_np) / 255.0
908
  floor_values = luminance[mask > 0]
@@ -915,21 +913,21 @@ def build_reflection_map(
915
  broad_sigma = max(8.0, min(h, w) / 36.0)
916
  broad = cv2.GaussianBlur(filled, (0, 0), sigmaX=broad_sigma, sigmaY=broad_sigma)
917
  detail = filled / np.maximum(broad, 1e-3)
918
- highlight = np.maximum(
919
- highlight,
920
- 0.75
921
- * (detail - (REFLECTION_RELATIVE_FLOOR + 0.04))
922
- / max(REFLECTION_RELATIVE_CEILING - REFLECTION_RELATIVE_FLOOR, 1e-6),
923
- )
924
-
925
- highlight = np.clip(highlight, 0.0, 1.0)
926
- if min(h, w) > 120:
927
- sigma = max(0.6, min(h, w) / 520.0)
928
- highlight = cv2.GaussianBlur(highlight, (0, 0), sigmaX=sigma, sigmaY=sigma)
929
- highlight[mask == 0] = 0.0
930
- if float(np.max(highlight[mask > 0])) < 0.025:
931
- return None
932
- return np.round(highlight * 255.0).clip(0, 255).astype(np.uint8)
933
 
934
 
935
  def build_luminance_lighting_maps(
@@ -2945,14 +2943,14 @@ def build_segmentation_bundle(contents: bytes):
2945
  "lightingSource": lighting_source,
2946
  "shadeMapRange": [SHADE_MAP_MIN, SHADE_MAP_MAX],
2947
  "showroomShadeMapRange": [SHOWROOM_SHADE_MAP_MIN, SHOWROOM_SHADE_MAP_MAX],
2948
- "renderPresetDefaults": {
2949
- "preset": "showroom",
2950
- "shadingStrength": 0.08,
2951
- "reflectionTransfer": False,
2952
  "edgeFeatherPixels": 2,
2953
  },
2954
  "reflectionTransferEnabled": reflection_map is not None,
2955
- "reflectionMapRange": [0.0, 1.0],
2956
  "geometryConfidence": plane.get("geometryConfidence", 0.0) if plane else 0.0,
2957
  "metricGeometry": bool(plane and plane.get("floorTransform")),
2958
  "geometryProvider": plane.get("geometryProvider", geometry.get("provider")) if plane else geometry.get("provider"),
 
365
  SHADE_MAP_MAX = 1.85
366
  SHOWROOM_SHADE_MAP_MIN = 0.85
367
  SHOWROOM_SHADE_MAP_MAX = 1.12
368
+ REFLECTION_RELATIVE_FLOOR = 1.04
369
+ REFLECTION_RELATIVE_CEILING = 1.95
370
+ REFLECTION_MAP_MIN = -1.0
371
+ REFLECTION_MAP_MAX = 1.0
372
 
373
 
374
  def hf_offline() -> bool:
 
882
  return build_showroom_shade_map_from_relative(relative, surface_mask)
883
 
884
 
885
+ def build_reflection_map(
886
  img_np: np.ndarray,
887
  surface_mask: np.ndarray,
888
  relative_shading: np.ndarray | None = None,
 
892
 
893
  mask = surface_mask.astype(np.uint8)
894
  h, w = mask.shape[:2]
895
+ reflection_candidates: list[np.ndarray] = []
896
 
897
  if relative_shading is not None:
898
  rel = relative_shading.astype(np.float32).copy()
 
900
  broad_sigma = max(6.0, min(h, w) / 44.0)
901
  broad = cv2.GaussianBlur(rel, (0, 0), sigmaX=broad_sigma, sigmaY=broad_sigma)
902
  detail = rel / np.maximum(broad, 1e-3)
903
+ reflection_candidates.append(np.clip((detail - 1.0) / 0.35, -1.0, 1.0))
 
 
 
 
904
 
905
  luminance = image_luminance(img_np) / 255.0
906
  floor_values = luminance[mask > 0]
 
913
  broad_sigma = max(8.0, min(h, w) / 36.0)
914
  broad = cv2.GaussianBlur(filled, (0, 0), sigmaX=broad_sigma, sigmaY=broad_sigma)
915
  detail = filled / np.maximum(broad, 1e-3)
916
+ reflection_candidates.append(np.clip((detail - 1.0) / 0.35, -1.0, 1.0))
917
+
918
+ if not reflection_candidates:
919
+ return None
920
+
921
+ reflection = np.mean(reflection_candidates, axis=0).astype(np.float32)
922
+ if min(h, w) > 120:
923
+ sigma = max(0.6, min(h, w) / 520.0)
924
+ reflection = cv2.GaussianBlur(reflection, (0, 0), sigmaX=sigma, sigmaY=sigma)
925
+ reflection = np.clip(reflection, REFLECTION_MAP_MIN, REFLECTION_MAP_MAX)
926
+ reflection[mask == 0] = 0.0
927
+ if float(np.max(np.abs(reflection[mask > 0]))) < 0.025:
928
+ return None
929
+ encoded = (reflection - REFLECTION_MAP_MIN) / (REFLECTION_MAP_MAX - REFLECTION_MAP_MIN)
930
+ return np.round(encoded * 255.0).clip(0, 255).astype(np.uint8)
931
 
932
 
933
  def build_luminance_lighting_maps(
 
2943
  "lightingSource": lighting_source,
2944
  "shadeMapRange": [SHADE_MAP_MIN, SHADE_MAP_MAX],
2945
  "showroomShadeMapRange": [SHOWROOM_SHADE_MAP_MIN, SHOWROOM_SHADE_MAP_MAX],
2946
+ "renderPresetDefaults": {
2947
+ "preset": "realistic",
2948
+ "shadingStrength": 0.95,
2949
+ "reflectionTransfer": True,
2950
  "edgeFeatherPixels": 2,
2951
  },
2952
  "reflectionTransferEnabled": reflection_map is not None,
2953
+ "reflectionMapRange": [REFLECTION_MAP_MIN, REFLECTION_MAP_MAX],
2954
  "geometryConfidence": plane.get("geometryConfidence", 0.0) if plane else 0.0,
2955
  "metricGeometry": bool(plane and plane.get("floorTransform")),
2956
  "geometryProvider": plane.get("geometryProvider", geometry.get("provider")) if plane else geometry.get("provider"),
test_floor_geometry.py CHANGED
@@ -66,7 +66,7 @@ class MetricFloorGeometryTests(unittest.TestCase):
66
  self.assertIn("normalMap", second["maps"])
67
  self.assertTrue(second["maps"]["normalMap"].endswith("/normal.png"))
68
 
69
- def test_showroom_shade_map_clamps_harsh_floor_shadow(self):
70
  height, width = 96, 128
71
  image = np.full((height, width, 3), 180, dtype=np.uint8)
72
  image[34:70, 46:82, :] = 45
@@ -84,7 +84,23 @@ class MetricFloorGeometryTests(unittest.TestCase):
84
  )
85
  self.assertGreaterEqual(float(decoded.min()), app.SHOWROOM_SHADE_MAP_MIN)
86
  self.assertLessEqual(float(decoded.max()), app.SHOWROOM_SHADE_MAP_MAX)
87
- self.assertGreater(float(decoded[52, 64]), 0.90)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  def test_surface_uv_quality_keeps_smooth_complete_uvs(self):
90
  height, width = 60, 80
 
66
  self.assertIn("normalMap", second["maps"])
67
  self.assertTrue(second["maps"]["normalMap"].endswith("/normal.png"))
68
 
69
+ def test_showroom_shade_map_clamps_harsh_floor_shadow(self):
70
  height, width = 96, 128
71
  image = np.full((height, width, 3), 180, dtype=np.uint8)
72
  image[34:70, 46:82, :] = 45
 
84
  )
85
  self.assertGreaterEqual(float(decoded.min()), app.SHOWROOM_SHADE_MAP_MIN)
86
  self.assertLessEqual(float(decoded.max()), app.SHOWROOM_SHADE_MAP_MAX)
87
+ self.assertGreater(float(decoded[52, 64]), 0.90)
88
+
89
+ def test_reflection_map_preserves_dark_and_bright_contrast(self):
90
+ height, width = 128, 160
91
+ image = np.full((height, width, 3), 128, dtype=np.uint8)
92
+ image[42:86, 28:68, :] = 52
93
+ image[42:86, 92:132, :] = 218
94
+ mask = np.ones((height, width), dtype=np.uint8)
95
+
96
+ reflection = app.build_reflection_map(image, mask)
97
+
98
+ self.assertIsNotNone(reflection)
99
+ decoded = app.REFLECTION_MAP_MIN + (reflection.astype(np.float32) / 255.0) * (
100
+ app.REFLECTION_MAP_MAX - app.REFLECTION_MAP_MIN
101
+ )
102
+ self.assertLess(float(decoded[64, 48]), 0.0)
103
+ self.assertGreater(float(decoded[64, 112]), 0.0)
104
 
105
  def test_surface_uv_quality_keeps_smooth_complete_uvs(self):
106
  height, width = 60, 80