图像处理中图像色彩的随机变换

在图像的随机变换中,使用cvtCOLOR()h函数实现图像色彩的变换。
实例代码:
import numpy as np
import cv2
import matplotlib.pyplot as plt

img = cv2.imread(“C:\lena.jpg”)
plt.subplot(2,3,1)
plt.imshow(img)
img_bgr_hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
plt.subplot(2,3,2)
plt.imshow(img_bgr_hsv)
img_bgr_hsv_copy = img_bgr_hsv.copy()
img_bgr_hsv_copy[:,:,0] = (img_bgr_hsv_copy[:,:,0]+np.random.random()) % 180
plt.subplot(2,3,3)
plt.imshow(img_bgr_hsv_copy)
img_bgr_hsv_copy[:,:,1] = (img_bgr_hsv_copy[:,:,1]+np.random.random()) % 180
plt.subplot(2,3,4)
plt.imshow(img_bgr_hsv_copy)
img_bgr_hsv_copy[:,:,2] = (img_bgr_hsv_copy[:,:,2]+np.random.random()) % 180
plt.subplot(2,3,5)
plt.imshow(img_bgr_hsv_copy)
img_bgr_hsv_bgr = cv2.cvtColor(img_bgr_hsv_copy,cv2.COLOR_HSV2BGR)
plt.subplot(2,3,6)
plt.imshow(img_bgr_hsv_bgr)
plt.show()

显示结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42612717/article/details/106321176