I'm trying to classify 10cm-resolution images with the RF-package.
I do this to separate some species in the forest, seen on my images.
While I was searching for an answer, I found the following code, bit I don't understand why the images have to be transformed into point-shapes, so I'm looking for a way to perform a RF-classification just with Raster (*tif, *png).
The code I found (made by Mr. Evans):
require(sp) require(rgdal) require(raster) require(randomForest) # CREATE LIST OF RASTERS rlist=list.files(getwd(), pattern="img$", full.names=TRUE) # CREATE RASTER STACK xvars <- stack(rlist) # READ POINT SHAPEFILE TRAINING DATA sdata <- shapefile("inshape.shp") # ASSIGN RASTER VALUES TO TRAINING DATA v <- data.frame(extract(xvars, sdata)) # RUN RF MODEL ## assumeing that sdata has a variable called 'train' with e.g. 0 and 1 values rf.mdl <- randomForest(x=v, y=as.factor(sdata$train)) ## or for regression: rf2 <- randomForest(x=v, y=sdata$train) # CHECK ERROR CONVERGENCE plot(rf.mdl) # PLOT mean decrease in accuracy VARIABLE IMPORTANCE varImpPlot(rf.mdl, type=1) # PREDICT MODEL predict(xvars, rf.mdl, filename="RfClassPred.img", type="response", index=1, na.rm=TRUE, progress="window", overwrite=TRUE)
At "Read Point Shapefile Training Data", why can't I use just raster? I don't get the "jump" to point-shape
In my understanding, I need to create a raster-stack and some training-areas, which are imported as raster's as well. Then I perform rf-classification and plot the results.
Am I right?