我使用从红杉鹦鹉传感器拍摄的.tif图像。我想进行辐射校准并以相同的格式(.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)
原始脚本是否缩进?使用示例图像,一切正常。
我做了一些小改动以便更好地理解:
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))
}