-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import geopandas as gpd | ||
from deepforest.utilities import read_file | ||
import rasterio as rio | ||
import os | ||
from shapely.geometry import box | ||
import pandas as pd | ||
|
||
train_crowns = gpd.read_file("/orange/ewhite/DeepForest/UrbanLondon/crowns/tiles_0.25m_160_20_0_train_crowns.shp") | ||
test_crowns = gpd.read_file("/orange/ewhite/DeepForest/UrbanLondon/crowns/tiles_0.25m_160_20_0_test_crowns.shp") | ||
|
||
source = "Zuniga-Gonzalez et al. 2023" | ||
|
||
def get_image_annotations(tif_path, crowns): | ||
with rio.open(tif_path) as src: | ||
bounds = src.bounds | ||
bbox = box(bounds.left, bounds.bottom, bounds.right, bounds.top) | ||
intersected = gpd.overlay(crowns, gpd.GeoDataFrame({'geometry': [bbox]}, crs=crowns.crs), how='intersection') | ||
clipped = gpd.clip(intersected, bbox) | ||
if clipped.empty: | ||
return None | ||
clipped["image_path"] = os.path.basename(tif_path) | ||
clipped['label'] = 'Tree' | ||
clipped = read_file(clipped, root_dir=os.path.dirname(tif_path)) | ||
|
||
return clipped | ||
|
||
tif_dir = "/orange/ewhite/DeepForest/UrbanLondon/rgb" | ||
tif_files = [os.path.join(tif_dir, f) for f in os.listdir(tif_dir) if f.endswith('.tif')] | ||
|
||
train_annotations = pd.concat([get_image_annotations(tif, train_crowns) for tif in tif_files], ignore_index=True) | ||
test_annotations = pd.concat([get_image_annotations(tif, test_crowns) for tif in tif_files], ignore_index=True) | ||
|
||
annotations = pd.concat([train_annotations, test_annotations], ignore_index=True) | ||
annotations['source'] = source | ||
annotations['image_path'] = tif_dir + "/" + annotations['image_path'] | ||
annotations["image_path"] = annotations["image_path"].str.replace("tif", "png") | ||
annotations.to_csv("/orange/ewhite/DeepForest/UrbanLondon/annotations.csv", index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.