diff --git a/tpat.py b/tpat.py index 73f1926..5533d8b 100644 --- a/tpat.py +++ b/tpat.py @@ -527,9 +527,9 @@ def save_8bit(image: npt.NDArray, bits: int, file_path: str) -> None: file_path (str): The output file path. """ if bits == 32: - image = (image * 255 + 0.5).astype(np.uint8) + image = np.clip(image * 255 + 0.5, 0, 255).astype(np.uint8) elif bits > 8: - image = (image * 255 / (2**bits - 1)).astype(np.uint8) + image = np.clip(image * 255 / (2**bits - 1), 0, 255).astype(np.uint8) iio.imwrite(file_path, image)