• Stars
    star
    168
  • Rank 225,507 (Top 5 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 5 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tree detection from aerial imagery in Python

PyPI version fury.io Conda Version Documentation Status Build Status codecov GitHub license DOI DOI

DetecTree

Overview

DetecTree is a Pythonic library to classify tree/non-tree pixels from aerial imagery, following the methods of Yang et al. [1]. The target audience is researchers and practitioners in GIS that are interested in two-dimensional aspects of trees, such as their proportional abundance and spatial distribution throughout a region of study. These measurements can be used to assess important aspects of urban planning such as the provision of urban ecosystem services. The approach is of special relevance when LIDAR data is not available or it is too costly in monetary or computational terms.

import detectree as dtr
import matplotlib.pyplot as plt
import rasterio as rio
from rasterio import plot

# select the training tiles from the tiled aerial imagery dataset
ts = dtr.TrainingSelector(img_dir='data/tiles')
split_df = ts.train_test_split(method='cluster-I')

# train a tree/non-tree pixel classfier
clf = dtr.ClassifierTrainer().train_classifier(
    split_df=split_df, response_img_dir='data/response_tiles')

# use the trained classifier to predict the tree/non-tree pixels
test_filepath = split_df[~split_df['train'].sample(1).iloc[0]['img_filepath']
y_pred = dtr.Classifier().classify_img(test_filepath, clf)

# side-by-side plot of the tile and the predicted tree/non-tree pixels
figwidth, figheight = plt.rcParams['figure.figsize']
fig, axes = plt.subplots(1, 2, figsize=(2 * figwidth, figheight))

with rio.open(img_filepath) as src:
    plot.show(src.read(), ax=axes[0])
axes[1].imshow(y_pred)

Example

A full example application of DetecTree to predict a tree canopy map for the Aussersihl district in Zurich is available as a Jupyter notebook. See also the API reference documentation and the example repository for more information on the background and some example notebooks.

Citation

Bosch M. 2020. “DetecTree: Tree detection from aerial imagery in Python”. Journal of Open Source Software, 5(50), 2172. doi.org/10.21105/joss.02172

Note that DetecTree is based on the methods of Yang et al. [1], therefore it seems fair to reference their work too. An example citation in an academic paper might read as follows:

The classification of tree pixels has been performed with the Python library DetecTree (Bosch, 2020), which is based on the approach of Yang et al. (2009).

Installation

With conda

The easiest way to install detectree is with conda as in:

conda install -c conda-forge detectree

With pip

You can install detectree with pip as in:

pip install detectree

If you want to be able to read compressed LAZ files, you will need the Python bindings for laszip. Note that the latter require [laszip], which can be installed using conda (which is automatically handled when installing detectree with conda as shown above) or downloaded from laszip.org. Then, detectree and the Python bindings for laszip can be installed with pip as in:

pip install detectree[laszip]

Development install

To install a development version of detectree, you can first use conda to create an environment with all the dependencies - with the environment-dev.yml file - and activate it as in:

conda env create -f environment-dev.yml
conda activate detectree-dev

and then clone the repository and use pip to install it in development mode

git clone [email protected]:martibosch/detectree.git
cd detectree/
pip install -e .

This will also install the dependencies required for running tests, linting the code and building the documentation. Additionally, you can activate pre-commit so that the latter are run as pre-commit hooks as in:

pre-commit install

See also

Acknowledgments

  • With the support of the École Polytechnique Fédérale de Lausanne (EPFL)

References

  1. Yang, L., Wu, X., Praun, E., & Ma, X. (2009). Tree detection from aerial imagery. In Proceedings of the 17th ACM SIGSPATIAL International Conference on Advances in Geographic Information Systems (pp. 131-137). ACM.

More Repositories

1

pylandstats

Computing landscape metrics in the Python ecosystem
Python
67
star
2

pylandstats-notebooks

Example notebooks of the PyLandStats library
Jupyter Notebook
18
star
3

lausanne-heat-islands

Simulation of urban heat islands in Lausanne with the InVEST urban cooling model
Jupyter Notebook
15
star
4

lausanne-tree-canopy

Tree canopy map of Lausanne in 2016 at a 1m resolution
Python
12
star
5

urban-footprinter

A convolution-based approach to detect urban extents from raster datasets
Python
12
star
6

detectree-examples

Example computational workflows to classify tree/non-tree pixels in Zurich using DetecTree
Jupyter Notebook
11
star
7

swiss-urbanization

Materials to reproduce the paper "Spatiotemporal patterns of urbanization in three Swiss urban agglomerations: insights from landscape metrics, growth modes and fractal analysis"
Jupyter Notebook
7
star
8

pystream

Python implementation of the STREAM hydrological rainfall-runoff model
Python
6
star
9

lausanne-greening-scenarios

Evaluation of urban greening for heat mitigation in Lausanne
Jupyter Notebook
3
star
10

snakemacs

emacs28 setup for Python with conda/mamba
Emacs Lisp
2
star
11

jupyter-emacs-post

Example notebook used in the "Jupyter in the Emacs universe" post
Jupyter Notebook
2
star
12

cookiecutter-data-snake

Reproducible data science template using Python, snakemake, mamba and more 🐍
Python
2
star
13

netatmo-geopy

Pythonic package to access Netatmo CWS data.
Python
1
star
14

swiss-urbanization-post

Materials to reproduce the blog post of https://martibosch.github.io/managing-analysis-workflows-geodata-make/
Jupyter Notebook
1
star
15

invest-ucm-calibration

Automated calibration of the InVEST urban cooling model with simulated annealing
Python
1
star
16

martibosch.github.io

Personal page
Jupyter Notebook
1
star
17

pystream-example

Example simulation with the PySTREAM library
Jupyter Notebook
1
star
18

django-doge-app

Example Django app using the Doge workflow
Python
1
star
19

agrometeo-geopy

Pythonic interface to access agrometeo.ch data
Python
1
star
20

carbon-sequestration-vaud

Evaluation of the carbon sequestation for the canton of Vaud
Jupyter Notebook
1
star