forked from xime377/RedEdge-calibration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7.Vegetation ind calc.R
65 lines (42 loc) · 1.24 KB
/
7.Vegetation ind calc.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
#Set WD
#setwd("H:/Ximena/MSc Thesis/Results")
setwd("D:/Google Drive/MSc Thesis/Results")
###Load libraries
#library(pacman)
#pacman::p_load(agricolae, Rmisc) To install several packages at the same time
library(raster)
#Load functions
devtools::load_all("VegIndx")
##Load orthomosaics
O1<- stack("./UAV imagery/Lonnstorp/2017_04_08/Agisoft/Flight_2/Orthomosaic/Lonnstorp_08_04_2017_2_ReflectanceT.tif")
##Calculate vegetation indices
#TCARI/OSAVI
tcariOsavi<-TCARI.OSAVI(O1)
names(tcariOsavi)<-"TCARI/OSAVI"
#GI
gi<-GI(O1)
names(gi)<-"GI"
#NDVI
ndvi<-NDVI(O1)
names(ndvi)<-"NDVI"
#NDRe
ndrei<-NDRe(O1)
names(ndrei)<-"NDRe"
#Evi
evi<-EVI(O1)
names(evi)<-"EVI"
#Group VI
VI.list<-ls(pattern="i")
VI<-lapply(VI.list,get)
names(VI)<-VI.list
#Vizualise all together
par(mfrow=c(3,2),
oma = c(5,4,0,0) + 0.1,
mar = c(0,0,1,1) + 0.1)
for (i in 1:length(VI))
{plot(VI[[i]], main=names(VI[[i]]))}
plotRGB(O1, r=3, g=2, b=1, 65535, colNA='white') #PlotRGB
#Save them as raster
for (i in 1:length(VI))
writeRaster(VI[[i]], paste0("./UAV imagery/Lonnstorp/2017_04_08/VI/Flight_2/Lonnstorp_08_04_2017_2_",
names(VI[i]),".tif"), overwrite=T)