繁体   English   中英

ImageJ宏不释放内存资源

[英]ImageJ macro not release memory resources

我正在使用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插件,并在相同的100,000张图像上运行。 内存使用率保持在70mb以下。

当使用IJ宏时,绝对是内存泄漏。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM