Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Grégoire PETIT
DataScience
Commits
cd9abc4e
Commit
cd9abc4e
authored
Dec 03, 2018
by
Grégoire PETIT
Browse files
ça marche pas mais c'est cool
parent
14c24b93
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Challenge3/code/getElevation.py
View file @
cd9abc4e
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.34940394
e-0
5
,
-
9.
22137497
e-03
],[
1.
127946
39e-02
,
4.39805467
e-0
4
]])
intercept
=
np
.
matrix
([
60.
96807828
,
-
9.89553667
])
coef
=
np
.
matrix
([[
1.66888816
e-0
6
,
-
9.
33208479
e-03
],
[
1.
207004
39e-02
,
-
1.55870403
e-0
3
]])
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"
)
Challenge3/code/regressionImage.py
View file @
cd9abc4e
...
...
@@ -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
)
...
...
Challenge3/code/svg.csv
0 → 100644
View file @
cd9abc4e
This diff is collapsed.
Click to expand it.
out.jpg
0 → 100644
View file @
cd9abc4e
687 Bytes
small_smiley.png
0 → 100644
View file @
cd9abc4e
72 Bytes
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment