r - 将 RGB RasterBrick 转换为灰度

标签 r tiff raster

我有一个包含 RGB 贴图的 RasterBrick:

class       : RasterBrick 
dimensions  : 2400, 4200, 10080000, 3  (nrow, ncol, ncell, nlayers)
resolution  : 100, 100  (x, y)
extent      : 480000, 9e+05, 62000, 302000  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +units=m +no_defs 
data source : topo_100.tif 
names       : swisstopo_100.1, swisstopo_100.2, swisstopo_100.3 
min values  :           20.68,           26.00,           35.00 
max values  :             255,             255,             255 

我想使用 R 转换为灰度

有谁知道有没有可以把RGB砖转成灰度的函数?

感谢您的帮助。

最佳答案

现在我找到了一个方法:

library(tmap)
gray_raster <- ( colour_raster$colour_raster.1 + colour_raster$colour_raster.2 + colour_raster$colour_raster.3 ) / 3

colors <- gray.colors(255, start = 0.3, end = 0.9, gamma = 2.2, alpha = NULL)
gray_raster <- brick(gray_raster)
tm_shape(gray_raster) + tm_raster(palette = colors, auto.palette.mapping = F, n = 255, legend.show = F)

您可以只构建三个色带的平均值,然后使用包含 255 种颜色的灰色配色方案进行绘图。

关于r - 将 RGB RasterBrick 转换为灰度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40886005/

相关文章:

r - 有什么有效的方法可以通过 R 中土地覆盖栅格的像素计数方法获得面积估计吗?

r - 如何在 R 中批量裁剪栅格图层并更改投影

r - 快速数据表过滤

r - 如何识别R中列中的模式并为所述模式提供身份

r - 在 R 中使用 dplyr 进行条件平均

java - 从 PDF 中提取 TIFF 图像而不解码

c++ - 获取 .tiff map 中的最短路径

python - 如何对相关的 .tif 文件进行分组?

r - emmeans (R) 仅拦截功能是否损坏?

c - Bresenham 画线算法和 PID