This repository has been archived by the owner on Sep 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprint_image.py
40 lines (31 loc) · 9.96 KB
/
print_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from PIL import Image, ImageDraw
import numpy as np
im = Image.open("a.pgm")
im = im.convert('RGB')
(length,height) = im.size
im = im.resize((length//2,height//2))
draw = ImageDraw.Draw(im)
# cities = [[111, 151, 7], [112, 154, 17], [114, 149, 26], [118, 150, 37], [134, 150, 46], [137, 157, 57], [144, 156, 66], [141, 161, 75], [139, 167, 85], [132, 161, 94], [132, 159, 103], [130, 157, 113], [116, 158, 124], [105, 158, 133], [105, 164, 143], [98, 161, 153], [93, 158, 163], [86, 155, 172], [85, 164, 183], [77, 164, 193], [69, 170, 203], [68, 160, 213], [62, 163, 223], [61, 153, 233], [52, 149, 242], [45, 148, 252], [54, 145, 262], [62, 133, 271], [54, 120, 285], [67, 118, 296], [65, 111, 306], [54, 111, 316], [58, 108, 327], [61, 97, 336], [55, 92, 345], [63, 90, 354], [60, 87, 363], [64, 85, 372], [60, 79, 381], [50, 83, 392], [47, 83, 401], [48, 71, 412], [53, 70, 422], [52, 60, 433], [44, 45, 445], [39, 42, 457], [38, 34, 469], [46, 33, 482], [50, 40, 495], [53, 42, 507], [51, 47, 519], [53, 47, 531], [58, 43, 544], [65, 43, 557], [69, 50, 570], [70, 51, 582], [77, 32, 597], [103, 23, 612], [106, 23, 621], [112, 24, 630], [118, 27, 638], [125, 21, 646], [123, 36, 654], [122, 34, 661], [119, 31, 669], [109, 29, 677], [108, 30, 684], [108, 31, 691], [108, 31, 692], [103, 29, 700], [103, 33, 707], [102, 42, 715], [98, 44, 721], [91, 44, 724], [76, 46, 725], [86, 51, 803], [88, 56, 804], [91, 70, 806], [85, 72, 808], [81, 71, 810], [78, 67, 812], [81, 64, 815], [79, 62, 818], [61, 68, 825], [67, 71, 834], [71, 73, 843], [71, 93, 854], [82, 93, 864], [88, 98, 874], [94, 107, 884], [95, 109, 894], [78, 106, 906], [76, 114, 916], [80, 118, 927], [86, 116, 938], [87, 132, 950], [82, 139, 961], [77, 138, 972], [81, 149, 984], [89, 144, 995]]
# cities = [[65, 107, 5], [48, 102, 13], [43, 101, 21], [47, 101, 30], [62, 96, 39], [58, 91, 48], [56, 88, 56], [58, 83, 65], [51, 81, 74], [41, 85, 84], [42, 79, 94], [43, 58, 104], [41, 38, 115], [57, 46, 125], [63, 43, 134], [57, 34, 144], [56, 26, 153], [61, 28, 161], [62, 29, 169], [63, 26, 177], [77, 30, 186], [78, 31, 193], [80, 39, 201], [90, 37, 209], [89, 34, 217], [98, 34, 226], [99, 27, 235], [103, 24, 244], [123, 27, 253], [120, 31, 261], [122, 37, 269], [121, 41, 277], [107, 37, 286], [101, 37, 294], [103, 43, 303], [86, 51, 312], [83, 66, 321], [78, 61, 330], [75, 59, 338], [70, 54, 347], [62, 67, 356], [73, 71, 364], [73, 79, 372], [80, 77, 379], [81, 78, 386], [81, 83, 393], [87, 100, 400], [97, 108, 406], [87, 111, 411], [86, 110, 416], [82, 107, 427], [79, 111, 438], [69, 116, 449], [69, 123, 459], [71, 128, 468], [74, 133, 476], [80, 129, 485], [81, 127, 493], [88, 131, 502], [87, 136, 510], [83, 136, 518], [86, 141, 527], [93, 138, 536], [110, 152, 545], [118, 150, 551], [120, 148, 555], [121, 149, 559], [125, 148, 564], [131, 154, 570], [145, 147, 577], [145, 157, 584], [139, 163, 591], [138, 161, 597], [116, 168, 604], [98, 163, 611], [96, 159, 618], [88, 162, 625], [82, 165, 632], [74, 155, 639], [74, 150, 646], [67, 151, 654], [62, 155, 662], [68, 170, 671], [59, 172, 679], [56, 157, 687], [52, 155, 694], [50, 150, 701], [45, 148, 709], [45, 148, 709], [49, 138, 716], [52, 138, 723], [63, 140, 730], [58, 136, 742], [54, 133, 751], [48, 132, 759], [50, 131, 767], [54, 112, 775], [56, 114, 782], [59, 112, 790], [60, 113, 797]]
# cities = [[88, 99, 20], [87, 95, 27], [89, 90, 39], [91, 86, 42], [82, 88, 57], [73, 95, 64], [81, 84, 78], [82, 83, 79], [78, 75, 91], [56, 70, 113], [55, 70, 113], [62, 59, 123], [52, 54, 135], [40, 63, 143], [45, 52, 154], [39, 50, 157], [49, 44, 171], [49, 42, 174], [57, 44, 184], [61, 39, 192], [57, 28, 207], [58, 27, 208], [66, 27, 219], [83, 26, 235], [81, 30, 238], [88, 24, 248], [90, 33, 253], [108, 28, 270], [111, 22, 275], [115, 25, 280], [127, 37, 296], [116, 35, 300], [115, 41, 305], [85, 39, 326], [89, 60, 337], [88, 68, 342], [81, 58, 349], [74, 54, 357], [76, 61, 360], [71, 65, 370], [67, 66, 372], [74, 70, 380], [71, 69, 381], [66, 94, 403], [58, 85, 406], [55, 88, 411], [50, 84, 419], [41, 82, 422], [48, 96, 431], [41, 101, 436], [42, 111, 445], [59, 110, 457], [60, 115, 460], [68, 101, 466], [62, 117, 473], [67, 114, 477], [72, 115, 487], [74, 114, 489], [75, 114, 489], [69, 127, 503], [84, 135, 513], [76, 132, 513], [69, 138, 524], [63, 129, 533], [47, 129, 551], [45, 128, 552], [46, 131, 553], [46, 134, 561], [43, 139, 569], [47, 139, 572], [52, 138, 578], [50, 139, 578], [50, 144, 588], [46, 147, 594], [47, 151, 601], [51, 148, 603], [60, 159, 618], [60, 172, 626], [72, 168, 631], [66, 156, 641], [65, 151, 648], [68, 150, 652], [69, 152, 653], [71, 151, 658], [78, 152, 668], [84, 155, 678], [85, 154, 680], [87, 154, 684], [93, 165, 697], [102, 161, 708], [104, 158, 715], [104, 157, 715], [112, 163, 730], [112, 162, 730], [113, 159, 736], [115, 153, 744], [146, 162, 769], [139, 153, 777], [142, 149, 778], [130, 151, 790]]
#cities = [[95, 150, 13], [73, 149, 31], [79, 145, 41], [80, 139, 51], [80, 135, 60], [80, 133, 68], [91, 136, 80], [90, 127, 91], [88, 123, 101], [90, 118, 111], [79, 105, 123], [86, 94, 134], [81, 96, 141], [78, 97, 147], [71, 98, 154], [65, 96, 159], [67, 100, 160], [63, 100, 166], [60, 94, 184], [62, 91, 193], [64, 90, 199], [69, 84, 210], [72, 83, 218], [82, 83, 228], [80, 76, 238], [74, 74, 246], [71, 72, 252], [75, 67, 261], [86, 69, 272], [82, 61, 281], [76, 63, 291], [75, 62, 299], [71, 56, 308], [61, 58, 320], [64, 49, 332], [66, 52, 340], [82, 55, 351], [89, 57, 363], [94, 42, 377], [97, 42, 387], [115, 35, 402], [123, 25, 415], [100, 26, 430], [97, 30, 440], [92, 28, 450], [82, 34, 462], [76, 26, 473], [71, 29, 483], [72, 38, 494], [70, 38, 500], [70, 36, 506], [63, 33, 515], [64, 28, 524], [61, 30, 532], [49, 31, 544], [51, 43, 557], [40, 41, 570], [38, 43, 579], [40, 45, 587], [43, 44, 594], [53, 49, 605], [47, 62, 620], [48, 88, 637], [48, 88, 637], [55, 90, 650], [50, 94, 660], [44, 93, 668], [43, 97, 676], [54, 112, 688], [52, 119, 697], [46, 124, 707], [46, 131, 716], [53, 129, 725], [58, 125, 735], [62, 127, 742], [63, 128, 748], [69, 134, 759], [53, 135, 772], [53, 138, 780], [54, 139, 785], [54, 143, 793], [60, 148, 802], [49, 146, 813], [46, 149, 824], [47, 161, 837], [45, 162, 844], [44, 167, 853], [52, 169, 863], [55, 163, 873], [68, 165, 885], [68, 156, 896], [99, 157, 912], [101, 161, 922], [114, 166, 935], [126, 170, 949], [130, 168, 957], [130, 164, 963], [140, 166, 973], [140, 158, 983], [144, 153, 992]]
# cities = [[60, 145, 0], [57, 147, 9], [50, 141, 21], [50, 149, 33], [49, 153, 43], [45, 158, 53], [54, 166, 66], [61, 163, 77], [64, 162, 87], [69, 170, 100], [69, 167, 109], [71, 157, 121], [67, 154, 132], [79, 152, 146], [80, 159, 159], [78, 165, 171], [77, 167, 180], [82, 171, 193], [89, 165, 208], [106, 170, 225], [123, 167, 239], [127, 164, 249], [137, 166, 260], [136, 162, 269], [143, 155, 280], [124, 152, 295], [121, 157, 307], [119, 160, 316], [111, 157, 326], [108, 161, 336], [103, 154, 348], [102, 150, 358], [99, 153, 368], [98, 152, 376], [91, 152, 388], [92, 149, 397], [79, 138, 411], [75, 130, 422], [78, 125, 432], [86, 117, 445], [90, 113, 456], [97, 107, 466], [84, 111, 478], [77, 113, 491], [70, 111, 510], [62, 110, 521], [58, 110, 530], [61, 97, 542], [65, 100, 555], [66, 95, 564], [68, 95, 569], [70, 93, 576], [74, 100, 584], [73, 104, 589], [86, 95, 602], [93, 91, 615], [79, 87, 630], [66, 80, 645], [68, 71, 658], [80, 72, 673], [89, 73, 686], [82, 67, 699], [82, 59, 714], [88, 59, 727], [87, 58, 735], [89, 52, 747], [114, 38, 766], [105, 33, 779], [101, 27, 791], [95, 34, 803], [91, 31, 814], [81, 38, 826], [78, 37, 832], [81, 32, 835], [77, 30, 839], [76, 34, 862], [70, 37, 873], [64, 38, 883], [63, 30, 895], [50, 35, 908], [45, 38, 919], [46, 47, 931], [57, 54, 945], [62, 53, 957], [48, 80, 975], [57, 86, 990], [40, 90, 1006], [46, 93, 1018], [42, 98, 1031], [55, 100, 1046], [52, 106, 1059], [43, 109, 1074], [47, 114, 1087], [44, 117, 1099], [53, 127, 1115], [58, 125, 1128], [67, 129, 1144], [74, 134, 1161], [64, 137, 1178], [63, 139, 1189]]
cities = [[47, 84, 3], [45, 90, 18], [44, 102, 38], [48, 122, 60], [52, 126, 76], [54, 129, 89], [49, 130, 103], [50, 137, 120], [43, 146, 136], [50, 143, 150], [64, 141, 164], [65, 139, 172], [67, 144, 183], [70, 140, 195], [76, 149, 211], [65, 148, 228], [66, 155, 243], [59, 170, 259], [65, 167, 272], [72, 163, 285], [79, 163, 297], [81, 163, 304], [82, 162, 311], [88, 166, 322], [88, 156, 336], [129, 166, 353], [132, 163, 361], [135, 169, 372], [146, 155, 389], [116, 149, 409], [108, 151, 425], [100, 149, 439], [95, 153, 449], [93, 149, 461], [80, 132, 475], [78, 128, 486], [84, 116, 500], [87, 110, 512], [91, 108, 521], [89, 106, 529], [78, 97, 539], [77, 109, 558], [68, 115, 572], [66, 108, 583], [62, 105, 592], [64, 100, 601], [66, 98, 609], [65, 88, 619], [64, 87, 625], [63, 86, 631], [69, 81, 641], [74, 94, 655], [75, 90, 664], [78, 86, 674], [80, 81, 682], [79, 80, 687], [82, 79, 695], [89, 83, 705], [89, 75, 716], [76, 67, 730], [86, 66, 742], [89, 62, 751], [82, 52, 760], [73, 45, 770], [86, 42, 789], [96, 40, 801], [97, 44, 811], [102, 38, 823], [126, 41, 841], [124, 39, 850], [119, 34, 860], [119, 33, 868], [119, 27, 880], [117, 28, 888], [116, 27, 894], [111, 24, 905], [104, 23, 918], [87, 27, 935], [84, 36, 951], [71, 34, 967], [69, 32, 977], [72, 26, 989], [66, 29, 1000], [49, 30, 1013], [39, 27, 1026], [52, 41, 1040], [57, 38, 1049], [62, 47, 1059], [55, 44, 1070], [46, 46, 1080], [45, 53, 1090], [40, 62, 1101], [53, 54, 1114], [55, 55, 1122], [55, 59, 1131], [70, 62, 1143], [65, 66, 1153], [60, 63, 1163], [53, 73, 1174], [43, 68, 1186]]
for city in cities:
city.pop()
def print_onlypoint(cities):
point_list = []
for city in cities:
point_list.append((city[1],city[0]))
draw.point(point_list,fill=(255,0,0))
im.save("only point.png")
def print_path(cities):
point_list = []
temp = 0
while temp < len(cities) - 1:
draw.line((cities[temp][1],cities[temp][0],cities[temp+1][1],cities[temp+1][0]),fill=(255,0,0))
temp += 1
draw.line((cities[temp][1],cities[temp][0],cities[0][1],cities[0][0]),fill=(255,0,0))
im.save("path.png")
print_onlypoint(cities)
print_path(cities)