Apply linear stretch to Landsat 8 images in the tmap R package

I have a Landsat 8 dataset downloaded from the USGS. I import into R using the following code:

library(raster)
library(tmap)

B1 <- raster("LC08_L2SP_166072_20210819_20210827_02_T1_SR_B1.TIF")
B2 <- raster("LC08_L2SP_166072_20210819_20210827_02_T1_SR_B2.TIF")
B3 <- raster("LC08_L2SP_166072_20210819_20210827_02_T1_SR_B3.TIF")
B4 <- raster("LC08_L2SP_166072_20210819_20210827_02_T1_SR_B4.TIF")
B5 <- raster("LC08_L2SP_166072_20210819_20210827_02_T1_SR_B5.TIF")
B6 <- raster("LC08_L2SP_166072_20210819_20210827_02_T1_SR_B6.TIF")
B7 <- raster("LC08_L2SP_166072_20210819_20210827_02_T1_SR_B7.TIF")

fcc_nir <- stack(B5, B4, B3)

The images are 16 bit. I can plot the false-colour composite image quite easily using this command:

plotRGB(fcc_nir, stretch = "lin")

Landsat FCC image generated using PlotRGB()

However, I need to overlay polygons and add a map grid etc. The tmap package makes great maps but I still have to figure out how to apply the same linear stretch in tmap. There is no obvious stretch option. When I plot the false-colour composite image, it appears dark:

tm_shape(fcc_nir) +
  tm_rgb(max.value = 65536)

Landsat FCC image generated using tm_rgb()

Do I need to rescale the image manually beforehand?

It would be nice if tm_rgb() had a stretch parameter like plotRGB(). Thanks in advance for any help/guidance!



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)