将线性拉伸应用于tmap r包装中的Landsat 8图像
我从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")
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")
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)
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
tm_rgb()
的选项有限。plotRGB()
函数似乎使用栅格单元格值的样本来执行拉伸。这就是为什么图像显得更明亮,更对比的原因。这是我使用tm_rgb()
:tm_rgb()
没有min.value =
选项。一个人可以输入较小的max.value
,但这有点受打击和错过。我希望根据图像统计数据使用更严格的方法。必须使用
raster :: stract()
或某些用户定义的拉伸功能之前先手动重新构造图像,以获得更明亮的输出。例如:
制作此图像:
tm_rgb()
has limited options. TheplotRGB()
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 withtm_rgb()
:tm_rgb()
has nomin.value =
option. One can enter a smallermax.value
but this is a bit hit and miss. I would prefer to use a more rigorous approach based on image statistics.One has to manually rescale images beforehand using the
raster::stretch()
or some user-defined stretch function to get a brighter output.For example:
produces this image: