将 RGB RasterBrick 转换为灰度

Convert RGB RasterBrick to Grayscale

我有一个包含 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 种颜色的灰色配色方案进行绘图。