fCover: Fractional Cover Analysis

View source: R/fCover.R

fCoverR Documentation

Fractional Cover Analysis


fCover takes a classified high resolution image, e.g. vegetation and non-vegetation based on Landsat and calculates cover fractions for pixels of a coarser resolution, e.g. MODIS.


  nSamples = 1000,
  classes = 1,
  model = "rf",
  tuneLength = 3,
  method = "cv",
  maxNA = 0,
  clamp = TRUE,
  filename = NULL,



high resolution RasterLayer containing a landcover classification, e.g. as obtained by superClass.


coarse resolution RasterLayer for which fractional cover will be estimated.


Integer. Number of pixels to sample from predImage to train the regression model


Integer. Classes for which fractional cover should be estimated (one or more).


Character. Which model to fit for image regression. See train for options. Defaults to randomForest ('rf')


Integer. Number of levels for each tuning parameters that should be generated by train. See Details and train.


Character. Resampling method for parameter tuning. Defaults to 10 fold cross-validation. See trainControl for options.


Numeric. Maximal proportion of NAs allowed in training pixels.


Logical. Enforce results to stay within [0,1] interval. Values <0 are reset to 0 and values >1 to 1.


Character. Filename of the output raster file (optional).


Logical. Print progress information.


further arguments to be passed to trainControl and writeRaster


fCover gets the pixel values in a high resolution classified image that correspond to randomly selected moderate resolution pixels and then calculates the percent of the classified image pixels that represent your cover type of interest. In other words, if your high resolution image has a pixel size of 1m and your moderate resolution image has a pixel size of 30m the sampling process would take a block of 900 of the 1m resolution pixels that correspond to a single 30m pixel and calculate the percentage of the 1m pixels that are forest. For example, if there were 600 forest pixels and 300 non-forest pixels the value given for the output pixel would be 0.67 since 67

fCover relies on the train() function from the caret package which provides access to a huge number of classifiers. Please see the available options at train. The default classifier (randomForest) we chose has been shown to provide very good results in image regression and hence it is recomended you start with this one. If you choose a different classifier, make sure it can run in regression mode.

Many models require tuning of certain parameters. Again, this is handled by train from the caret package. With the tuneLength argument you can specify how many different values of each tuning parameter should be tested. The Random Forest algorithm for example can be tuned by varying the mtry parameter. Hence, by specifying tuneLength = 10, ten different levels of mtry will be tested in a cross-validation scheme and the best-performing value will be chosen for the final model.

If you register a parallel backend before, model fitting will run in parallel.

If the total no-data values for a block of high resolution pixels is greater than maxNA then it will not be included in the training data set since there is too much missing data to provide a reliable cover percentage. If the no-data proporton is less then maxNA the no-data pixels are removed from the total number of pixels when calculating the percent cover.


Returns a list with two elements: models contains the fitted models evaluated in tenfold cross-validation (caret train objects); fCover contains a RasterStack with a fractional cover layer for each requested class.

See Also



## Create fake input images
lsat <- rlogo
agg.level <- 9
modis <- aggregate(lsat, agg.level)

## Perform classification
lc      <- unsuperClass(lsat, nClass=2)

## Calculate the true cover, which is of course only possible in this example, 
## because the fake corse resolution imagery is exactly res(lsat)*9
trueCover <- aggregate(lc$map, agg.level, fun = function(x, ...){sum(x == 1, ...)/sum(!is.na(x))})

## Run with randomForest and support vector machine (radial basis kernel)
## Of course the SVM is handicapped in this example due to poor tuning (tuneLength)
for(model in c("rf", "svmRadial")){
   fc <- fCover(
           classImage = lc$map ,
           predImage = modis,
           nSample = 50,
           number = 5,
   ## How close is it to the truth?
   compare.rf <- trueCover - fc$map
   plot(fc$map, main = paste("Fractional Cover: Class 1\nModel:", model))
   plot(compare.rf, main = "Diffence\n true vs. predicted")
   plot(trueCover[],fc$map[],  xlim = c(0,1), ylim =c(0,1),
           xlab = "True Cover", ylab = "Predicted Cover" )
   rmse <- sqrt(cellStats(compare.rf^2, sum))/ncell(compare.rf)
   r2 <- cor(trueCover[], fc$map[], "complete.obs")
                           round(c(rmse, r2),3)),collapse="\n"), adj=1)

## Reset par

RStoolbox documentation built on March 18, 2022, 5:37 p.m.