【问题标题】:ImageJ macro not release memory resourcesImageJ 宏不释放内存资源
【发布时间】:2014-08-12 12:41:52
【问题描述】:

我正在使用 ImageJ v1.49e(附带 java 1.6.0_24 (64bit))

我编写了一个宏,它从输入目录读取图像,进行一些处理并根据条件将图像移动到输出目录。以批处理模式运行,因为我希望处理 100,000 张图像。

因此,我从 ImageJ 运行宏,并通过 JConsole 监控内存使用情况,我只看到内存使用情况不断上升,再也没有回落。 ImageJ 分配了 6GB,但很快它就达到了这个限制。即使我从 JConsole 或宏中调用 GC,它什么也不做。

我检查以确保我在批处理模式下运行并关闭我打开的任何窗口,但仍然不行。在网上也找不到任何关于为什么会发生这种情况的信息。

我没有正确释放我的资源吗? 我有什么遗漏吗?

下面是宏代码

inputDir = getDirectory("Choose the Input Directory");
outputDir = getDirectory("Choose the Output Directory");

inputDir = replace(inputDir,"\\\\", "\\\\\\\\");
outputDir = replace(outputDir,"\\\\", "\\\\\\\\");

if(inputDir != "" || outputDir != "") {
    setBatchMode(true);
    analyzeImagesBatch(inputDir, outputDir);
    exit("Done");
}
else {
    exit("Must select an input and output directory");
}

function analyzeImagesBatch(inputDir, outputDir) {
    inputList = getFileList(inputDir);

    for (i=0; i < inputList.length; i++) {
        showProgress(i+1, inputList.length);
        fileName = inputList[i];
        ok = imageAnalysis(inputDir, outputDir, fileName, 50, 30, 20);
        if(ok != 1) {
            imageAnalysis(inputDir, outputDir, fileName, 5, 10, 10);
        }
    }
}

function imageAnalysis(inputDir, outputDir, fileName, backgroundValue, size, countThresh) {
    ok = 0;
    open(inputDir+fileName);
    imageId = getImageID();
    run("8-bit");
    run("Subtract Background...", "rolling="+backgroundValue);  
    setAutoThreshold("Default");
    setOption("BlackBackground", false);
    run("Convert to Mask");
    run("Analyze Particles...", "size="+size+"-Infinity circularity=0.40-1.00 exclude clear");

    count = nResults();
    if(count >= countThresh) {
        ok = File.rename(inputDir+fileName, outputDir+fileName);
    }

    selectImage(imageId);
    close();
    return ok;
}

【问题讨论】:

    标签: java macros imagej


    【解决方案1】:

    我将宏重写为 Java 插件,并在同一组 100,000 张图像上运行它。内存使用量保持在 70mb 以下。

    使用 IJ 宏时肯定是内存泄漏。

    【讨论】:

    • 我同意,我也看到过这种行为:即使在数百张图像上运行时,我也清楚地看到宏运行的时间越长,运行速度越慢,内存使用量猛增。
    • 我刚刚发现,当我在插件中包含一个内部类并经常使用时,内存会不断增加。即使我很小心并清除了我不再使用的对象。
    • 我从 ImageJ 邮件列表中得到确认,内存泄漏的主要原因是 SCIFIO 选项被打开。当我更新 ImageJ(斐济)时,它默认关闭,这就是为什么它在更新后为我修复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 2012-01-08
    • 2012-05-04
    • 2014-05-19
    相关资源
    最近更新 更多