gpt4 book ai didi

r - 在 R 中使用 EBImage 的图像处理循环

转载 作者:行者123 更新时间:2023-12-04 04:34:35 25 4
gpt4 key购买 nike

require("EBImage")

我本质上想在 R 中循环这组命令以生成图像掩码
a <- readImage('BF_Position004_time021.tif') # load rgb image
g <- channel(a, "asgreen") #take green channel from image
writeImage(g,"/Users/...path.../GFP_Position004_time021.tif") #save green channel image
r <- channel(a, "asred") #take red channel from image
writeImage(r,"/Users/...path.../RFP_Position004_time021.tif")#save red
b <- channel(r, "gray") #makes red channel into gray scale
#the following creates a white mask over pixels with high intensity
nmask2 = thresh(sqrt(b), 15, 15, .001)
# nmask2 = fillHull(nmask2)
mk3 = makeBrush(3, shape = 'diamond')
nmask3 = opening(nmask2, mk3)
nseg = bwlabel(nmask3)
nf = computeFeatures.shape(nseg)
nr = which(nf[,'s.area'] < 150)
nseg = rmObjects(nseg,nr) #resulting image called nseg
writeImage(nseg,"/Users/...path.../BF_Position004_time021.tif") #save nseg with the following name

我想跨越从 000 到 100 的多个位置以及时间点 001 到 100。为了清楚起见,我对上面的代码进行了注释

感谢您的帮助

最佳答案

将上面的命令放入一个函数中,该函数采用文件名的公共(public)部分和您要写入的目录

fun <- function(fl, dirpath) {
a <- readImage(sprintf("BF_%s", fl))
...
writeImage(g, file.path(dirpath, sprintf("GFP_%s", fl)))
....
}

创建文件名向量
fls <- sprintf("Position%03d_time%03d.tif", rep(0:100, each=100), 1:100)

去!
for (fl in fls)
fun(fl, "/Users/...path...")

关于r - 在 R 中使用 EBImage 的图像处理循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19966224/

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