Skip to content

Commit 882fd06

Browse files
minor modification/bug fix: zero length normals of the "classical" approach are now no longer an issue
This can happen on patterns like [[[0 1], [0 1]],[[1, 0], [1,0]]] and alike (i.e. room-diagonals differing from the remaining values)
1 parent 9da7b58 commit 882fd06

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/supervoxel.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def supervoxel_normal(img, lap_img, l, vol_frac=None):
7171
assert(img.ndim == 3),'error: expecting 3D ndarray (0--> phase 0; else-->phase 1)'
7272
N = np.array(img.shape) # size of the supervoxel
7373
l_combi = l*np.array(img.shape) # edge lengths of the supervoxel
74+
TOL_l = 1e-8*l_combi.mean() # tolerance
7475
# assemble and solve the least squares problem
7576
w = np.abs(lap_img) # weights
7677
iface = np.where(w > 1e-5) # find the interface voxels
@@ -112,7 +113,17 @@ def supervoxel_normal(img, lap_img, l, vol_frac=None):
112113
normal_xyz *= -1.
113114

114115
normal_classic = np.array([x1_c, y1_c, z1_c])
115-
normal_classic = -normal_classic / inline_norm(normal_classic)
116+
l_classic = inline_norm(normal_classic)
117+
if(l_classic<TOL_l):
118+
print(normal_classic, l_classic)
119+
print(img.shape)
120+
if(img.size < 100):
121+
print(img)
122+
print('combo normal: ',normal_xyz)
123+
l_classic = 1.
124+
normal_classic = np.array([1.,0.,0.])
125+
else:
126+
normal_classic = -normal_classic / l_classic
116127
return normal_xyz, normal_classic
117128

118129

0 commit comments

Comments
 (0)