Skip to content

Commit

Permalink
Add chile data
Browse files Browse the repository at this point in the history
  • Loading branch information
bw4sz committed Sep 25, 2024
1 parent 6ddd4b6 commit 6e5df52
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 18 deletions.
93 changes: 93 additions & 0 deletions data_prep/Alejandro_Chile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import os
import geopandas as gpd
from deepforest import utilities
import pandas as pd
import rasterio
from PIL import Image

# Directory containing the shapefiles and tif files
directory = "/orange/ewhite/DeepForest/Alejandro_Chile/alejandro"

# List to store all the GeoDataFrames
gdfs = []

# Iterate over all files in the directory
for filename in os.listdir(directory):
if filename.endswith(".shp"):
# Load the shapefile
shapefile_path = os.path.join(directory, filename)
gdf = gpd.read_file(shapefile_path)

# Extract the base name (without extension)
base_name = os.path.splitext(filename)[0].lower()

# Construct the corresponding tif file name
tif_filename = f"mos_{base_name}.tif"
tif_path = os.path.join(directory, tif_filename)

# Check if the corresponding tif file exists
if os.path.exists(tif_path):
# Append the GeoDataFrame to the list
gdf["image_path"] = os.path.basename(tif_path)
# remove multi-polygons
gdf = gdf[~gdf.geometry.type.isin(["MultiPolygon"])]
gdf["label"] = "Tree"
image_annotations = utilities.read_file(gdf, root_dir=directory)
# Just keep image_path, geometry, label columns
image_annotations = image_annotations[["image_path", "geometry", "label"]]
gdfs.append(image_annotations)
else:
print(f"Corresponding tif file for {filename} not found.")

# Concatenate all GeoDataFrames
all_annotations = gpd.GeoDataFrame(pd.concat(gdfs, ignore_index=True))

# Remove any annotations with negative coordinates
# Remove any annotations with negative coordinates
all_annotations = all_annotations[all_annotations.geometry.apply(lambda geom: geom.bounds[0] >= 0 and geom.bounds[1] >= 0)]

# Save the concatenated annotations to a CSV file
annotations_csv_path = os.path.join(directory, "annotations.csv")
# Ensure the output directory exists
output_directory = os.path.join(directory, "png_images")
os.makedirs(output_directory, exist_ok=True)

# Process each unique image path
unique_image_paths = all_annotations["image_path"].unique()
for image_path in unique_image_paths:
# Open the tif file
with rasterio.open(os.path.join(directory,image_path)) as src:
# Read the data matrix
data = src.read()
png_path = os.path.join(output_directory, os.path.basename(image_path).replace(".tif", ".png"))
# Normalize the bands to 0-255
bands = data.astype('float32')
for i in range(bands.shape[0]):
band_min, band_max = bands[i].min(), bands[i].max()
bands[i] = 255 * (bands[i] - band_min) / (band_max - band_min)
bands = bands.astype('uint8')

transform = src.transform

# Save the normalized image as PNG
with rasterio.open(
png_path,
'w',
driver='PNG',
height=src.height,
width=src.width,
count=3,
dtype='uint8',
transform=transform,
) as dst:
dst.write(bands[0], 1)
dst.write(bands[1], 2)
dst.write(bands[2], 3)

# Replace .tif with .png for the image_paths
all_annotations["image_path"] = all_annotations["image_path"].str.replace(".tif", ".png")

# Make full image_path
all_annotations["image_path"] = output_directory + "/" + all_annotations["image_path"]
all_annotations["source"] = "Alejandro_Miranda"
all_annotations.to_csv("/orange/ewhite/DeepForest/Alejandro_Chile/alejandro/annotations.csv", index=False)
3 changes: 2 additions & 1 deletion data_prep/collect_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"/orange/ewhite/DeepForest/Troles_Bamberg/coco2048/annotations/annotations.csv",
"/orange/ewhite/DeepForest/Cloutier2023/images/annotations.csv",
"/orange/ewhite/DeepForest/Firoze2023/annotations.csv",
"/orange/ewhite/DeepForest/Wagner_Australia/annotations.csv"
"/orange/ewhite/DeepForest/Wagner_Australia/annotations.csv",
"/orange/ewhite/DeepForest/Alejandro_Chile/alejandro/annotations.csv"
]

# Current errors
Expand Down
38 changes: 21 additions & 17 deletions docs/datasets.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Datasets

There are three datasets within the MillionTrees package, TreeBoxes, TreePoints, TreePolygons. Those datasets contain many source datasets from dozens of papers and research efforts. Below, each source is briefly described. The images for each dataset are generated directly from the dataloaders to allow rapid verification of the annotation status and are regenerated automatically when a new dataset is released or updated.

## Boxes
Expand All @@ -17,62 +16,67 @@ Location: Suwon, South Korea

![sample_image](public/Velasquez-Camacho_et_al._2023.png)

https://zenodo.org/records/10246449
[https://zenodo.org/records/10246449](https://zenodo.org/records/10246449)

Location: Spain

### Zamboni et al. 2022

![sample_image](public/Zamboni_et_al._2021.png)

https://github.com/pedrozamboni/individual_urban_tree_crown_detection
[https://github.com/pedrozamboni/individual_urban_tree_crown_detection](https://github.com/pedrozamboni/individual_urban_tree_crown_detection)

Location: Mato Grosso do Sul, Brazil

## Points

### Amirkolaee et al. 2023

Citation: Amirkolaee, Hamed Amini, Miaojing Shi, and Mark Mulligan. "TreeFormer: a Semi-Supervised Transformer-based Framework for Tree Counting from a Single High Resolution Image." IEEE Transactions on Geoscience and Remote Sensing (2023). https://github.com/HAAClassic/TreeFormer
Amirkolaee, Hamed Amini, Miaojing Shi, and Mark Mulligan. "TreeFormer: a Semi-Supervised Transformer-based Framework for Tree Counting from a Single High Resolution Image." IEEE Transactions on Geoscience and Remote Sensing (2023). [https://github.com/HAAClassic/TreeFormer](https://github.com/HAAClassic/TreeFormer)

Location: London, England
London, England

![sample_image](public/Amirkolaee_et_al._2023.png)

### Ventura et al. 2022

Citation:

J. Ventura, C. Pawlak, M. Honsberger, C. Gonsalves, J. Rice, N.L.R. Love, S. Han, V. Nguyen, K. Sugano, J. Doremus, G.A. Fricker, J. Yost, and M. Ritter (2024). Individual Tree Detection in Large-Scale Urban Environments using High-Resolution Multispectral Imagery. International Journal of Applied Earth Observation and Geoinformation, 130, 103848. https://github.com/jonathanventura/urban-tree-detection-data
J. Ventura, C. Pawlak, M. Honsberger, C. Gonsalves, J. Rice, N.L.R. Love, S. Han, V. Nguyen, K. Sugano, J. Doremus, G.A. Fricker, J. Yost, and M. Ritter (2024). Individual Tree Detection in Large-Scale Urban Environments using High-Resolution Multispectral Imagery. International Journal of Applied Earth Observation and Geoinformation, 130, 103848. [https://github.com/jonathanventura/urban-tree-detection-data](https://github.com/jonathanventura/urban-tree-detection-data)

Location: Southern California, United States

![sample_image](public/Ventura_et_al._2022.png)

## Polygons

### Miranda et al. 2024

[Courtesy of Alejandro Miranda](http://www.lepfor.ufro.cl/)

[<img src="public/Alejandro_Miranda.png" width="250"/>](public/Alejandro_Miranda.png)

### Hickman et al. 2021

https://zenodo.org/records/5515408
[https://zenodo.org/records/5515408](https://zenodo.org/records/5515408)

Sabah, Malaysia


### Ball et al. 2023

https://zenodo.org/records/8136161
[https://zenodo.org/records/8136161](https://zenodo.org/records/8136161)

Danum, Malaysia

### Cloutier et al. 2023

![sample_image](public/Cloutier_et_al._2023.png)
https://zenodo.org/records/8148479
[https://zenodo.org/records/8148479](https://zenodo.org/records/8148479)

Location: Quebec, Canada

### Firoze et al. 2023

https://openaccess.thecvf.com/content/CVPR2023/papers/Firoze_Tree_Instance_Segmentation_With_Temporal_Contour_Graph_CVPR_2023_paper.pdf
[https://openaccess.thecvf.com/content/CVPR2023/papers/Firoze_Tree_Instance_Segmentation_With_Temporal_Contour_Graph_CVPR_2023_paper.pdf](https://openaccess.thecvf.com/content/CVPR2023/papers/Firoze_Tree_Instance_Segmentation_With_Temporal_Contour_Graph_CVPR_2023_paper.pdf)

Indiana, United States

Expand All @@ -82,9 +86,9 @@ Indiana, United States

![sample_image](public/Jansen_et_al._2023.png)

Location: Northern Australia
[https://zenodo.org/records/7094916](https://zenodo.org/records/7094916)

https://zenodo.org/records/7094916
Location: Northern Australia

### Troles et al. 2024

Expand All @@ -94,9 +98,9 @@ Location: Bamberg, Germany

### Wagner et al. 2023

https://www.mdpi.com/2504-446X/7/3/155
[https://www.mdpi.com/2504-446X/7/3/155](https://www.mdpi.com/2504-446X/7/3/155)

Australia
https://www.mdpi.com/2072-4292/16/11/1935
[https://www.mdpi.com/2072-4292/16/11/1935](https://www.mdpi.com/2072-4292/16/11/1935)

![sample_image](public/Wagner_et_al._2023.png)
![sample_image](public/Wagner_et_al._2023.png)
Binary file added docs/public/Alejandro_Miranda.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6e5df52

Please sign in to comment.