DetecTree

DetecTree: Tree detection from aerial imagery in Python - Published in JOSS (2020)

https://github.com/martibosch/detectree

Science Score: 93.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 11 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

image-segmentation python remote-sensing tree-canopy tree-detection tree-pixels

Scientific Fields

Mathematics Computer Science - 84% confidence
Last synced: 4 months ago · JSON representation

Repository

Tree detection from aerial imagery in Python

Basic Info
Statistics
  • Stars: 267
  • Watchers: 6
  • Forks: 35
  • Open Issues: 6
  • Releases: 10
Topics
image-segmentation python remote-sensing tree-canopy tree-detection tree-pixels
Created over 6 years ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing License

README.md

PyPI version fury.io Conda Version Documentation Status tests pre-commit.ci status codecov GitHub license DOI DOI

DetecTree

Overview

DetecTree is a Pythonic library to perform semantic segmentation of aerial imagery into tree/non-tree pixels, following the methods of Yang et al. [1]. A pre-trained model is available at Hugging Face hub, which can be used as follows:

```python from urllib import request

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

download a tile from the SWISSIMAGE WMS

tileurl = ( "https://wms.geo.admin.ch/?SERVICE=WMS&REQUEST=GetMap&VERSION=1.3.0&" "FORMAT=image/png&LAYERS=ch.swisstopo.images-swissimage&CRS=EPSG:2056" "&BBOX=2532980,1152150,2533380,1152450&WIDTH=800&HEIGHT=600" ) tilefilename = "tile.png" request.urlretrieve(tileurl, tilefilename)

use the pre-trained model to segment the image into tree/non-tree-pixels

ypred = dtr.Classifier().predictimg(tile_filename)

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(tilefilename) as src: plot.show(src, ax=axes[0]) axes[1].imshow(ypred) ```

Pre-trained example

Alternatively, you can use detectree to train your own model on your aerial imagery dataset:

```python 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(imgdir='data/tiles') splitdf = ts.traintestsplit(method='cluster-I')

train a tree/non-tree pixel classifier

clf = dtr.ClassifierTrainer().trainclassifier( splitdf=splitdf, responseimgdir='data/responsetiles')

use the trained classifier to predict the tree/non-tree pixels

testfilepath = splitdf[~splitdf['train'].sample(1).iloc[0]['img_filepath'] ypred = dtr.Classifier(clf=clf).classifyimg(testfilepath)

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(imgfilepath) as src: plot.show(src.read(), ax=axes[0]) axes[1].imshow(ypred) ```

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 examples repository for more information on the background and some example notebooks.

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.

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:

bash conda install -c conda-forge detectree

With pip

You can install detectree with pip as in:

bash 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:

bash 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:

bash 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

bash git clone git@github.com: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:

bash 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.

Owner

  • Name: Martí Bosch
  • Login: martibosch
  • Kind: user
  • Location: Lausanne
  • Company: EPFL

Doctor in civil and environmental engineering. Urban sprawl, Python, and a bit of landscape ecology and complexity

JOSS Publication

DetecTree: Tree detection from aerial imagery in Python
Published
June 25, 2020
Volume 5, Issue 50, Page 2172
Authors
Martí Bosch ORCID
Urban and Regional Planning Community, École Polytechnique Fédérale de Lausanne, Switzerland
Editor
Kristen Thyng ORCID
Tags
tree detection image segmentation remote sensing images GIS

GitHub Events

Total
  • Create event: 4
  • Issues event: 2
  • Release event: 2
  • Watch event: 33
  • Issue comment event: 1
  • Push event: 74
  • Fork event: 5
Last Year
  • Create event: 4
  • Issues event: 2
  • Release event: 2
  • Watch event: 33
  • Issue comment event: 1
  • Push event: 74
  • Fork event: 5

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 130
  • Total Committers: 2
  • Avg Commits per committer: 65.0
  • Development Distribution Score (DDS): 0.008
Past Year
  • Commits: 41
  • Committers: 1
  • Avg Commits per committer: 41.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Martí Bosch m****h@p****m 129
Kristen Thyng k****g@g****m 1

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 13
  • Total pull requests: 21
  • Average time to close issues: 2 months
  • Average time to close pull requests: 6 days
  • Total issue authors: 9
  • Total pull request authors: 4
  • Average comments per issue: 2.92
  • Average comments per pull request: 0.43
  • Merged pull requests: 5
  • Bot issues: 0
  • Bot pull requests: 19
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: 3 months
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 1.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • rmsare (3)
  • MisterB92 (2)
  • easz (2)
  • jehontan (1)
  • ligaofeng0901 (1)
  • wittylife (1)
  • Ayushri (1)
  • tadolphi (1)
  • pedromarcolin (1)
Pull Request Authors
  • dependabot[bot] (15)
  • pre-commit-ci[bot] (4)
  • kthyng (1)
  • martibosch (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (15)

Packages

  • Total packages: 3
  • Total downloads:
    • pypi 815 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 4
    (may contain duplicates)
  • Total versions: 30
  • Total maintainers: 1
proxy.golang.org: github.com/martibosch/detectree
  • Versions: 13
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 3.8%
Forks count: 4.5%
Average: 4.9%
Dependent packages count: 5.4%
Dependent repos count: 5.7%
Last synced: 4 months ago
pypi.org: detectree

Tree detection from aerial imagery in Python.

  • Versions: 13
  • Dependent Packages: 0
  • Dependent Repositories: 3
  • Downloads: 815 Last month
Rankings
Stargazers count: 5.5%
Dependent packages count: 7.3%
Forks count: 7.6%
Dependent repos count: 9.1%
Average: 10.1%
Downloads: 20.9%
Maintainers (1)
Last synced: 4 months ago
conda-forge.org: detectree
  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Dependent repos count: 24.1%
Stargazers count: 31.4%
Forks count: 35.3%
Average: 35.6%
Dependent packages count: 51.5%
Last synced: 4 months ago

Dependencies

.github/workflows/release.yml actions
  • actions/checkout v4 composite
  • actions/download-artifact v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • heinrichreimer/github-changelog-generator-action v2.1.1 composite
  • pypa/gh-action-pypi-publish release/v1 composite
  • softprops/action-gh-release v1 composite
.github/workflows/tests.yml actions
  • actions/checkout v4 composite
  • codecov/codecov-action v3 composite
  • mamba-org/setup-micromamba v1 composite
pyproject.toml pypi
  • dask [delayed,distributed]
  • joblib *
  • laspy >= 2.0.0
  • numpy >= 1.15
  • opencv-python >= 4.0.0
  • pandas >= 0.23
  • pymaxflow >= 1.0.0
  • rasterio >= 1.0.0
  • scikit-image *
  • scikit-learn *
  • scipy >= 1.0.0
  • tqdm *
docs/requirements.txt pypi
  • m2r2 ==0.3.3
  • pydata-sphinx-theme ==0.15.2
  • sphinx ==7.2.6
  • sphinx_click ==5.01
  • sphinxcontrib.bibtex ==2.6.2