I have used the command
library(SegOptim) and it worked. Everything is working but taking too long to process.
Here is the code. Sorry I am still learning how to publish projects in GitHUB so at the moment I copy and paste here:
# ----- INSTALL THE PACKAGE SEGOPTIM---- ##
#PROTOCOL: First, install remotes to conect to GitHUB
#Check if devtools package is installed and install it if not
if(!requireNamespace("remotes")){
install.packages("remotes")
}
# Run the installation, from repository in GitHub . I have chosen ALL installation
#
remotes::install_github("joaofgoncalves/SegOptim")
## ----- END OF INSTALLATION OF PACKAGE SEGOPTIM---- ##
##Calling libraries
library(SegOptim)
library(tools)
library(raster)
library(rgdal)
library(rgeos)
library(sp)
library(RColorBrewer)
library(pillar)
library(cli)
library(vctrs)
library(rprojroot)
library(rstudioapi)
#Remove existing variables
rm(list = ls())
# A function providing CLI access to TerraLib 5 Baatz-Shcape segmentation
##and optimize its parameters using genetic algorithms.
#HELP: ??segmentation_Terralib_Baatz
##Create multi layered Raster (input bands)
allBands <- list.files("Route to rasters",pattern = "tif$",full.names = TRUE)
#1. stack bands and save them
stackBands <- stack(allBands)
writeRaster(stackBands, filename = "Route to stack bands/stack.tif")
ImgSegment <- segmentation_Terralib_Baatz(
c(5,3,20,500),
"
Route to stack bands/stack.tif ",
outputSegmRst = "Output/segmentation.tif",
CompactnessWeight = NULL,
SpectralWeight = NULL,
Threshold = NULL,
MinSize = NULL, # Minimum size of 8 because our training samples have 8 pixels (Pol -> Ras)
verbose = TRUE, # I want to see messages
TerraLib.path = "C:/terralib-5.2.1-TISA-win_x64/terralib-5.2.1-TISA/lib" #input for argument path
)
# Check out the result
rstSegm <- raster(ImgSegment$segm)
print(rstSegm)
plot(rstSegm)
I am doing a first teste with those arguments of x. Perhaps it is why it is going so slow.
Thank you.