python两点画线_在图像python matplotlib的两点之间画一条线

使用Python的matplotlib库在2D数组表示的图像上,从一个像素点到另一个像素点绘制直线,并在该直线上方绘制垂直线。通过调整角度和坐标,实现了不同颜色的线条效果。代码中存在一些问题导致垂直线未正确显示,可能需要修正角度计算或绘图逻辑。
摘要由CSDN通过智能技术生成

我有一个图像,我正在使用pyfits加载到2D数组中。我想在图像上画一条穿过两个像素的线,并用添加的新线保存它(不是绘图)。在这之后,我想用不同的颜色画一条垂直于前一条线的线。使用matplotlib实现这一点的最佳方法是什么?我用皮尔试过了。我没能做到。请看一下代码并建议我一种方法。我也附上了图片def plotAxes(map, angle, x_centroid, y_centroid):

hor = math.floor(x_centroid + 20*(math.cos(angle)))

ver = math.floor(y_centroid - 20*(math.sin(angle)))

hor1 = math.floor(x_centroid + 20*(math.cos(angle+90.0)))

ver1 = math.floor(y_centroid - 20*(math.sin(angle+90.0)))

map_height = len(map)

map_width = len(map[0])

point = [ver, hor]

center = [y_centroid, x_centroid]

Max = np.max(map)

array = np.zeros((map_height, map_width), int)

for i in range(0, map_height):

for j in range(0, map_width):

array[i][j] = (math.floor((float(map[i][j])/float(Max))*255))

im = Image.fromarray(np.uint8(array))

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值