Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,25 @@
|
|
1 |
-
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from urllib import request
|
2 |
|
3 |
+
import detectree as dtr
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import rasterio as rio
|
6 |
+
from rasterio import plot
|
7 |
+
|
8 |
+
# download a tile from the SWISSIMAGE WMS
|
9 |
+
tile_url = (
|
10 |
+
"https://wms.geo.admin.ch/?SERVICE=WMS&REQUEST=GetMap&VERSION=1.3.0&"
|
11 |
+
"FORMAT=image/png&LAYERS=ch.swisstopo.images-swissimage&CRS=EPSG:2056"
|
12 |
+
"&BBOX=2532980,1152150,2533380,1152450&WIDTH=800&HEIGHT=600"
|
13 |
+
)
|
14 |
+
tile_filename = "tile.png"
|
15 |
+
request.urlretrieve(tile_url, tile_filename)
|
16 |
+
|
17 |
+
# use the pre-trained model to segment the image into tree/non-tree-pixels
|
18 |
+
y_pred = dtr.Classifier().predict_img(tile_filename)
|
19 |
+
|
20 |
+
# side-by-side plot of the tile and the predicted tree/non-tree pixels
|
21 |
+
figwidth, figheight = plt.rcParams["figure.figsize"]
|
22 |
+
fig, axes = plt.subplots(1, 2, figsize=(2 * figwidth, figheight))
|
23 |
+
with rio.open(tile_filename) as src:
|
24 |
+
plot.show(src, ax=axes[0])
|
25 |
+
axes[1].imshow(y_pred)
|