R栅格包图()生成单色图像

use*_*622 2 plot monochrome r raster

我想使用绘图功能获得单色图像.但它一直在制作彩色图像.我甚至有单色图像,我使用绘图功能绘制,我得到了一些奇怪的绿色和橙色.如何使绘图功能提供单色图像?我试着阅读有关getValues函数但是发现它很难理解,因为我不是来自图像分析背景.似乎getBlocks()函数返回单色图像.但有没有办法只使用绘图功能获得单色图像?

library(raster)
r <- raster(matrix(runif(100), 10))
plot(r)
#even below lines produce a yellow color image. i thought that they will produce a black or white square
r <- raster(matrix(rep(0,100), 10))
plot(r)
Run Code Online (Sandbox Code Playgroud)

Ste*_*ven 7

如果您正在寻找颜色的灰度矢量,您可以使用gray.scale()以下col参数plot():

library(raster)
r <- raster(matrix(rnorm(100), 10))
plot(r, col = gray.colors(10, start = 0.3, end = 0.9, gamma = 2.2, alpha = NULL))
Run Code Online (Sandbox Code Playgroud)

你得到了绿色,plot()因为默认col使用

rev(terrain.colors(255)) 
Run Code Online (Sandbox Code Playgroud)