Learn R Programming

uavRst (version 0.5-2)

calc_ext: Convenient function to preprocess synthetic raster bands from a given RGB image and/or DTM/DSM data.

Description

Convenient function to preprocess synthetic raster bands from a given RGB image and/or DTM/DSM data. Currently for all chanels of the input images the following textures and indices can be calculated: rgb indices (17), color transformation (9), haralick (3 = 25 layers), statitics (4),edge (3),morpho (4), DEM Parameter (20). All layers will be stacked (as an ENVI file). If wanted the raster values can be extracted to a data frames by overlaying corresponding vector data. NOTE: The vector data has to be named identically to the rasterfiles. This is useful for for classification training purposes and covers usually step 1 of the random forest based classification of UAV derived visible imagery and point clouds.

Usage

calc_ext(calculateBands = FALSE, extractTrain = TRUE,
  prefixRun = "temp", patterndemFiles = "dem", prefixTrainImg = "",
  prefixTrainGeom = "", suffixTrainImg = "", suffixTrainGeom = "",
  patternIdx = "index", patternImgFiles = "", channels = c("red",
  "green", "blue"), hara = TRUE, haraType = c("simple", "advanced",
  "higher"), stat = TRUE, edge = TRUE, edgeType = c("gradient",
  "sobel", "touzi"), morpho = TRUE, morphoType = c("dilate", "erode",
  "opening", "closing"), rgbi = TRUE, indices = c("VVI", "VARI",
  "NDTI", "RI", "SCI", "BI", "SI", "HI", "TGI", "GLI", "NGRDI", "GRVI",
  "GLAI", "HUE", "CI", "SAT", "SHP"), rgbTrans = TRUE,
  colorSpaces = c("CIELab", "CMY", "Gray", "HCL", "HSB", "HSI", "Log",
  "XYZ", "YUV"), pardem = TRUE, demType = c("hillshade", "slope",
  "aspect", "TRI", "TPI", "Roughness", "SLOPE", "ASPECT", "C_GENE",
  "C_PROF", "C_PLAN", "C_TANG", "C_LONG", "C_CROS", "C_MINI", "C_MAXI",
  "C_TOTA", "C_ROTO", "MTPI"), morphoMethod = 6, minScale = 1,
  maxScale = 8, numScale = 2, kernel = 3, currentDataFolder = NULL,
  currentIdxFolder = NULL, cleanRunDir = TRUE, giLinks = NULL)

Arguments

calculateBands

logical. switch for set on calculation of syntheic bands and indices default = TRUE

extractTrain

logical. switch for set on extract training data according to training geometries default = TRUE

prefixRun

character. general prefix of all result files of the current run default = "tmp"

patterndemFiles

character. mandantory if DEM data is processes. prefix of current DEM default = "dem"

prefixTrainImg

character. potential string of characters that is used in the beginning of a shape file prefixTrainImg_SHAPEFILENAME_suffixTrainImg

prefixTrainGeom

character. potential string of characters that is used in the beginning of a shape file prefixTrainGeom_SHAPEFILENAME_suffixTrainGeom

suffixTrainImg

character. potential string of characters that is used in the beginning of a shape file prefixTrainImg_SHAPEFILENAME_suffixTrainImg

suffixTrainGeom

character. potential string of characters that is used in the beginning of a shape file prefixTrainGeom_SHAPEFILENAME_suffixTrainGeom

patternIdx

character. code string that will concatenated to the filename to identify the index file

patternImgFiles

character. mandantory string that exist in ech imagefile to be processes

channels

character. channels to be choosed options are c("red", "green", "blue") default = c("red", "green", "blue")

hara

logical. switch for using HaralickTextureExtraction, default = TRUE.

haraType

character. hara options, default is c("simple"), other options are "advanced" "higher" "all". NOTE: "higher" takes a LOT of time

stat

logical. switch for using statistic default = TRUE the stas are mean,variance, curtosis, skewness

edge

logical. switch for using edge filtering default = TRUE

edgeType

character. edge options, default is c("gradient","sobel","touzi") all options are c("gradient","sobel","touzi")

morpho

logical. switch for using morphological filtering default = TRUE

morphoType

character. morphological options, default is c("dilate","erode","opening","closing") all options are ("dilate","erode","opening","closing")

rgbi

logical. switch for using rgbi index calcualtions default = TRUE

indices

character. RGB indices, default is c("VARI","NDTI","RI","CI","BI","SI","HI","TGI","GLI","NGRDI") all options are c("VVI","VARI","NDTI","RI","SCI","BI","SI","HI","TGI","GLI","NGRDI","GRVI","GLAI","HUE","CI","SAT","SHP")

rgbTrans

logical. switch for using color space transforming default = TRUE

colorSpaces

character. RGB colorspace transforming to default c("CIELab","CMY","Gray","HCL","HSB","HSI","Log","XYZ","YUV")

pardem

logical. switch for calculating dem parameter, default = FALSE

demType

character. ("hillshade","slope", "aspect","TRI","TPI","Roughness")

morphoMethod

numeric. saga morphometric method

minScale

numeric. in scale for multi scale TPI

maxScale

numeric. max scale for multi scale TPI

numScale

numeric. number of scale for multi scale TPI

kernel

numeric. size of kernel for filtering and statistics, default is 3

currentDataFolder

NULL folder to image (and shape) data

currentIdxFolder

NULL folder for saving the results

cleanRunDir

logical. TRUE logical switch for deleting the calculated tifs, default is TRUE

giLinks

list. GI tools cli paths

Details

(01) calc_ext() calculation of spectral indices, basic spatial statistics and textures and extracting of training values over all channels according to training data (02) ffs_train() training using random forest and the forward feature selection method startTrain=TRUE (03) calc_ext() with respect to the selected predictor variables you may calculate the requested channels for all rgb data that you want to predict. (04) prediction startPredict=TRUE

Examples

Run this code
# NOT RUN {
##- required packages
require(uavRst)
require(link2GI)

# create and check the links to the GI software
giLinks<-uavRst::linkAll()
if (giLinks$saga$exist & giLinks$otb$exist){
#'
##- create and set folders
##- please mind that the pathes are exported as global variables
paths<-link2GI::initProj(projRootDir = tempdir(),
                         projFolders = c("data/","data/ref/","output/","run/","las/"),
                         global = TRUE,
                         path_prefix = "path_")

##- clean runtime folder
unlink(paste0(path_run,"*"), force = TRUE)

##- get the tutorial data
utils::download.file("https://github.com/gisma/gismaData/raw/master/uavRst/data/tutorial_data.zip",
                     paste0(path_run,"tutorial_data.zip"))
unzip(zipfile = paste0(path_run,"tutorial_data.zip"), exdir = R.utils::getAbsolutePath(path_run))

##- calculate some synthetic channels from the RGB image and the canopy height model
##- then extract the from the corresponding training geometries the data values aka trainingdata
trainDF <- calc_ext(calculateBands    = TRUE,
                    extractTrain      = TRUE,
                    suffixTrainGeom   = "",
                    patternIdx        = "index",
                    patternImgFiles   = "rgb" ,
                    patterndemFiles   = "chm",
                    prefixRun         = "tutorial",
                    prefixTrainImg    = "",
                    rgbi              = TRUE,
                    indices           = c("TGI","CI"),
                    channels          = c("red"),
                    rgbTrans          = FALSE,
                    hara              = FALSE,
                    haraType          = c("simple"),
                    stat              = FALSE,
                    edge              = FALSE,
                    morpho            = FALSE,
                    pardem            = TRUE,
                    demType           = c("slope", "MTPI"),
                    kernel            = 3,
                    currentDataFolder = path_run,
                    currentIdxFolder  = path_run,
                    giLinks = giLinks)

##- show the result
head(trainDF)
# use ffs_train as next step for rf classification issues
}
##+
# }

Run the code above in your browser using DataLab