我正在解决一个问题,我只解决了一半。
我正在用X,Y坐标处理二维绘图空间。我想在绘图空间中设置4个点,为每个点设置颜色并生成颜色贴图。在
我可以用2个点生成彩色地图-创建向量,从一个点到另一个点。然而,这种方法在几何意义上在点上创建2D平面/1D线。但如果设置4个点,则需要生成曲面。换言之,我需要把曲面拟合到这些点上。在
我就是这么想的:
这是我生成从一个X,Y,[RGB]到另一个X,Y,[RGB]的直接变化的代码。在import numpy as np
import colorsys
import cv2
a = np.array([100,0,0]) # Point one with x=0,y=0-max and rgb value
b = np.array([0,255,0]) # point two with x=max,y=0-max and rgb value
#in this case i loop from y=0 to y=max for corresponding point on the other side of drawing space - that is x=max
a = a[::-1]
b= b[::-1]
leds = 31 # just constant
h_color=100 # height of drawing space
t_lengt = (600/leds)*leds #recalculation of width (because I need integer)
vector = (b-a)*1.0/t_lengt
arr_texture = np.zeros(shape=[h_color, t_lengt, 3], dtype=np.uint8) #drawing space defined by x,y and 3d value
for i in range(t_lengt): # loop for all points in x=0 to x=max (that is y=0 to max)
for j in range(h_color):
arr_texture[j][i]=[a[0]+vector[0]*i,a[1]+vector[1]*i,a[2]+vector[2]*i]
cv2.imwrite('color_img.jpg', arr_texture)
cv2.imshow("image", arr_texture);
cv2.waitKey(0)
cv2.destroyAllWindows()
结果:
我对这个方法也很困惑,因为绘图空间上的点是由X,Y坐标定义的,但是它们携带[R,G,B]值。在
总而言之,我需要将3到更多的点拟合到colormap曲面中,这些点有X,Y坐标,但携带[R,G,B]值。在
提前谢谢