Image Processing
Invert Image color / Invert Image lightness (python opencv)
민토즈
2020. 10. 8. 10:51
300x250
일반적인 Image Color의 반전
import cv2 src_bgr = cv2.imread("src.jpg", cv2.IMREAD_COLOR) # invert color (색반전) invert_img = cv2.bitwise_not(src_bgr) cv2.imshow("original image", src_bgr) cv2.imshow("inverted image", invert_img) |
이미지의 밝기만 반전 - 색상은 유지 (Invert only lmage lightness)
기본적인 색상은 유지하며, 밝기만 반전하는 코드
import cv2 src_bgr = cv2.imread("src.jpg", cv2.IMREAD_COLOR) // convert bgr to hls hls 모드로 변경 hls = cv2.cvtColor(src_bgr, cv2.COLOR_BGR2HLS) h, l, s = cv2.split(hls) // invert lightness - 밝기 반전 invert_lightness = cv2.bitwise_not(l) invert_hls = cv2.merge([h, invert_lightness, s]) invert_img = cv2.cvtColor(invert_hls, cv2.COLOR_HLS2BGR) cv2.imshow("inverted lightness", invert_img) cv2.waitKey(0) cv2.destoryAllWindows() |
300x250