Commit f393c481 authored by Monnet Jean-Matthieu's avatar Monnet Jean-Matthieu

rastZonalStats function added, code removed from segmentation, possibility to...

rastZonalStats function added, code removed from segmentation, possibility to perform detection and segmentation on dsm instead of chm. Still one bug to correct.
parent de8430e5
......@@ -39,6 +39,7 @@ export(rasterChullMask)
export(rasterLocalmax)
export(rasterMetrics)
export(rasterXYMask)
export(rasterZonalStats)
export(rasters2Cor)
export(rastersMovingCor)
export(segAdjust)
......
This diff is collapsed.
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tree.detection.R
\name{rasterZonalStats}
\alias{rasterZonalStats}
\title{Image statistic in segment}
\usage{
rasterZonalStats(segms, dem.nl, fun = max)
}
\arguments{
\item{segms}{cimg or rasterLayer object. image with segments id (e.g. from \code{\link{segmentation}})}
\item{dem.nl}{cimg or rasterLayer object. image to compute statistic from}
\item{fun}{function to compute statistis from values in each segment}
}
\value{
A cimg object or raster object with values of the statistic
}
\description{
compute zonal statistic of an image
}
\examples{
data(chmchablais3)
# median filter
chmchablais3 <- demFiltering(chmchablais3, nlFilter="Median", nlSize=3, sigmap=0)$non.linear.image
# maxima detection
maxi <- maximaDetection(chmchablais3)
# segmentation
seg.maxi <- segmentation(maxi, chmchablais3)
# compute image of maximum value in each segment
max.in.segment <- rasterZonalStats(seg.maxi, chmchablais3)
\dontrun{
# plot original image
plot(chmchablais3, main="Median filter")
# plot segments and image of max value inside segments
seg.maxi[seg.maxi==0] <- NA
plot(seg.maxi \%\% 8, main="Segments", col=rainbow(8))
plot(max.in.segment, main="Max value in segment")}
}
\seealso{
\code{\link{segmentation}}
}
......@@ -39,17 +39,23 @@ selected.maxi <- maximaSelection(maxi, chmchablais3, dm=1, dprop=0.1)
# segmentation
seg.selected.maxi <- segmentation(selected.maxi, chmchablais3)
# max value in segments
max.in.segment <- rasterZonalStats(seg.selected.maxi, chmchablais3)
# segmentation modification
seg.modif1 <- segAdjust(seg.selected.maxi$id, seg.selected.maxi$maxvalue,
seg.modif1 <- segAdjust(seg.selected.maxi, max.in.segment,
chmchablais3, prop=0.5)
seg.modif2 <- segAdjust(seg.selected.maxi$id, seg.selected.maxi$maxvalue,
seg.modif2 <- segAdjust(seg.selected.maxi, max.in.segment,
chmchablais3, prop=0, min.value=5, min.maxvalue=10)
\dontrun{
# plot initial segmented image
plot(seg.selected.maxi$id \%\% 8, main="Initial segments")
plot(seg.modif1 \%\% 8, main="Modified segments 1")
plot(seg.modif2 \%\% 8, main="Modified segments 2")}
seg.selected.maxi[seg.selected.maxi==0] <- NA
plot(seg.selected.maxi \%\% 8, main="Initial segments", col=rainbow(8))
seg.modif1[seg.modif1==0] <- NA
plot(seg.modif1 \%\% 8, main="Modified segments 1", col=rainbow(8))
seg.modif2[seg.modif2==0] <- NA
plot(seg.modif2 \%\% 8, main="Modified segments 2", col=rainbow(8))}
}
\seealso{
......
......@@ -12,36 +12,10 @@ segmentation(maxi, dem.nl)
\item{dem.nl}{cimg or rasterLayer object. image for seed propagation (typically initial image used for maxima detection).}
}
\value{
A list of 2 cimg object or RasterStack object with image of segments id and image of maximum value in segment)
A cimg object or rasterlayer object with segments id
}
\description{
performs a seed-based watershed segmentation and outputs two images: one with segment id and one where the segments are filled with the highest value of the segment in the initial image
}
\examples{
data(chmchablais3)
# median filter
chmchablais3 <- demFiltering(chmchablais3, nlFilter="Median", nlSize=3, sigmap=0)$non.linear.image
# maxima detection
maxi <- maximaDetection(chmchablais3)
# maxima selection
selected.maxi <- maximaSelection(maxi, chmchablais3, dm=1, dprop=0.1)
# segmentation
seg.maxi <- segmentation(maxi, chmchablais3)
seg.selected.maxi <- segmentation(selected.maxi, chmchablais3)
\dontrun{
# plot original image
plot(chmchablais3, main="Median filter")
# plot segmented image
plot(seg.maxi$id \%\% 8, main="Segments, no maxima selection")
plot(seg.selected.maxi$id \%\% 8, main="Segments, maxima selection")
plot(seg.selected.maxi$maxvalue, main="Max value in segment, maxima selection")}
performs a seed-based watershed segmentation (wrapper for imager::watershed)
}
\seealso{
\code{\link{maximaDetection}}, \code{\link{maximaSelection}}, \code{\link{segAdjust}}
......
......@@ -6,10 +6,10 @@
\usage{
treeSegmentation(dem, nlFilter = "Closing", nlSize = 5, sigma = 0.3,
dmin = 0, dprop = 0.05, hmin = 5, crownProp = 0.3,
crownMinH = 2)
crownMinH = 2, dtm = NULL)
}
\arguments{
\item{dem}{raster object or string indicating location of raster file (typically a canopy height model)}
\item{dem}{raster object or string indicating location of raster file (typically a canopy height model or a digital surface model; in the latter case the dtm parameter should be provided)}
\item{nlFilter}{string. specifies the non-linear filter for image pre-processing, should be an option of function \code{\link{demFiltering}}}
......@@ -26,6 +26,8 @@ treeSegmentation(dem, nlFilter = "Closing", nlSize = 5, sigma = 0.3,
\item{crownProp}{numeric. minimum height of tree crown as proportion of treetop height}
\item{crownMinH}{numeric. minimum crown height}
\item{dtm}{raster object or string indicating location of raster file with the terrain model. If provided, the maxima extraction and watershed segmentation are performed on the dem (this avoids the deformation of crown because of the normalisation with terrain), but maxima selection and segment adjustement are performed on 'dem-dtm' because the selection criteria is the height to terrain.}
}
\value{
A RasterStack with 4 layers: selected local maxima (values = distance to higher pixel), segments, non-linear preprocessed dem, smoothed preprocessed dem
......@@ -49,11 +51,11 @@ plot(segments$local.maxima, main="Local maxima")
#
# replace segment with id 0 (not a tree) with NA
segments$segments.id[segments$segments.id==0] <- NA
plot(segments$segments.id \%\% 8 , main="Segments")
plot(segments$segments.id \%\% 8 , main="Segments", col=rainbow(8))
#
# plot segmentation with other parameters
segments2$segments.id[segments2$segments.id==0] <- NA
plot(segments2$segments.id \%\% 8, main="Segments2")}
plot(segments2$segments.id \%\% 8, main="Segments2", col=rainbow(8))}
}
\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