Created
December 15, 2022 02:36
-
-
Save sarajoha/ab17847f1423289127edc86c0d5e9b4d to your computer and use it in GitHub Desktop.
Tasseled Caps indexes for Sentinel 2 in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://geoinnova.org/blog-territorio/calculo-de-tasseled-cap-para-imagenes-sentinel-2-con-r/ | |
# install libraries | |
install.packages("raster") | |
# load libraries | |
library("raster") | |
# Set your working directory | |
setwd("your_directory") | |
# load your image in .tif format. I used a Sentinel 2 image | |
s2 <- stack("image.tif") | |
#Tasselled Cap - brightness | |
BRI <- 0.3510*s2$B2 + 0.3813*s2$B3 + 0.3437*s2$B4+ 0.7196*s2$B8 + 0.2396*s2$B11 + 0.1949*s2$B12 | |
#Tasselled Cap – greenness | |
GRE <- (-0.3599*s2$B2) + (-0.3533*s2$B3) +(-0.4734*s2$B4) + 0.6633*s2$B8 + 0.0087*s2$B11 + (-0.2856*s2$B12) | |
#Tasselled Cap - wetness | |
WET <- (0.2578*s2$B2 + 0.2305*s2$B3 + 0.0883*s2$B4 + 0.1071*s2$B8 + (-0.7611*s2$B11) + (-0.5308*s2$B12)) | |
TC = stack(BRI, GRE, WET) | |
writeRaster(TC, "tasselled_cap.tif", drivername="Gtiff") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment