gpt4 book ai didi

r - 使用 EBImage 或类似工具将 TIFF 中的单个帧加载到 R 中

转载 作者:行者123 更新时间:2023-12-02 09:24:08 26 4
gpt4 key购买 nike

我正在 R 中分析 TIFF 文件。TIFF 只有一种颜色/ channel ,但它来自一部大约 1000 帧的电影,因此非常大。我尝试使用以下命令与 EBImage 将图像数据作为矩阵加载到 R 中:

img <- readImage(file, as.is = TRUE)

但是,巨大的文件使计算机的 RAM 完全重载,我收到以下错误消息:

Error: cannot allocate vector of size 22.4 Gb
In addition: Warning messages:
1: In readTIFF(x, all = all, ...) :
TIFFReadDirectory: Unknown field with tag 50838 (0xc696) encountered
2: In readTIFF(x, all = all, ...) :
TIFFReadDirectory: Unknown field with tag 50839 (0xc697) encountered
3: In array(unlist(arg.list, use.names = FALSE), dim = c(arg.dim[-along, :
Reached total allocation of 65170Mb: see help(memory.size)
4: In array(unlist(arg.list, use.names = FALSE), dim = c(arg.dim[-along, :
Reached total allocation of 65170Mb: see help(memory.size)
5: In array(unlist(arg.list, use.names = FALSE), dim = c(arg.dim[-along, :
Reached total allocation of 65170Mb: see help(memory.size)
6: In array(unlist(arg.list, use.names = FALSE), dim = c(arg.dim[-along, :
Reached total allocation of 65170Mb: see help(memory.size)

我提出的解决方案是创建一个循环,该循环将单独打开每个帧,执行并存储我的分析,然后移至下一个图像。 EBImage 调用的 TIFF 包提供了仅打开第一帧 (all = FALSE) 的选项,但不打开您选择的帧。有没有办法可以单独打开每个框架?

最佳答案

<强> RBioFormats 提供了一种从较大图像堆栈中仅读取选定帧的解决方案。它连接的是 BioFormats Java 库,而不是 R 包 tiff。

要从 GitHub 安装软件包,请运行

# install.packages("devtools")
devtools::install_github("aoles/RBioFormats")

然后,您可以使用 read.image()subset 参数来指定要读取的帧。生成的对象属于 AnnotatedImage 类,它是 EBImage Image 类的子类。请参阅package vignette有关详细信息,请参阅以下示例来说明子集化方法。

library(EBImage)
library(RBioFormats)

f <- system.file("images", "nuclei.tif", package="EBImage")

metadata <- read.metadata(f)

frames <- metadata$coreMetadata$sizeT

for(i in 1:frames) {
frame <- read.image(f, subset=list(T=i))
frame <- resize(frame, 128)
display(frame)
}

关于r - 使用 EBImage 或类似工具将 TIFF 中的单个帧加载到 R 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39277628/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com