Commit b0d06ed8 authored by Grégoire PETIT's avatar Grégoire PETIT
Browse files

essai de 4 dimensionnal corr fail

parent 0bca5c30
from PIL import Image
pixels=[(x,1593) for x in range(919,2076)
import pandas as pd
import numpy as np
from sklearn import linear_model
from PIL import Image
import matplotlib.pyplot as plt
input_filename_altitude="D:/documents/IMT/datascience/challenge3/moodle/elevation1x1_new-mer-bleue_deforme.bmp"
im_alt = Image.open(input_filename_altitude)
listePixels=[]
pixels=[(x,1593) for x in range(919,2071)]
alt_test=[]
for pix in pixels:
rgbvalues=im_alt.getpixel(pix)
red,green,blue=rgbvalues
listePixels.append(rgbvalues)
alt_test.append(-1087.8611147630386+9.49719453*red-2.34124445*green+1.6696076*blue)
altitudes=[0, 11, 6, 11, 14, 10, 29, 13, 0, 15, 9, 14, 31, 8, 9, 11, 4, 1, 2, 2, 2, 3, 4, 4, 11, 17, 22, 27, 41, 29, 35, 40, 40, 44, 44, 43, 41, 33, 35, 31, 39, 50, 56, 38, 43, 30, 11, 11, 9, 7, 5, 6, 4, 9, 15, 6, 12, 14, 2, 3, 3, 4, 5, 5, 7, 8, 9, 8, 7, 18, 31, 31, 40, 48, 9, 36, 37, 50, 27, 11, 28, 15, 18, 21, 21, 18, 25, 22, 32, 34, 33, 40, 50, 49, 74, 86, 107, 104, 83, 55, 82, 70, 81, 73, 81, 88, 46, 39, 31, 46, 61, 46, 69, 73, 61, 79, 63, 135, 119, 134, 126, 117, 105, 103, 85, 115, 116, 112, 132, 120, 101, 95, 140, 180, 233, 144, 154, 163, 192, 186, 185, 219, 219, 251, 210, 150, 191, 242, 202, 172, 203, 222, 227, 245, 258, 281, 288, 293, 313, 326, 370, 424, 387, 360, 390, 373, 406, 363, 367, 326, 359, 311, 351, 369, 377, 383, 360, 344, 349, 396, 409, 396, 380, 342, 398, 396, 361, 323, 311, 320, 321, 330, 315, 355, 395, 403, 391, 386, 370, 305, 312, 302, 271, 308, 351, 323, 317, 340, 350, 308, 293, 305, 329, 341, 380, 372, 374, 393, 428, 405, 379, 424, 440, 460, 502, 513, 517, 574, 523, 462, 378, 494, 504, 531, 529, 609, 535, 605, 598, 570, 603, 544, 585, 730, 616, 535, 518, 569, 711, 608, 545, 606, 703, 676, 687, 788, 830, 797, 776, 793, 816, 768, 836, 883, 818, 886, 894, 895, 856, 773, 740, 744, 728, 726, 773, 778, 744, 734, 721, 736, 793, 773, 805, 757, 790, 795, 855, 862, 835, 836, 850, 807, 818, 795, 778, 776, 775, 761, 741, 738, 729, 745, 761, 735, 776, 795, 814, 831, 857, 913, 943, 919, 905, 923, 921, 927, 903, 918, 904, 909, 940, 926, 904, 873, 994, 943, 916, 1029, 882, 914, 968, 998, 990, 975, 969, 956, 1008, 924, 890, 909, 987, 960, 905, 823, 760, 718, 643, 595, 618, 593, 495, 451, 469, 408, 364, 343, 336, 491, 572, 683, 592, 672, 567, 544, 544, 564, 530, 456, 524, 571, 668, 673, 667, 595, 531, 576, 509, 477, 446, 468, 516, 491, 575, 520, 540, 548, 605, 550, 507, 545, 598, 626, 589, 563, 607, 656, 823, 999, 868, 949, 1213, 1343, 1373, 1393, 1370, 1225, 1062, 978, 1003, 979, 822, 908, 712, 673, 763, 819, 811, 791, 723, 647, 623, 596, 455, 426, 405, 394, 427, 358, 356, 353, 349, 363, 373, 342, 335, 334, 333, 340, 340, 347, 353, 354, 359, 369, 388, 460, 441, 507, 473, 533, 563, 596, 530, 482, 461, 438, 489, 637, 727, 764, 735, 822, 832, 799, 797, 714, 739, 757, 717, 537, 408, 400, 395, 380, 318, 314, 335, 338, 314, 291, 230, 251, 214, 251, 214, 205, 235, 162, 161, 172, 194, 198, 207, 197, 206, 203, 213, 220, 220, 223, 231, 235, 269, 282, 272, 257, 242, 251, 254, 264, 218, 220, 215, 208, 216, 254, 313, 350, 335, 338, 391, 350, 306, 353, 269, 308, 281, 243, 223, 225, 234, 224, 233, 258, 376, 331, 244, 242, 224, 228, 213, 207, 206, 207, 205, 206, 208, 208, 219, 211, 659, 465, 353, 350, 368, 268, 230, 221, 217, 619, 465, 322, 296, 390, 377, 375, 392, 395, 658, 916, 287, 230, 230, 230, 241, 294, 380, 484, 691, 986, 1523, 1422, 1282, 1298, 1352, 1231, 916, 783, 898, 1299, 836, 688, 654, 898, 1169, 889, 1164, 1693, 1454, 1637, 2132, 1729, 1870, 1925, 1459, 1351, 1058, 977, 1150, 852, 524, 493, 524, 500, 436, 574, 843, 1309, 1625, 2001, 2097, 2129, 2418, 2086, 1967, 1729, 1402, 1097, 1155, 1342, 1840, 1713, 1519, 1556, 1892, 1974, 2087, 2070, 2140, 2084, 2096, 1581, 1987, 2260, 2048, 2479, 2346, 2216, 2099, 2326, 2698, 2860, 2498, 2168, 2316, 2467, 2365, 2270, 2062, 1702, 2140, 2444, 2706, 2732, 2652, 2374, 2559, 2622, 2575, 2348, 2116, 1759, 1256, 1346, 1169, 1335, 1332, 940, 997, 1211, 1222, 967, 1315, 1609, 1743, 1880, 1813, 1651, 1975, 2116, 2151, 2436, 2904, 2765, 2973, 2665, 2622, 2873, 2201, 1795, 2217, 2274, 1720, 1668, 2061, 2229, 2331, 2299, 2505, 2112, 1913, 1603, 1310, 1166, 1062, 854, 420, 407, 790, 872, 700, 868, 1328, 1646, 1967, 2092, 2640, 2390, 2207, 2117, 1676, 1173, 1056, 1671, 2273, 2157, 2248, 1982, 1714, 1181, 1070, 970, 1306, 1512, 1439, 1716, 1416, 1413, 1504, 1135, 1077, 1095, 856, 710, 932, 1208, 952, 590, 459, 499, 543, 500, 407, 395, 421, 624, 591, 475, 421, 323, 318, 332, 356, 404, 420, 414, 377, 374, 371, 359, 350, 296, 295, 304, 337, 324, 342, 311, 347, 346, 357, 334, 292, 283, 303, 225, 256, 246, 255, 245, 273, 287, 281, 288, 295, 275, 292, 291, 265, 260, 287, 285, 274, 273, 271, 279, 282, 278, 265, 264, 267, 269, 266, 268, 268, 271, 274, 267, 257, 265, 272, 268, 262, 270, 254, 255, 274, 267, 240, 245, 253, 256, 255, 267, 212, 247, 262, 298, 301, 303, 311, 295, 269, 277, 252, 260, 246, 262, 260, 258, 266, 265, 263, 262, 260, 251, 246, 226, 229, 225, 227, 228, 194, 233, 231, 227, 223, 232, 235, 243, 251, 246, 257, 248, 252, 258, 244, 239, 238, 237, 240, 249, 250, 242, 267, 392, 499, 477, 448, 314, 410, 250, 293, 418, 635, 435, 451, 329, 389, 329, 182, 182, 182, 187, 346, 536, 857, 787, 890, 869, 365, 421, 841, 964, 1016, 1131, 1097, 903, 716, 552, 729, 678, 714, 619, 457, 572, 677, 703, 446, 437, 557, 572, 720, 917, 857, 780, 455, 443, 635, 1030, 1474, 993, 763, 740, 556, 536, 545, 465, 212, 62, 62, 62, 62, 62, 62, 62, 143, 526, 885, 1078, 1429, 1819, 1738, 1323, 1046, 1018, 901, 337, 134, 215, 271, 599, 1469, 1436, 1430, 1362, 1526, 1476, 1482, 1508, 1572, 1640, 1565, 1496, 1708, 1490, 1198, 1608, 1708, 1682, 1137, 1110, 1038, 867, 973, 1034, 847, 680, 343, 765, 603, 635, 572, 439, 308, 198, 161, 161, 150, 141, 130, 123, 117, 120, 111, 111, 105, 94, 91, 96, 95, 88, 89, 88, 79, 74, 68, 64, 66, 66, 66, 67, 64, 70, 70, 70, 70, 68, 66, 68, 64, 64, 61, 60, 52, 53, 49, 48, 48, 45, 44, 43, 42, 38, 41, 40, 41, 40, 41, 40, 39, 40, 41, 40, 32, 37, 39, 38, 37, 36, 31, 25, 28, 27, 22, 22, 16, 16, 13, 15, 16, 12, 16, 13, 14, 11, 10, 8, 10, 7, 7, 6, 7, 4, 6, 5, 4, 6, 4, 3, 2, 1, 1, -1, -3, -3, -2, -2, 0, 2, 0, -2, -3, 0, 1, 0, 0, 0, -1, -4, -4, -3, -2, -2, -2, -5, -3, -5, -4, -2, -2, -1, -2, -3, -2, -2, -1, -1, -1, -3, -1, -1]
alt=altitudes[::-1]
df = {'altitude' : pd.Series(alt), 'R' : pd.Series([rgbvalues[0] for rgbvalues in listePixels]), 'G' : pd.Series([rgbvalues[1] for rgbvalues in listePixels]), 'B' : pd.Series([rgbvalues[2] for rgbvalues in listePixels])}
print(df)
reg = linear_model.LinearRegression()
reg.fit(listePixels, alt)
print("reg.coef_ = ", reg.coef_)
print("reg.intercept_ = ", reg.intercept_)
print(len(pixels))
print(len(altitudes))
\ No newline at end of file
print(len(altitudes))
def getAltitude(rgbValues):
if rgbValues==(255,255,255):
res=0 #il y aura un effet sur les bord de la carte car sur la jonction les pixels ne sont pas parfaitement blanc
else:
R,G,B=rgbValues
res=4810/7921*(G-186)**2
return(res)
def getAltXY(pixel):
'''Permet d'avoir l'altitude réelle pour un pixel'''
rgbValues=im_alt.getpixel(pixel)
# print("rgbValues = ", rgbValues)
return(getAltitude(rgbValues))
alt_vert=[getAltXY(pix) for pix in pixels]
#plt.plot(pixels,alt_test)
plt.plot(pixels,alt)
plt.plot(pixels,alt_vert)
plt.show()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment