self_example/TensorFlow_eaxmple/OpenCV_try/图像色彩的随机变换.py

14 lines
665 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import cv2
import numpy as np
import random
img=cv2.imread('lena.jpg')
img_hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
turn_green_hsv=img_hsv.copy()
'''等式左边的参数方括号中第一个和第二个参数分别代表图像矩阵的坐标第三个参数代表HSV的选择0指的是色调1指的是饱和度2指的是明暗度'''
turn_green_hsv[:,:,0]=(turn_green_hsv[:,:,0]+np.random.random())%180
turn_green_hsv[:,:,1]=(turn_green_hsv[:,:,1]+np.random.random())%180
turn_green_hsv[:,:,2]=(turn_green_hsv[:,:,2]+np.random.random())%180
turn_green_img=cv2.cvtColor(turn_green_hsv,cv2.COLOR_HSV2BGR)
cv2.imshow("test",turn_green_img)
cv2.waitKey(0)