在 R 中导入、处理、编辑和导出 .tif 文件

Importing, processing, edit and export .tif files in R

我正在处理从 Sequoia Parrot 传感器捕获的 .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")

原始脚本是否缩进正确?使用您的示例图像,一切正常。

为了更好地理解,我做了一些小改动:

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))
}