import cv2
from matplotlib import pyplot as plt
"""图片格式转换"""
def viz_hsv(image_list, image_num: int = 0) -> None:
"""
将图像分解到hsv三通道的可视化
"""
# test_im, test_label = image_list[image_num]
test_im = image_list[image_num]
# convert to hsv
hsv = cv2.cvtColor(test_im, cv2.COLOR_RGB2HSV)
# Print image label
h = hsv[:, :, 0]
s = hsv[:, :, 1]
v = hsv[:, :, 2]
# Plot the original image and the three channels
_, ax = plt.subplots(1, 4, figsize=(20, 10))
ax[0].set_title("Standardized image")
ax[0].imshow(test_im)
ax[1].set_title("H channel")
ax[1].imshow(h, cmap="gray")
ax[2].set_title("S channel")
ax[2].imshow(s, cmap="gray")
ax[3].set_title("V channel")
ax[3].imshow(v, cmap="gray")
plt.show()
img1 = "./light1.jpg"
img2 = "./light2.jpg"
img2 = cv2.imread(img2)
viz_hsv([img2], 0)
hsv = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV)
hsv格式图片转换
于 2023-09-18 16:23:36 首次发布