In image-array arithmetic, converting pixel data to a wider type before a transformation can prevent 8-bit unsigned integer overflow. Convert back only after limiting values to the valid pixel range. section 4.2.3
Brightening an image
Doubling 8-bit pixel values can overflow without an obvious visual warning. Widen the array, multiply, cap values at 255, and cast back to uint8. section 4.2.3
brighter3_arr = image_arr.astype(np.uint16)
brighter3_arr = brighter3_arr * 2
print(brighter3_arr.max(), brighter3_arr.dtype)
brighter3_arr = np.minimum(brighter3_arr, 255) #1
print(brighter3_arr.max(), brighter3_arr.dtype)
brighter3_arr = brighter3_arr.astype(np.uint8)
print(brighter3_arr.max(), brighter3_arr.dtype)
Image.fromarray(brighter3_arr).save("brighter3.png")
The sequence widens pixel values to uint16, doubles them, clips them to 255, then converts them back to uint8. section 4.2.3




















