How to get threshold value used by auto threshold Plugin

為{幸葍}努か 提交于 2019-12-11 05:44:59

问题


I have the following code, where I read images from directory and use ImageJ Auto Threshold plugin to segment my images.

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();
    }
}

I would like to get the threshold value using "Otsu dark" method, and modify that value (e.g. scale it by a factor) and apply it to my images for segmentation.


回答1:


In an ImageJ macro, use the getThreshold(lower,upper) and setThreshold(lower,upper) methods (here's the documentation).

Your code would look like this then:

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();
    }
}

If you plan to do more complicated things, consider using another scripting language like the ones provided by Fiji.



来源:https://stackoverflow.com/questions/16267651/how-to-get-threshold-value-used-by-auto-threshold-plugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!