Dear
Ricardo and João,
It's been too long when this conversation happenned but now I am strating to work with usefull tool to perform OBIA based crop classification. I double-checked
my input data and nevertheless I'm still getting this error.
"> evalMatrix <- evalPerformanceClassifier(classifObj)
Error in evalPerformanceClassifier(classifObj) :
The input in obj must be an object of class SOptim.Classifier generated by calibrateClassifier with option runFullCalibration = TRUE!"
And here is my full code:
#--------------------------------------------------------------------------------------------------------------
"#1. Use image3 as referenceRaster
referenceRaster <- raster("C:/Users/gulni/img3.tif")
#2. Load or create other raster objects
rstTrainData <- raster("C:/Users/gulni/train8.tif")
rstSeg <- raster("C:/Users/gulni/00_segmentasyon/aso_1.tif")
image3 <- raster("C:/Users/gulni/img3.tif")
image4 <- raster("C:/Users/gulni/S2_06_NDVI.img")
image5 <- raster("C:/Users/gulni/S2_07_NDVI.img")
image6 <- raster("C:/Users/gulni/S2_08_NDVI.img")
image7 <- raster("C:/Users/gulni/S2_09_NDVI.img")
#3. Project other raster objects
rstTrainData_proj <- projectRaster(rstTrainData, referenceRaster)
rstSeg_proj <- projectRaster(rstSeg, referenceRaster)
image3_proj <- projectRaster(image3, referenceRaster)
image4_proj <- projectRaster(image4, referenceRaster)
image5_proj <- projectRaster(image5, referenceRaster)
image6_proj <- projectRaster(image6, referenceRaster)
image7_proj <- projectRaster(image7, referenceRaster)
classfeat <- stack(image7_proj,image6_proj,image5_proj,image4_proj,image3_proj)
plot(rstTrainData_proj)
# Prepare data before classification
# This will populate each segment with statistics of each one of the layers in rstClassifFeatures ------
#
?prepareCalData
calDataPrep <- prepareCalData( rstSegm = rstSeg_proj,
trainData = rstTrainData_proj,
rstFeatures = classfeat,
thresh = 0.5,
funs = "mean",
minImgSegm = 1,
bylayer = TRUE,
tiles = NULL,
verbose = TRUE,
progressBar = FALSE
)
# Check the generated datasets
head(calDataPrep$calData)
head(calDataPrep$classifFeatData)
unique(calDataPrep$calData$train)
evalPerf <- evalPerformanceClassifier(calDataPrep)
print(evalPerf)
# Run the final classification --------------------------------------------- ----------------------------
?calibrateClassifier
classifObj <- calibrateClassifier(calDataPrep,
classificationMethod = "RF",
classificationMethodParams = NULL,
balanceTrainData = FALSE,
balanceMethod = "ubOver",
evalMethod = "5FCV",
evalMetric = "Kappa",
minTrainCases = 30,
minCasesByClassTrain = 10,
minCasesByClassTest = 5,
runFullCalibration = TRUE,
verbose = TRUE
)
warnings()
# Get more evaluation measures
evalMatrix <- evalPerformanceClassifier(classifObj)
print(round(evalMatrix,2))
# Finally, predict the class label for the entire image (i.e., outside the training set)
# and also save the classified image
rstPredSegmRF <- predictSegments(classifierObj = RFclassif,
calData = calData,
rstSegm = segmRst,
predictFor = "all",
filename = outClassRst.path)
print(rstPredSegmRF)"
#--------------------------------------------------------------------------------------------------------------
I wonder if you can find a solution or different approach for this problem.
Thank you in advance,
Cheers,
Gulnihal KURT
PhD Researcher
Cukurova University
Adana, Turkey