Do we have a function to invert gray image values?

yes ty, i tested it now, These two methods have the same result for the gray image but different results for the bgr image.
(1) bitwise_not
(2) 255 - img