肥皂起泡泡
在 Python 中使用 OpenCV 非常简单。在这里,我创建了一个函数来绘制示例图像。请注意,对于此功能,图像必须是 RGB 或 BGR。import cv2import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dimage_BGR = np.uint8(np.random.rand(50,50,3) * 255)#this image above is just an example. To load a real image use the line below#image_BGR = cv2.imread('path/to/image')def toLAB(image, input_type = 'BGR'): conversion = cv2.COLOR_BGR2LAB if input_type == 'BGR' else cv2.COLOR_RGB2LAB image_LAB = cv2.cvtColor(image, conversion) y,x,z = image_LAB.shape LAB_flat = np.reshape(image_LAB, [y*x,z]) colors = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) if input_type == 'BGR' else image colors = np.reshape(colors, [y*x,z])/255. fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(xs=LAB_flat[:,2], ys=LAB_flat[:,1], zs=LAB_flat[:,0], s=10, c=colors, lw=0) ax.set_xlabel('A') ax.set_ylabel('B') ax.set_zlabel('L') plt.show() return image_LAB lab_image = toLAB(image_BGR)结果是这样的: