使用R作为从头开始的卫星图像波段来模拟数据矩阵

问题描述 投票:0回答:1

我正在尝试1)使用R模拟数据矩阵(实际上是数字图像,其中矩阵中的每个单元格都有一个数字范围为0-255的数字(8位数据))

2)使用映射工具映射模拟数据

3)将图像分为8-10类

想法是使用一个简单的函数来生成具有3个波段的红绿色和蓝色图像的图像,以模拟来自卫星的多光谱图像。因此,这是3个不同矩阵的组合。像这样。

https://desktop.arcgis.com/en/arcmap/latest/manage-data/raster-and-images/GUID-9C81871D-F349-473E-8D24-FA0B6F235EFE-web.gif

然后按颜色将合成物分为8或10类任何帮助将不胜感激。

r matrix rgb
1个回答
1
投票

只要样本是随机的,sample就很容易。

imagerows <- 400
imagecols <- 400
colors <- c("red","green","blue")
result <- lapply(colors,function(x){
  matrix(sample(0:255,imagerows*imagecols,replace=TRUE),
         nrow=imagerows,
         ncol=imagecols)
  })

result现在是长度为3的列表,其每个元素都是400x400矩阵。矩阵在0255之间包含400 * 400个随机样本。

names(result) <- colors

library(grid)
rgb.matrix <- rgb(result[["red"]],result[["green"]],result[["blue"]],maxColorValue = 255)
dim(rgb.matrix) <- c(imagerows,imagecols)
plot.new()
grid.raster(rgb.matrix,interpolate = FALSE)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.