【问题标题】:Image processing loop using EBImage in R在 R 中使用 EBImage 的图像处理循环
【发布时间】:2013-11-14 09:00:11
【问题描述】:
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 的多个位置上进行操作。为了清楚起见,我对上面的代码进行了注释

感谢大家的帮助

【问题讨论】:

    标签: r loops image-processing


    【解决方案1】:

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

    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...")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多