2
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。为了清楚起见,我对上面的代码进行了注释

感谢您的帮助

4

1 回答 1

3

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

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...")
于 2013-11-14T00:59:55.463 回答