36 lines
835 B
Python
36 lines
835 B
Python
# -*- coding:utf-8 -*-
|
|
# @Author len
|
|
# @Create 2023/11/22 11:18
|
|
|
|
import cv2
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
def show_lab_colorspace(image_path):
|
|
# 加载图像
|
|
image = cv2.imread(image_path)
|
|
|
|
# 将图像转换为LAB颜色空间
|
|
lab_image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
|
|
|
|
# 分割LAB通道
|
|
L, A, B = cv2.split(lab_image)
|
|
|
|
# 显示LAB通道
|
|
fig, axes = plt.subplots(1, 3, figsize=(12, 4))
|
|
axes[0].imshow(L, cmap='gray')
|
|
axes[0].set_title('L Channel')
|
|
axes[0].axis('off')
|
|
axes[1].imshow(A, cmap='gray')
|
|
axes[1].set_title('A Channel')
|
|
axes[1].axis('off')
|
|
axes[2].imshow(B, cmap='gray')
|
|
axes[2].set_title('B Channel')
|
|
axes[2].axis('off')
|
|
|
|
plt.show()
|
|
|
|
|
|
# 示例用法
|
|
image_path = "data/img.png" # 替换为您的图像路径
|
|
show_lab_colorspace(image_path) |