I would like to implement a tool to adjust the brightness of a RGB image, which is simply a (N, M, 3)-shaped numpy array of dtype uint8
.
The algorithm is really simple, I'm just adding an integer in range [-255, 255]
to all pixels of my images.
Unfortunately, I also need to truncate the resulting pixel value to stay in range [0, 255], and numpy makes the array overflow when I'm adding the value.
Is there a way to add the brightness and take care of truncating the result without creating an intermediary array or using an ugly loop?
I'm working with large images, so I need to be efficient.