有点挣扎,所以决定寻求帮助。首先,介绍一下背景。我从事金属增材制造的工艺监控工作。我从每一层获取灰度光学断层扫描图像,强度变化可能表示存在缺陷(或跨多层的缺陷簇表示存在缺陷)。我正在尝试编写一个宏来帮助我执行以下操作:
- 创建与我的样本所在位置相对应的 ROI
- 根据默认算法之一对图像进行阈值设置
- 循环遍历单个图像的 ROI 并运行分析粒子
- 收集我拥有的每幅图像中每个 ROI 的计数(明亮粒子)
- 汇总文件夹中所有图像的每个 ROI 的计数数量
我设法列出了大多数要点,但未能将 ROI 名称合并到摘要中(列出计数的地方),也未能总结所有图像中每个 ROI 的计数数量。摘要窗口的图像,我努力将 ROI 合并到其中,显示计数数量,我现在非常笨拙的方法是保存每个图像的每个摘要,手动重命名 ROI,并编写更笨拙的 Excel 宏来汇总图像中的计数。
这里还有原始数据集的一小部分链接。2
希望能得到一些关于如何更好地简化这一过程的反馈。我搜索并尝试了 ChatGPT,但没有取得太大成功。
这是某一层的原始图像。来自某一层的光学断层扫描。 这是显示检测到的粒子的阈值图像,我想要计算每个 ROI 内的粒子数量。带有 ROI 的阈值图像。 最后,我想要获得一个文本(csv、excel 或类似文件)文件,该文件总结了正在分析的图像中每个 ROI 的计数量。 这是之前的 Excel 工作表的图像,其中我有几个 ROI、相应的测试件名称以及不同阈值操作的计数汇总量。以前总结的示例。
这是我当前的代码:
#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix
processFolder(input);
setBatchMode(true);
// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}
function processFile(input, output, file) {
// Do the processing here by adding your own code.
// Leave the print statements until things work, then remove them.
print("Processing: " + input + File.separator + file);
print("Saving to: " + output);
//opening the image
open(input + File.separator + file);
filename_pure = File.nameWithoutExtension;
//preparations
roiManager("reset");
run("Clear Results");
saving_prefix = output + File.separator + filename_pure;
//get the image name
title = getTitle();
//load ROI
roiManager("Open", "C:\\Users\\riabov\\OneDrive - Chalmers\\höganäs and phd\\printing\\dynamiq\\al-case\\ot\\analysis\\dynamiq-al-roi.zip");
//set an auto threshold and binarize
setAutoThreshold("Yen dark no-reset");
run("Convert to Mask");
//run the ROI-macro
c= roiManager("count");
for (i = 0; i < c; i++) {
roiManager("Select", i);
run("Analyze Particles...", " show=Nothing display summarize composite");
}
roiManager("show all without labels");
//saving
//save the results window as a comma-separated-value file
saveAs("Results", saving_prefix + "_results.csv"); //use saveAs command to save results
//save the image
saveAs("tiff", saving_prefix + "_ROI.tif"); //use saveAs command to save an image
//Clean-up
run("Close All");
}
这是一个 ImageJ 宏,可以计算您想要获得的内容:
启动此宏时,必须在 ImageJ 中打开阈值图像和带有 RoI 集的 ROI-Manager。
以下是我根据估计阈值得到的样本图像: