for i in range(x, x + width): for j in range(y, y + height): # Invert pixel values (assuming 3 channels - BGR) image[j, i] = 255 - image[j, i]