这里我试图将CT图像的tiff文件导入R进行分析。我有大约250个tiff文件,我试图在循环中分析。分析首先进行裁剪,然后进行阈值处理,然后根据像素强度值计算孔隙度。目前我收到此错误:
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file. (file does not exist)
`library(raster)
library(rgdal)
library(sp)`
`project_files <- dir("/Users/Rob/Documents/BMBT5130/Data")
for (jj in 1:length(mget(project_files))) {
x[jj] <- raster(paste0(project_files[jj]))
x1 <- crop(x, extent(800,1600,700,1600))
x[x<=35]=0
plot(x1)
Porosity[jj] <- (length(x1[x1<=35]))/length(x1[x1>=0])`
工作目录是上面使用的目录
Sessioninfo:
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X El Capitan 10.11.6
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RBioFormats_0.0.30 rJava_0.9-8 EBImage_4.16.0 imager_0.40.2 magrittr_1.5
[6] plyr_1.8.4 ROI_0.2-1 rgdal_1.2-6 raster_2.5-8 sp_1.2-4
[11] tiff_0.1-5
loaded via a namespace (and not attached):
[1] Rcpp_0.12.10 knitr_1.15.1 BiocGenerics_0.20.0 lattice_0.20-35 jpeg_0.1-8
[6] stringr_1.2.0 tools_3.3.3 parallel_3.3.3 grid_3.3.3 png_0.1-7
[11] registry_0.3 abind_1.4-5 bmp_0.2 purrr_0.2.2 fftwtools_0.9-8
[16] slam_0.1-40 readbitmap_0.1-4 stringi_1.1.5 locfit_1.5-9.1
非常感谢任何帮助解决这个问题
最好,
罗布
答案 0 :(得分:1)
正如评论中已经提到的那样:
list.files("/Users/Rob/Documents/BMBT5130/Data", full.names=T, pattern="tif$")
应该使您的代码有效。
确保设置full.names=T
以确保获得整个路径名,如果您正在使用tif文件,请考虑仅搜索以“tif”结尾的文件(即排除tix.aux文件)。