Skip to content

Commit

Permalink
Guard against division by zero (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Feb 16, 2024
1 parent 8e6be49 commit b0b1242
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion histomicstk/features/compute_fsd_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion histomicstk/features/compute_haralick_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = \
Expand Down

0 comments on commit b0b1242

Please sign in to comment.