Skip to content

Commit c2966e8

Browse files
fix: Handle zero standard deviation in ZNCC computation by returning NaN
1 parent 4cef670 commit c2966e8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

karios/matcher/zncc_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def _zncc2(img1: NDArray, img2: NDArray, u1: int, v1: int, u2: int, v2: int, n:
116116
std2: float = float(np.std(patch2))
117117

118118
if std1 == 0 or std2 == 0:
119-
raise ValueError("Cannot compute ZNCC: one or both patches have zero standard deviation")
119+
logger.warning("One or both patches have zero standard deviation, returning NaN for ZNCC")
120+
return np.nan
120121

121122
# Normalize patches
122123
patch1_norm = (patch1 - np.mean(patch1)) / std1

0 commit comments

Comments
 (0)