2014-03-14 3 views
0

저는 pyfits를 사용하여 2D 배열에로드 할 이미지가 있습니다. 이미지의 두 픽셀을 통해 선을 그려 새로운 선을 추가하여 저장하려고합니다 (플롯 아님). 이 후 다른 색상으로 이전 선에 수직 인 선을 그립니다. matplotlib를 사용하여 이것을 달성하는 가장 좋은 방법은 무엇입니까? 나는 PIL로 시도했다. 나는 그것을 할 수 없었다. 코드를보고이를 수행 할 수있는 방법을 제안하십시오. 나는 또한 이미지를 붙이고있다이미지 파이썬 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 대신 enter image description here

+0

이 편집은 확실히 문제를 개선합니다. 재개하기 위해 투표. –

+0

필요한 변경을했습니다. 미안해지기 전에 미안해. :). 감사 – chaithu

답변

1

죄송합니다

(90)의 모습. 저는 각도를 죄에, 실수로 각도로 전달했습니다. 나는 라디안으로 전달되었고 효과가있었습니다. 고맙습니다

angle = (angle * math.pi)/180 
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+ (math.pi)/2))) 
ver1 = math.floor(y_centroid - 20*(math.sin(angle+(math.pi)/2)))