- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 rgdal 包在 R 中处理图像分类脚本。有问题的栅格是具有 28 个 channel 的 PCIDSK 文件:一个训练数据 channel 、一个验证数据 channel 和 26 个光谱数据 channel 。目标是填充一个数据帧,其中包含训练数据 channel 中不为零的每个像素的值,以及 26 个波段中的相关光谱值。
在 Python/Numpy 中,我可以轻松地将整个图像的所有波段导入到多维数组中,但是,由于内存限制,R 中的唯一选项似乎是逐块导入此数据,这非常慢:
library(rgdal)
raster = "image.pix"
training_band = 2
validation_band = 1
BlockWidth = 500
BlockHeight = 500
# Get some metadata about the whole raster
myinfo = GDALinfo(raster)
ysize = myinfo[[1]]
xsize = myinfo[[2]]
numbands = myinfo[[3]]
# Iterate through the image in blocks and retrieve the training data
column = 0
training_data = NULL
while(column < xsize){
if(column + BlockWidth > xsize){
BlockWidth = xsize - column
}
row = 0
while(row < ysize){
if(row + BlockHeight > ysize){
BlockHeight = ysize - row
}
# Do stuff here
myblock = readGDAL(raster, region.dim = c(BlockHeight,BlockWidth), offset = c(row, column), band = c(training_band,3:numbands), silent = TRUE)
blockdata = matrix(NA, dim(myblock)[1], dim(myblock)[2])
for(i in 1:(dim(myblock)[2])){
bandname = paste("myblock", names(myblock)[i], sep="$")
blockdata[,i]= as.matrix(eval(parse(text=bandname)))
}
blockdata = as.data.frame(blockdata)
blockdata = subset(blockdata, blockdata[,1] > 0)
if (dim(blockdata)[1] > 0){
training_data = rbind(training_data, blockdata)
}
row = row + BlockHeight
}
column = column + BlockWidth
}
remove(blockdata, myblock, BlockHeight, BlockWidth, row, column)
myformula = formula(paste("as.factor(V1) ~ V3:V", dim(training_data)[2], sep=""))
r_tree = randomForest(formula = myformula, data = training_data, ntree = 500, keep.forest=TRUE)
library(raster)
library(randomForest)
# Set some user variables
fn = "image.pix"
training_band = 2
validation_band = 1
# Get the training data
myraster = stack(fn)
training_class = subset(myraster, training_band)
training_class[training_class == 0] = NA
training_class = Which(training_class != 0, cells=TRUE)
training_data = extract(myraster, training_class)
training_data = as.data.frame(training_data)
最佳答案
查看 Raster 包。 Raster 包为 Rgdal 提供了一个方便的包装器,而无需将其加载到内存中。
http://raster.r-forge.r-project.org/
希望这有帮助。
The 'raster' package deals with basic spatial raster (grid) data access and manipulation. It defines raster classes; can deal with very large files (stored on disk); and includes standard raster functions such as overlay, aggregation, and merge.
The purpose of the 'raster' package is to provide easy to use functions for raster manipulation and analysis. These include high level functions such as overlay, merge, aggregate, projection, resample, distance, polygon to raster conversion. All these functions work for very large raster datasets that cannot be loaded into memory. In addition, the package provides lower level functions such as row by row reading and writing (to many formats via rgdal) for building other functions.
关于rgdal 有效读取大型多波段栅格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4186507/
我需要从 4 波段图像中提取 3 波段。我正在使用一个名为 NumpyArrayToRaster() 的函数,它最多只接受 3 个波段图像。我如何让它适用于 4 波段图像? 这是我现在的代码- imp
我正在尝试制作一个安卓播放器,但在制作均衡器时出现了问题。均衡器频段是有限制的,例如 Nexus 5 默认有 5 频段均衡器。一些播放器(例如 Poweramp)以某种方式设法获得 10 频段均衡器,
我正在尝试读取 4 波段(红色、绿色、蓝色、近红外)geotiff ( example data ) 并执行 quickshift segmentation在 Python 中使用 scikit-im
如何使用 Rasterio 从多数据集 MODIS 图像中打开特定数据集? 我在 GitHub 上发布了一些示例数据:https://github.com/SteveObert/rasterIO_qu
我正在为 Microsoft Band 开发 UWP 应用程序,最近从 Band SDK ver 1.3.11121 升级到 Microsoft Band SDK ver 1.3.20115。 我注意
我是一名优秀的程序员,十分优秀!