I have an 640x480 RGB image with numpy shape (480, 640, 3) -- 3 for the R, G, B channels and I would like to at each pixel, transform the RGB value according to:
# for each pixel
for i in range(img.shape[0]):
for j in range(img.shape[1]):
# set the new RGB value at that pixel to
# (new RGB vector) = (const matrix A) * (old RGB vector) + (const vector B)
img[i,j,:] = np.reshape((np.matmul(A, np.expand_dims(img[i,j,:], axis = 1)) + B), (3,))
Where A is of shape (3,3) and B is of shape (3,1). How do I do this with numpy without writing a loop over the pixels?