Skip to content

Commit

Permalink
fix: normalization to prevent divison-by-zero (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbmrz authored Jan 22, 2025
1 parent 7529260 commit c188d97
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion depthai_nodes/ml/parsers/utils/denormalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ def unnormalize_image(image, normalize=True):
"""
# Normalize the image tensor to the range [0, 1]
if normalize:
image = (image - image.min()) / (image.max() - image.min())
min_val = image.min()
max_val = image.max()
if max_val != min_val:
image = (image - min_val) / (max_val - min_val)
else:
# Handle the case where all values in the image are the same
image = image - min_val

# Scale to [0, 255] and clip the values to be in the proper range
image = image * 255.0
Expand Down

0 comments on commit c188d97

Please sign in to comment.