与ImageJ中的应用程序和代码不同的结果

时间:2014-07-23 20:24:49

标签: java imagej

当我尝试使用ImageJ进行图片分析并尝试计算孔隙度时出现了我的问题。

我录制了宏并在java中运行相同的过程。这两次执行的结果不同,我不知道为什么。你能帮忙吗?

我尝试使用ImageJ API再次编写代码。我运行的两个样本如下所示:

    ImagePlus imp = new ImagePlus();
    imp = IJ.openImage("path_to_image");
    int measurements = Measurements.AREA + Measurements.MEAN +Measurements.STD_DEV +    Measurements.AREA_FRACTION;
    ResultsTable rt = new ResultsTable();
    Analyzer analyzer = new Analyzer(imp, measurements, rt);
    IJ.setAutoThreshold(imp, "Default");
    System.out.println(rt.MIN);

并记录代码

    imp = IJ.openImage("path_to_image");
    IJ.run("Set Measurements...", "area mean standard modal min median area_fraction limit redirect=None decimal=3");
    IJ.setAutoThreshold(imp, "Default");
    IJ.run(imp, "Measure", "");

1 个答案:

答案 0 :(得分:2)

您的代码有几个问题:

您录制的代码似乎是Javascript,而不是ImageJ宏代码,因此以下是您的脚本的某些版本,它们都采用 Blob 示例图像(文件>打开示例&gt ; Blob(25K)),设置默认阈值并测量相同的参数。

ImageJ1宏:

run("Blobs (25K)");
setAutoThreshold("Default");
run("Set Measurements...", "area mean standard modal min median area_fraction limit redirect=None decimal=3");
run("Measure");

使用Javascript:

importClass(Packages.ij.IJ);

imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");
IJ.setAutoThreshold(imp, "Default");
IJ.run("Set Measurements...", "area mean standard modal min median area_fraction limit redirect=None decimal=3");
IJ.run(imp, "Measure", "");
imp.show();

Beanshell(最接近Java代码):

import ij.IJ;

imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");
IJ.setAutoThreshold(imp, "Default");
IJ.run("Set Measurements...", "area mean standard modal min median area_fraction limit redirect=None decimal=3");
IJ.run(imp, "Measure", "");
imp.show();

如果您想避免调用IJ并使用较低级别的ImageJ API,那么它在Beanshell中的外观如下:

import ij.ImagePlus;
import ij.IJ;
import ij.measure.Measurements;
import ij.measure.ResultsTable;
import ij.plugin.filter.Analyzer;

ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");
// IJ.setAutoThreshold(imp, "Default");
imp.getProcessor().setAutoThreshold("Default");

// IJ.run("Set Measurements...", "area mean standard modal min median area_fraction limit redirect=None decimal=3");
int measurements = Measurements.AREA + Measurements.MEAN + Measurements.MIN_MAX + Measurements.STD_DEV + Measurements.MODE + Measurements.MEDIAN + Measurements.AREA_FRACTION + Measurements.LIMIT;

// IJ.run(imp, "Measure", "");
ResultsTable rt = new ResultsTable();
Analyzer analyzer = new Analyzer(imp, measurements, rt);
analyzer.measure();

Double result = rt.getValue("Min", rt.getCounter() - 1); // get value of interest
IJ.log(result.toString()); // print to log window
// Alternatively, show the full results table
// rt.show("New Results");