python定义x、y_Python创建由X,Y位置定义的RGB值的颜色映射

我正在解决一个问题,我只解决了一半。

我正在用X,Y坐标处理二维绘图空间。我想在绘图空间中设置4个点,为每个点设置颜色并生成颜色贴图。在

我可以用2个点生成彩色地图-创建向量,从一个点到另一个点。然而,这种方法在几何意义上在点上创建2D平面/1D线。但如果设置4个点,则需要生成曲面。换言之,我需要把曲面拟合到这些点上。在

我就是这么想的:

FgJGv.png

这是我生成从一个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()

结果:

xni2H.png

我对这个方法也很困惑,因为绘图空间上的点是由X,Y坐标定义的,但是它们携带[R,G,B]值。在

总而言之,我需要将3到更多的点拟合到colormap曲面中,这些点有X,Y坐标,但携带[R,G,B]值。在

提前谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值