jboth commited on
Commit
56e808f
·
verified ·
1 Parent(s): e0de0ec

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -95,7 +95,41 @@ try:
95
  edge = edge & mask
96
  return edge
97
  _u3d_np.depth_edge = _depth_edge
98
- print("Injected depth_edge into utils3d.numpy")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  except Exception as e:
100
  print(f"depth_edge patch skipped: {e}")
101
 
 
95
  edge = edge & mask
96
  return edge
97
  _u3d_np.depth_edge = _depth_edge
98
+
99
+ def _normals_edge(normals, tol=0.1, mask=None):
100
+ """Detect normal discontinuities."""
101
+ import numpy as _np
102
+ from scipy.ndimage import sobel
103
+ # Compute gradient of each normal component
104
+ edges = _np.zeros(normals.shape[:2], dtype=bool)
105
+ for c in range(normals.shape[-1]):
106
+ ch = normals[..., c]
107
+ if mask is not None:
108
+ ch = _np.where(mask, ch, 0.0)
109
+ gx = sobel(ch, axis=1)
110
+ gy = sobel(ch, axis=0)
111
+ grad = _np.sqrt(gx**2 + gy**2)
112
+ edges |= (grad > tol)
113
+ if mask is not None:
114
+ edges = edges & mask
115
+ return edges
116
+ _u3d_np.normals_edge = _normals_edge
117
+
118
+ # Also inject a catch-all __getattr__ for any future missing functions
119
+ _orig_getattr = getattr(_u3d_np, '__getattr__', None)
120
+ def _u3d_catchall(name):
121
+ if name.startswith('__') and name.endswith('__'):
122
+ raise AttributeError(name)
123
+ import warnings
124
+ warnings.warn(f"utils3d.numpy stub: {name} not implemented, returning dummy")
125
+ def _dummy(*a, **kw):
126
+ import numpy as _np
127
+ return _np.zeros(1)
128
+ return _dummy
129
+ import types
130
+ _u3d_np.__getattr__ = _u3d_catchall
131
+
132
+ print("Injected depth_edge + normals_edge + catch-all into utils3d.numpy")
133
  except Exception as e:
134
  print(f"depth_edge patch skipped: {e}")
135