将线性拉伸应用于tmap r包装中的Landsat 8图像

发布于 2025-01-26 20:04:12 字数 1252 浏览 5 评论 0原文

我从USGS下载了一个Landsat 8数据集。我使用以下代码导入R:

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)

图像为16位。我可以使用此命令很容易地绘制False-Colour复合图像:

plotRGB(fcc_nir, stretch = "lin")

生成的landsat fcc图像

i.sstatic.net/lh0gy.jpg“ alt =”使用plotrgb ( 必须弄清楚如何在TMAP中应用相同的线性拉伸。没有明显的伸展选项。当我绘制假色复合图像时,它看起来很黑:

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

如果tm_rgb()具有一个拉伸参数,例如plotrgb(),那将是不错的。事先感谢您的任何帮助/指导!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由范儿 2025-02-02 20:04:12

tm_rgb()的选项有限。 plotRGB()函数似乎使用栅格单元格值的样本来执行拉伸。这就是为什么图像显得更明亮,更对比的原因。这是我使用tm_rgb()

fcc_nir <- setMinMax(fcc_nir)

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

“最佳拉伸”

tm_rgb()没有min.value =选项。一个人可以输入较小的max.value,但这有点受打击和错过。我希望根据图像统计数据使用更严格的方法。

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

必须使用raster :: stract()或某些用户定义的拉伸功能之前先手动重新构造图像,以获得更明亮的输出。

例如:

fcc_nir_s <- stretch(fcc_nir, minv = 0, maxv = 255, minq = 0.1, maxq = 0.99)

tm_shape(fcc_nir_s) +
  tm_rgb()

制作此图像:

”拉伸图像“

tm_rgb() has limited options. The plotRGB() function appears to use a sample of raster cell values to perform a stretch. That is why images appear brighter and more contrasty. This is the best I could achieve with tm_rgb():

fcc_nir <- setMinMax(fcc_nir)

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

best stretch

tm_rgb() has no min.value = option. One can enter a smaller max.value but this is a bit hit and miss. I would prefer to use a more rigorous approach based on image statistics.

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

arbitrary user-defined max.value

One has to manually rescale images beforehand using the raster::stretch() or some user-defined stretch function to get a brighter output.

For example:

fcc_nir_s <- stretch(fcc_nir, minv = 0, maxv = 255, minq = 0.1, maxq = 0.99)

tm_shape(fcc_nir_s) +
  tm_rgb()

produces this image:

stretched image

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文