0
我有一個圖像,我正在使用pyfits加載到二維數組中。我想通過圖像上的兩個像素繪製一條線,並將其添加爲新線(而非繪圖)。在此之後,我想用不同顏色繪製與上一行垂直的線。什麼是使用matplotlib實現這一點的最佳方式?我用PIL試了一下。我無法做到。請查看代碼併爲我提供一種方法來執行此操作。我附上的圖像也通過圖像python的兩點繪製一條線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))
draw = ImageDraw.Draw(im)
draw.line((x_centroid,y_centroid, hor,ver ), fill="red")
draw.line((x_centroid,y_centroid, hor1,ver1 ), fill="red")
im.show()
但上述代碼似乎並沒有垂直打印行。角度看起來120代替90.
此編輯絕對可以改善問題;投票重新開放。 –
我做了必要的修改。對不起,以前不清楚:)。謝謝 – chaithu