Skip to content

Commit

Permalink
Avoid dividing by zero when writing a blank image
Browse files Browse the repository at this point in the history
  • Loading branch information
yut23 committed Sep 27, 2023
1 parent 3760d58 commit ed3bdac
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions yt/visualization/image_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def write_bitmap(bitmap_array, filename, max_val=None, transpose=False):
alpha_channel.shape = s1, s2, 1
if max_val is None:
max_val = bitmap_array[:, :, :3].max()
if max_val == 0.0:
# avoid dividing by zero for blank images
max_val = 1.0
bitmap_array = np.clip(bitmap_array[:, :, :3] / max_val, 0.0, 1.0) * 255
bitmap_array = np.concatenate(
[bitmap_array.astype("uint8"), alpha_channel], axis=-1
Expand Down

0 comments on commit ed3bdac

Please sign in to comment.