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

ça marche pas mais c'est cool

parent 14c24b93
from PIL import Image
import urllib.request
import json
import math
......@@ -5,25 +6,36 @@ import matplotlib.pyplot as plt
import csv
import numpy as np
csvfile = "D:/documents/IMT/datascience/challenge3/code/svg.csv"
import png
def draw_image_from_colour_grid(iteration,partie,colour_grid):
im = Image.new(mode='RGB', size=(len(colour_grid), len(colour_grid[0])))
im.putdata([x for row in colour_grid for x in row])
im.show()
im.save('D:/documents/IMT/datascience/challenge3/code/out'+str(iteration)+'partie'+str(partie)+'.jpg', 'JPEG')
def pixelfromaltitude(altitude):
'''convert altitude to RGB as altitude = R*255+V'''
return((altitude//255,altitude%255,0))
def altitudefrompixel(pixel):
'''pixelfromaltitude^-1'''
return(pixel[0]*255+pixel[1]+0)
def convert(listPixels):
intercept=np.matrix([60.59049467, -12.61278589])
coef=np.matrix([[2.34940394e-05, -9.22137497e-03],[1.12794639e-02, 4.39805467e-04]])
intercept=np.matrix([60.96807828, -9.89553667])
coef=np.matrix([[1.66888816e-06, -9.33208479e-03], [1.20700439e-02, -1.55870403e-03]])
res=[]
for pixel in listPixels:
print("intercept = ", intercept)
print("coef = ", coef)
print("np.matrix(([pixel[0],pixel[1]])) = ", np.matrix(([pixel[0],pixel[1]])))
res.append(np.transpose(intercept)+coef*np.transpose(np.matrix(([pixel[0],pixel[1]]))))
return(res)
print("coucou ! : ",convert([(4036,2790),(1988,2579),(660,1319)]))
def getElevation(listPixels):
listLongLat=convert(listPixels)
lat_list=[elt[0] for elt in listLongLat]
long_list=[elt[1] for elt in listLongLat]
lat_list=[elt[0].item(0) for elt in listLongLat] #.item(0) c'est pour prendre l'unique elt de la np.matrix
lon_list=[elt[1].item(0) for elt in listLongLat]
#on contruit le json
d_ar=[{}]*len(lat_list)
......@@ -51,17 +63,22 @@ def getElevation(listPixels):
elev_list.append(js_str['results'][j]['elevation'])
return(elev_list)
listPixels=[]
for line in range(3510):
for col in range(4830):
listPixels.append((col,line))
liste=getElevation(listPixels)
nbLine=3510
nbCol=483
partie=0
for iteration in range(3510):
listPixels=[]
for line in range(iteration,(iteration+1)):
for col in range(partie*nbCol,(partie+1)*nbCol):
listPixels.append((col,line))
liste=getElevation(listPixels)
res=[[[] for _ in range(4830)] for _ in range(3510)]
for pixel in listPixels:
line=pixel[1]
col=pixel[0]
res[line][col]=listPixels[4830*line+col]
with open(csvfile, "w") as output:
writer = csv.writer(output, lineterminator='\n')
writer.writerows(res)
res=[[[] for _ in range(nbCol)] for _ in range(nbLine)]
for pixel in listPixels:
line=pixel[1]
col=pixel[0]
res[line][col]=liste[nbCol*line+nbCol]
image_svg=[[pixelfromaltitude(a) for a in liste]]
draw_image_from_colour_grid(iteration,partie,image_svg)
print("ok")
......@@ -5,12 +5,12 @@ from sklearn import linear_model
from PIL import Image
import matplotlib.pyplot as plt
pixel_x=[4036,1988,553,660,706]
pixel_y=[2790,2579,2686,1319,684]
latitude=[34.966380,36.834287,35.898757,48.275379,54.415694]
longitude=[34.068130,11.116444,-5.284306,-4.582430,-4.365422]
listePixels=[[pixel_x[i],pixel_y[i]] for i in range(5)]
listeLatLong=[[latitude[i],longitude[i]] for i in range(5)]
pixel_x=[4036,1988,553,660,706,720,1672,2920,3976,2344,2728]
pixel_y=[2790,2579,2686,1319,684,1320,568,2504,2256,3072,240]
latitude=[34.966380,36.834287,35.898757,48.275379,54.415694,48.480773,56.300218,37.550021,39.389509,32.928013,58.837378]
longitude=[34.068130,11.116444,-5.284306,-4.582430,-4.365422,-4.614974,9.251141,22.098190,32.671718,13.178906,25.607752]
listePixels=[[pixel_x[i],pixel_y[i]] for i in range(11)]
listeLatLong=[[latitude[i],longitude[i]] for i in range(11)]
reg = linear_model.LinearRegression()
reg.fit(listePixels, listeLatLong)
......
This diff is collapsed.
out.jpg

687 Bytes

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