The purpose is to review
Import CV2 Import numpy NP AS # grayscale inversion DEF grayReversal (Gray): gray_reversal = 255 - Gray # grayscale inversion return gray_reversal # color image reversal DEF imgReversal (IMG): img_reversal = np.zeros (IMG. Shape, np.uint8) # initial template for I in Range (img.shape [0]): for J in Range (img.shape [. 1 ]): B, G, R & lt = IMG [I, J] # note is bgr, not RGB img_reversal [I, J] = 255 - B, 255 - G, 255 - R & lt return img_reversal # logarithmic transformation DEF logTrans (Gray, C): gray_log = np.uint8 ((np.log C * (1.0 + Gray))) return gray_log # power law (gamma) conversion DEF PowerTrans (Gray, C, Y): gray_power = np.uint8 (C * (Gray ** Y)) return gray_power path = " _kdy.jpg " IMG = cv2.imread (path) Gray = cv2.cvtColor (IMG, cv2.COLOR_BGR2GRAY) # is converted to grayscale gray_reversal = grayReversal (Gray) img_reversal = imgReversal (IMG) gray_log= logTrans(gray, c=30) gray_power = powerTrans(gray, c=30, y =0.35) cv2.imshow("img", img) cv2.imshow("gray", gray) cv2.imshow("gray_reversal", gray_reversal) cv2.imshow("img_reversal", img_reversal) cv2.imshow("gray_log", gray_log) cv2.imshow("gray_power", gray_power) cv2.waitKey(0)
(FIG picture respectively, grayscale, FIG gradation inversion, FIG logarithmic transformation, power law (gamma) conversion FIG)