2017-10-12 2247 views
0

我正在处理从红杉鹦鹉传感器捕获的.tif图像。我想要进行辐射校准并以相同格式(.tif)导出生成的图像。在R中导入,处理,编辑和导出.tif文件

我将图像作为栅格导入,然后使用一些算法进行处理,最后尝试导出为.tif文件,但无法打开。生成的文件为7 MB,但无法查看图像。

这里是我的脚本:

setwd("/where the images are/") 
rlist=list.files(getwd(), pattern="TIF$", full.names=F) 
options(digits=20) 

for(i in rlist){ 
    data <- raster(i) 

meta <- exifr(i, recursive = FALSE, quiet = TRUE, exiftoolargs = NULL) 
SM <- meta$SensorModel 
SM <- strsplit(SM, ",")[[1]] 
A <- as.numeric(SM[1]) 
B <- as.numeric(SM[2]) 
C <- as.numeric(gsub("[^0-9\\.]", "", SM[3])) 

Ep <- meta$ExposureTime ## Epsilon 
f <- meta$FNumber ## Focus Number 
ys <- meta$ISO ##ISO 

I <- f^2*(data-B)/(A*Ep*ys+C) 
I <- flip(I,"x") 
I <- flip(I,"y") 
+0

我会用'计算的()。没有示例图像,我无法帮助您确定问题。 –

回答

0

是原来的剧本以及缩进?用您的示例图像,一切正常。

我为更好地了解小的变化:在``先计算I`

library(raster) 
library(exifr) 

setwd("/where the images are/") 
rlist=list.files(getwd(), pattern="TIF$", full.names=F) 
options(digits=20) 

for(i in seq_along(rlist)){ # small change 

    data <- raster(rlist[i]) # small change 

    meta <- exifr(rlist[i], recursive = FALSE, quiet = TRUE, exiftoolargs = NULL) # small change 
    SM <- meta$SensorModel 
    SM <- strsplit(SM, ",")[[1]] 
    A <- as.numeric(SM[1]) 
    B <- as.numeric(SM[2]) 
    C <- as.numeric(gsub("[^0-9\\.]", "", SM[3])) 

    Ep <- meta$ExposureTime ## Epsilon 
    f <- meta$FNumber ## Focus Number 
    ys <- meta$ISO ##ISO 

    I <- calc(data,fun = function(x){f^2*(x-B)/(A*Ep*ys+C)}) # small change 
    I <- flip(I,"x") 
    I <- flip(I,"y") 
    print(plot(I)) 
} 

image