我正在尝试1)使用R模拟数据矩阵(实际上是数字图像,其中矩阵中的每个单元格都有一个数字范围为0-255的数字(8位数据))
2)使用映射工具映射模拟数据
3)将图像分为8-10类
想法是使用一个简单的函数来生成具有3个波段的红绿色和蓝色图像的图像,以模拟来自卫星的多光谱图像。因此,这是3个不同矩阵的组合。像这样。
然后按颜色将合成物分为8或10类任何帮助将不胜感激。
只要样本是随机的,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矩阵。矩阵在0
和255
之间包含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)