有没有办法使用宏将 ImageJ 中多个图像的信息附加到结果表中?

问题描述 投票:0回答:1

我正在尝试编写一个宏来协助处理ImageJ中的多个动物图像。简而言之,我有多个文件夹,其中包含动物照片,需要在某些特征上设置点,并且我想要一个结果表,可以将其保存为 csv 文件,其中包含一个文件夹中所有图像的坐标。

我希望在最终结果表中包含的信息是:

  1. 使用多点工具制作的每张图像上的 X 和 Y 坐标(假设有 6 个)位置,其中每个位置都与图像的文件名相关联。 (我想我已经弄清楚这部分了)

  2. 因为我通过此宏运行的每个文件夹中都有多个图像,所以我希望将每个新图像的坐标附加到结果表输出中,而不是在 for 循环的每个新迭代中清除。

  3. 因为多点工具输出不是连续的,理想情况下这些点将在最终表的单独列中编号(我还没有尝试过,但这将是我的下一个障碍)。

我的结果表理想情况下应该是这样的(尽管填充了 X 和 Y 的坐标):

|  X  |  Y  |  Filename  |  CoordNumber  |
|     |     |   AA.tif   |       1       |
|     |     |   AA.tif   |       2       |
|     |     |   AA.tif   |       3       |
|     |     |   AA.tif   |       4       |
|     |     |   AA.tif   |       5       |
|     |     |   AA.tif   |       6       |
|     |     |   BB.tif   |       1       |
|     |     |   BB.tif   |       2       |
|     |     |   BB.tif   |       3       |
|     |     |   BB.tif   |       4       |
|     |     |   BB.tif   |       5       |
|     |     |   BB.tif   |       6       |
|     |     |   CC.tif   |       1       |
|     |     |   CC.tif   |       2       |
|     |     |   CC.tif   |       3       |
|     |     |   CC.tif   |       4       |
|     |     |   CC.tif   |       5       |
|     |     |   CC.tif   |       6       |

我编写了一个宏,让用户一张一张地浏览图像,并记录多点工具选择的坐标。不幸的是,我编写的 for 循环不会将下一个图像的坐标附加到结果表中,而是清除上一个图像的结果并重新开始。虽然我可以单独保存每个表并手动执行此操作,但如果可能的话,让 ImageJ 为我创建一个连续表(如上面的假想表所示)会更快。

我对宏的尝试如下:

//---------------------------------------------
macro "Ventral Measurements Test ."
{
//---------------------------------------------
imageDirectory=getDirectory("Open Folder");
print("InitialFolder is=", imageDirectory);
list=getFileList(imageDirectory);
n=lengthOf(list);
print("The number of images is: ="+n);
//---------------------------------------------
// Start macro processing
//---------------------------------------------
//Using a for loop
for(i=0; i<n;i++) {
open(imageDirectory+list[i]);
//---------------------------------------------
//setTool("multipoint");
waitForUser("If you haven't already, use the multi-point tool to mark the image as described in your instructions.\n Pay close attention to the orientation of the specimen. (is it in the VENTRAL orientation?)\n When you are finished, double-check to ensure that your selections are correctly placed and in order.\n If you notice anything odd about the specimen, make a note of its filename and what you think is odd,\n and Email your comment along with the data.\n If everything looks good, click OK to go to the next image.");
getSelectionCoordinates( x, y );
for(j=0; j<lengthOf(x); j++) {
Table.set("X", j, x[j]);
Table.set("Y", j, y[j]);
Filename=getTitle();
Table.set("Filename",j,Filename);
Table.update();
}
//---------------------------------------------
close(list[i]);
}
//---------------------------------------------
close("*");
// End of macro processing
//---------------------------------------------
exit("Finished! Please review to make sure everything is displayed correctly,\n and then save the document if it looks correct.\n Don't forget to email your data and comments.");
}
//---------------------------------------------
imagej fiji imagej-macro
1个回答
0
投票

你可以这样做:

imageDirectory=getDirectory("Open Folder");
print("InitialFolder is=", imageDirectory);
list=getFileList(imageDirectory);
n = lengthOf(list);
print("The number of images is: ="+n);
row_to_write = 0;

for(i = 0; i < n; i++){
    open(imageDirectory+list[i]);
    close("\\Others");
    run("ROI Manager...");
    setTool("multipoint");
    waitForUser("Select points to measure");
    n_rois = roiManager("count");
    coordNumber = 1;
    for(j = 0; j < n_rois; j++){
         roiManager("select", j);
         getSelectionCoordinates(x, y);
         setResult("X", row_to_write, x[0]);
         setResult("Y", row_to_write, y[0]);
         setResult("Filename", row_to_write, list[i]);
         setResult("CoordNumber", row_to_write, coordNumber);
         row_to_write += 1;
         coordNumber += 1;
    }
    roiManager("reset");
}
saveAs("results");
close("*");
  1. 您可以为添加所有点的每个图像打开一个新的 roiManager。添加所有点后,您可以单击“确定”waitForUser(),它将循环遍历每个点获取坐标并写入结果表(setResult() 函数)。
  2. 使用变量来跟踪要写入结果的行。
  3. 要获取所谓的 coordNumber,您可以在每次打开新图像时重置该变量。这还允许您在另一列中输出文件名。

希望对您有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.