Commit f42ce606 authored by Monnet Jean-Matthieu's avatar Monnet Jean-Matthieu
Browse files

Minor changes to gaps.edges.detection

parent 3639eeb0
This diff is collapsed.
......@@ -19,19 +19,7 @@ knitr::opts_chunk$set(fig.align = "center")
---
This tutorial presents R code for forest gaps and edges detection from Airborne Laser Scanning (ALS) data. The workflow is based on functions from packages `lidaRtRee` and `lidR`.
Licence: CC BY / Source page
Changelog
* Jan 2021: updated to comply with lidR 3.1.0 and lidaRtRee 3.0.0
+ Oct 2020: checked compatibility with lidR 3.0.3
+ May 2020: added edge detection
+ Feb 2019: updated for compatibilty with package lidR 2.0.0 and lidaRtRee 2.0.0
+ June 2018: first version
```{r include = FALSE}
library(lidR)
```
Licence: CC BY / [Source page](https://gitlab.irstea.fr/jean-matthieu.monnet/lidartree_tutorials/-/blob/master/gap.edges.detection.Rmd)
## Study area and ALS data
......@@ -58,23 +46,24 @@ chm <- lidaRtRee::points2DSM(las, 1, centre[1]-size, centre[1]+size, centre[2]-s
If the CHM has been previously calculated.
```{r loadals, include = TRUE}
# load dataset
load(file="./data.gapDetection/chm.rda")
# load dataset
load(file="./data/gap.detection/chm.rda")
```
Missing, low and high values are replaced for better visualisation and processing.
Missing, low and high values are replaced for better visualization and processing.
```{r checkchm, include = TRUE, out.width='70%', fig.width = 9, fig.height = 4.5}
# replace NA by 0
chm[is.na(chm)] <- 0
# replace NA by 0 # raster::values to avoid error in knitr, otherwise use:
# chm[is.na(chm[])] <- 0
raster::values(chm)[is.na(raster::values(chm))] <- 0
# replace negative values by 0
chm[chm<0] <- 0
chm[chm[]<0] <- 0
# set maximum threshold at 50m
chm[chm>50] <- 50
# display CHM and areas where vegetation height is lower than 1m
par(mfrow=c(1,2))
raster::plot(chm, main="CHM")
raster::plot(chm<1, asp=1, main="CHM <1m")
raster::plot(chm<1, asp=1, main="CHM < 1m", legend = FALSE)
```
## Gap detection
......@@ -82,7 +71,9 @@ raster::plot(chm<1, asp=1, main="CHM <1m")
Gaps will be detected according to two different sets of criteria:
1. Vegetation height lower than 1 m, distance to surrounding vegetation larger than 0.5 times vegetation height and minimum gap surface of 100 m^2^.
2. Vegetation height lower than 1m, and no restrictions on distance to surrounding vegetation and surface.
2. Vegetation height lower than 1 m, and no restrictions on distance to surrounding vegetation and surface.
The procedure of gap detection is exemplified in @Glad20.
```{r gaps, include = TRUE, fig.width = 6.5, fig.height = 6, warning=FALSE}
# Perform gap detection with gap width criterion
......@@ -128,7 +119,7 @@ head(gaps.df, n=3)
Hmisc::Ecdf(log(gaps.df$surface), weights=gaps.df$surface, xlab="log(surface)")
```
Histogram can be used to compare the distribution of surface in different classes of gap surface. For better visualization of the differences between the set of criteria, large gaps are not taken into account.
Histogram can be used to compare the distribution of surface in different classes of gap surface. For better visualization of the differences between the set of criteria, gaps bigger than 500 m^2^ are not taken into account.
```{r gapsstats2, include = TRUE, out.width = '60%', fig.dim=c(5.5, 4.5) }
# extract vector of total gap surface of pixel
......@@ -143,7 +134,7 @@ hist(surface1, border="red", col="red",density=30,add=TRUE)
legend("topright", c("1", "2"), fill=c("red", "blue"))
```
## Edge detection
## Edges detection
In the previous part, a pixel that fulfills the maximum height criterion but does not fulfill the distance ratio criterion (i.e. it is too close to surrounding vegetation based on the distance / vegetation height ratio) is removed from gap surface. For edge detection, it seems more appropriate to integrate those pixels in the gap surface, otherwise some edges would be detected inside flat areas. The difference is exemplified in the following plots. The second image exhibits more gaps, because some gaps which are not reconstructed do not reach the minimum surface. The gaps in the second image are also larger, because gaps extend to all neighboring pixels complying with the height threshold, even if they do not comply with the distance criterion.
......@@ -178,3 +169,5 @@ raster::plot(edgeInside, main="Edges (detection by erosion)", legend=FALSE)
raster::plot(edgeOutside, main="Edges (detection by dilation)", legend=FALSE)
```
Percentage of edges can be calculated as the ratio between edge pixels surface and total surface, multiplied by 100. The result is dependent on the raster resolution. Obtained percentage for the "erosion" method is `r round(sum(raster::values(edgeInside))/(nrow(edgeInside)*ncol(edgeInside))*100, 1)`, whereas it is `r round(sum(raster::values(edgeOutside))/(nrow(edgeOutside)*ncol(edgeOutside))*100, 1)` for method "dilation".
## References
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment