我正在解决一个问题,但只解决了其中一半。我正在处理带有X,Y坐标的2D绘图空间。我想在绘图空间上设置4个点,并为每个点设置颜色并生成颜色映射。
我能够使用2个点生成颜色映射-创建向量并从一个点到另一个点。然而,这种方法在几何意义上创建了覆盖点的2D平面/1D线。但是如果设置4个点,则需要生成表面。换句话说,我需要在这些点之间适配表面。
以下是我的想象示意图:
这是我用于生成从一个X,Y,[RGB]到另一个X,Y,[RGB]的直接变化的代码。
我能够使用2个点生成颜色映射-创建向量并从一个点到另一个点。然而,这种方法在几何意义上创建了覆盖点的2D平面/1D线。但是如果设置4个点,则需要生成表面。换句话说,我需要在这些点之间适配表面。
以下是我的想象示意图:
![](https://istack.dev59.com/FgJGv.webp)
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个以上的点拟合到创建色彩地图表面中,其中这些点具有X、Y坐标,但携带[R、G、B]值。
提前致谢。