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.我已经注释了上面的代码以获得一些清晰度
感谢任何和所有帮助
答案 0 :(得分: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...")