【问题标题】:How to get threshold value used by auto threshold Plugin如何获取自动阈值插件使用的阈值
【发布时间】:2013-04-28 20:44:55
【问题描述】:

我有以下代码,我从目录中读取图像并使用 ImageJ Auto Threshold 插件来分割我的图像。

dir = getDirectory("path");
list = getFileList(dir);

for (i=0; i<list.length; i++)
{
   if (endsWith(list[i], ".tif")) 
   {
        open(dir + list[i]);
        run("8-bit");
        run("Gaussian Blur...", "sigma=2");
        setAutoThreshold("Otsu dark");
        run("Convert to Mask");
        saveAs("TIFF", dir+list[i]);
        close();
    }
}

我想使用 “Otsu dark” 方法获取阈值,并修改该值(例如按一个因子缩放)并将其应用于我的图像进行分割。

【问题讨论】:

    标签: imagej


    【解决方案1】:

    在 ImageJ 宏中,使用 getThreshold(lower,upper)setThreshold(lower,upper) 方法(here 的文档)。

    您的代码将如下所示:

    dir = getDirectory("path");
    list = getFileList(dir);
    factor = 1.5;
    
    for (i=0; i<list.length; i++)
    {
       if (endsWith(list[i], ".tif")) 
       {
            open(dir + list[i]);
            run("8-bit");
            run("Gaussian Blur...", "sigma=2");
            setAutoThreshold("Otsu dark");
            getThreshold(lower,upper);
            setThreshold(lower,upper*factor);
            run("Convert to Mask");
            saveAs("TIFF", dir+list[i]);
            close();
        }
    }
    

    如果您打算做更复杂的事情,请考虑使用另一个scripting language,就像Fiji 提供的那样。

    【讨论】:

    • 谢谢,真的很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 2013-03-29
    • 2019-12-03
    • 2015-09-07
    • 1970-01-01
    相关资源
    最近更新 更多