使用 R 中的图像函数设置特定的 RGB 值
Setting specific RGB values using Image function in R
我有一个矩阵 (NxM),我想用矩阵的值创建一个图像!如何为 Matrix 的特定值设置特定的 RGB 值?
例如:
值 <0 时的 RGB (128/128/128)
值 [0,0.7) 的 RGB (128/96/0)
等等 !
我应该通过更改 col 参数来使用 Image 函数,还是可以使用其他更简单的函数?
我找到了这个:
# plot reclassified data
plot(chm_classified,
legend = FALSE,
col = c("red", "blue", "green"), axes = FALSE,
main = "Classified Canopy Height Model \n short, medium, tall trees")
来自 : https://earthdatascience.org/courses/earth-analytics/lidar-raster-data-r/classify-raster/
如何为我想要的颜色设置特定的 RGB 值而不是 "RED" 、 "Green " 、 "Blue"
我不太清楚。你想要这样的东西吗:
M <- matrix(rnorm(100), 10, 10)
Mcolors <- apply(M, 1:2,
function(x) ifelse(x>0,
rgb(128,128,128,maxColorValue=255),
rgb(0,0,255, maxColorValue=255)))
library(plotrix)
color2D.matplot(M, cellcolors=Mcolors)
我有一个矩阵 (NxM),我想用矩阵的值创建一个图像!如何为 Matrix 的特定值设置特定的 RGB 值?
例如: 值 <0 时的 RGB (128/128/128) 值 [0,0.7) 的 RGB (128/96/0) 等等 !
我应该通过更改 col 参数来使用 Image 函数,还是可以使用其他更简单的函数?
我找到了这个:
# plot reclassified data
plot(chm_classified,
legend = FALSE,
col = c("red", "blue", "green"), axes = FALSE,
main = "Classified Canopy Height Model \n short, medium, tall trees")
来自 : https://earthdatascience.org/courses/earth-analytics/lidar-raster-data-r/classify-raster/
如何为我想要的颜色设置特定的 RGB 值而不是 "RED" 、 "Green " 、 "Blue"
我不太清楚。你想要这样的东西吗:
M <- matrix(rnorm(100), 10, 10)
Mcolors <- apply(M, 1:2,
function(x) ifelse(x>0,
rgb(128,128,128,maxColorValue=255),
rgb(0,0,255, maxColorValue=255)))
library(plotrix)
color2D.matplot(M, cellcolors=Mcolors)