-
Notifications
You must be signed in to change notification settings - Fork 2
/
3_Classification.R
126 lines (100 loc) · 5.12 KB
/
3_Classification.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
################################################################################
## R-Script - 3_Classification_CanopyLevel.R ##
## author: Javier Lopatin ##
## mail: [email protected] ##
## ##
## Manuscript: Mapping plant species in mixed grassland communities using ##
## close range imaging spectroscopy ##
## ##
## description: Classification procidure for canopy-level spectras ##
## ##
################################################################################
library(raster)
home = "D:/Sp_Images"
setwd(home)
#load("Class_Canopy.RData")
## load the data
potVal_spec <- read.table("Data/potVal_spec.csv", sep = ",", header = T)
rf_spec <- read.table("Data/rf_spec.csv", sep = ",", header = T)
potVal_spec_BN <- read.table("Data/potVal_spec_BN.csv", sep = ",", header = T)
rf_spec_BN <- read.table("Data/rf_spec_BN.csv", sep = ",", header = T)
potVal_MNF <- read.table("Data/potVal_MNF.csv", sep = ",", header = T)
rf_MNF <- read.table("Data/rf_MNF.csv", sep = ",", header = T)
potVal_MNF_BN <- read.table("Data/potVal_MNF_BN.csv", sep = ",", header = T)
rf_MNF_BN <- read.table("Data/rf_MNF_BN.csv", sep = ",", header = T)
potVal_GLCM <- read.table("Data/potVal_GLCM.csv", sep = ",", header = T)
rf_GLCM <- read.table("Data/rf_GLCM.csv", sep = ",", header = T)
potVal_GLCM_BN <- read.table("Data/potVal_GLCM_BN.csv", sep = ",", header = T)
rf_GLCM_BN <- read.table("Data/rf_GLCM_BN.csv", sep = ",", header = T)
# wavelength
wl <- c( 398, 407, 415, 424, 432, 441, 450, 459, 468, 477, 486, 495, 504, 513, 522, 531, 540, 550, 558, 568,
577, 587, 596, 605, 615, 624, 633, 643, 652, 661, 671, 680, 690, 699, 708, 717, 727, 736, 746, 755,
765, 775, 784, 794, 803, 813, 822, 832, 842, 851, 861, 870, 880, 890, 899, 908, 918, 928, 937, 947, 957)
# load species cover dataset
species <- read.table("Data/Plots_Species.csv", header = T, sep=",")
#### Source Functions from GitHub
source_github <- function(u) {
# load package
require(RCurl)
# read script lines from website and evaluate
script <- getURL(u, ssl.verifypeer = FALSE)
eval(parse(text = script), envir=.GlobalEnv)
detach("package:RCurl", unload=TRUE)
}
source_github("https://raw.githubusercontent.com/JavierLopatin/Grassland-Species-Classification/master/0_Functions.R")
## load plot images
raster_spec <- rasterList(fileExtantion = ".tif", folder = "Plots/Plots_spec", dir=home)
r <- stack( paste0(home, "/Plots/Plots_spec/plot_17.dat") )
raster_spec[[11]] <- r; names(raster_spec) <- c("plot_10", "plot_11", "plot_12", "plot_13", "plot_14", "plot_15",
"plot_16", "plot_18", "plot_19", "plot_9", "plot_17")
raster_spec_BN <- rasterList(fileExtantion = ".tif", folder = "Plots/Plots_spec_BN", dir=home)
raster_MNF <- rasterList(fileExtantion = ".tif", folder = "Plots/Plots_MNF", dir=home)
raster_MNF_BN <- rasterList(fileExtantion = ".tif", folder = "Plots/Plots_MNF_BN", dir=home)
raster_GLCM <- rasterList(fileExtantion = ".tif", folder = "Plots/Plots_GLCM", dir=home)
raster_GLCM_BN <- rasterList(fileExtantion = ".tif", folder = "Plots/Plots_GLCM_BN", dir=home)
##########################
### Run Classification ###
##########################
setwd(home)
save.image("Class_Canopy.RData")
subplotDir = "C:/Users/Lopatin/Dropbox/PhD/Grass_single_spp_segmentation/Single_spp/subplots"
#------------------------#
# Spectra #
#------------------------#
ApplyModels(valData = species,
potVal = potVal_spec,
rf = rf_spec,
raster_List = raster_spec,
wl = wl,
modelTag = "spect",
boots = 100)
#-------------------------------------#
# Spectra w/ brightness normalization #
#-------------------------------------#
ApplyModels(valData = species,
potVal = potVal_spec_BN,
rf = rf_spec_BN,
raster_List = raster_spec_BN,
wl = wl,
modelTag = "spect_BN",
boots = 100)
#------------------------#
# MNF #
#------------------------#
ApplyModels(valData = species,
potVal = potVal_MNF,
rf = rf_MNF,
raster_List = raster_MNF,
wl = seq(1,10,1),
modelTag = "MNF",
boots = 100)
#---------------------------------#
# MNF w/ brightness normalization #
#---------------------------------#
ApplyModels(valData = species,
potVal = potVal_MNF_BN,
rf = rf_MNF_BN,
raster_List = raster_MNF_BN,
wl = seq(1,10,1),
modelTag = "MNF_BN",
boots = 100)