image = cv2.imread('black.jpg')[:,:,0] # let's just take the red channel alone for brevity
print(image[75:85,155:165]) # print middle 10x10
# output: [[0,0,0,....],...]
I want subtract 1 from all pixel intensity. And yes, I definitely do not want 0s to become 255s. I just want them to stay as 0.
print(image[75:85,155:165]-1)
# output: [[255,255,255,....],...]
print(np.array(image[75:85,155:165])-1)
# output: [[255,255,255,....],...]
print(np.array(image[75:85,155:165], dtype='float32')-1)
# output: [[-1.,-1.,-1.,....],...]
I can convert the last one back to uint8
after .clip(0,255)
but that doesn't feel like the right way of doing it. Is there a way to directly do it (without casting and if conditions which might not be efficient for parallel processing)?