Do we have a function to invert gray image values?

did you even try that?

look at the cat’s chest, or any other dark region. that’s what happens when your method inverts black… arbitrary colors, but light instead of dark.

>>> im = cv.imread("cat.jpg")
>>> hsv = cv.cvtColor(im, cv.COLOR_BGR2HSV)
>>> hsv[:,:,2] = 255 - hsv[:,:,2]
>>> cv.imshow("wat", cv.cvtColor(hsv, cv.COLOR_HSV2BGR)); cv.waitKey()

output:

source: