HSV变换 — OpenCV& Python

import cv2

img_path = 'C:/Users/WZChan/Desktop/'
img = cv2.imread(img_path + 'tree.jpg')
img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
turn_green_hsv = img_hsv.copy()
turn_green_hsv[:, :, 0] = (turn_green_hsv[:, :, 0] + 15) % 180
turn_green_img = cv2.cvtColor(turn_green_hsv, cv2.COLOR_HSV2BGR)
cv2.imwrite(img_path + 'turn_green.jpg', turn_green_img)

colorless_hsv = img_hsv.copy()
colorless_hsv[:, :, 2] = 0.5 * colorless_hsv[:, :, 1]
colorless_img = cv2.cvtColor(colorless_hsv, cv2.COLOR_HSV2BGR)
cv2.imwrite(img_path + 'colorless.jpg', colorless_img)

darker_hsv = img_hsv.copy()
darker_hsv[:, :, 2] = 0.5 * darker_hsv[:, :, 2]
darker_img = cv2.cvtColor(darker_hsv, cv2.COLOR_HSV2BGR)
cv2.imwrite(img_path + 'darker.jpg', darker_img)
HSV变换 — OpenCV& Python_第1张图片
tree.jpg
HSV变换 — OpenCV& Python_第2张图片
turn_green.jpg
HSV变换 — OpenCV& Python_第3张图片
colorless.jpg
HSV变换 — OpenCV& Python_第4张图片
darker.jpg

你可能感兴趣的:(HSV变换 — OpenCV& Python)