1

我有以下代码,我从目录中读取图像并使用 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”方法获得阈值,并修改该值(例如按一个因子缩放)并将其应用于我的图像进行分割。

4

1 回答 1

5

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.

于 2013-04-29T08:30:24.960 回答