From 58c5648f76d73c66fc719a4abb00e862ba98a55b Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 15 Feb 2024 16:52:36 -0500 Subject: [PATCH] Guard against division by zero --- histomicstk/features/compute_fsd_features.py | 2 +- histomicstk/features/compute_haralick_features.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/histomicstk/features/compute_fsd_features.py b/histomicstk/features/compute_fsd_features.py index eb8bf9d85..a90b85477 100644 --- a/histomicstk/features/compute_fsd_features.py +++ b/histomicstk/features/compute_fsd_features.py @@ -186,7 +186,7 @@ def _FSDs(X, Y, K, Intervals): fX = np.fft.fft(Curvature).T # spectral energy fX = fX * fX.conj() - fX = fX / fX.sum() + fX = (fX / fX.sum()) if fX.sum() else 0 # calculate 'F' values for i in range(L - 1): F[i] = np.round( diff --git a/histomicstk/features/compute_haralick_features.py b/histomicstk/features/compute_haralick_features.py index 51c98589b..9368eba1a 100644 --- a/histomicstk/features/compute_haralick_features.py +++ b/histomicstk/features/compute_haralick_features.py @@ -370,7 +370,7 @@ def compute_haralick_features(im_label, im_intensity, offsets=None, pxy_ijr = np.ravel(pxy_ij) HXY1 = -np.dot(nGLCMr, np.log2(pxy_ijr + e)) HXY2 = -np.dot(pxy_ijr, np.log2(pxy_ijr + e)) - ldata.at[r, 'Haralick.IMC1'] = (HXY - HXY1) / max(HX, HY) + ldata.at[r, 'Haralick.IMC1'] = ((HXY - HXY1) / max(HX, HY)) if max(HX, HY) else 0 # computes information measures of correlation ldata.at[r, 'Haralick.IMC2'] = \