Problem adding results to results table
So I had some help with this macro and I'm still fairly new to writing things for ImageJ. The code is some of my work and a bunch of stuff others have helped with. In general, I'm trying to analyze a bunch of thresholded/binary images with analyze particles to generate ROI in each image. Then, I would like to use the ROI and apply them to the original image, before it was thresholded, and analyze the texture of the objects within those ROI. This is done with the GLCM texture plugin. So far this works and I can get results for one ROI after another - each in a new results window. What I would like is for all the results to display one after the other so I can save it all in one file. I trued adding updateResults() to no avail.
print("start directory loop");
dir = getDirectory("Choose input segment Directory, the thresholded image folder");
// analyze particles will be run on these thresholded images to generate ROIs.
list = getFileList(dir); // gives ImageJ a list of all files in the folder to work through
print("number of files in dir1 Segments",list.length); // optional prints the number of files in the folder
dir2 = getDirectory("Choose input Image Directory, the raw images "); // promts user to select folder to be saved in
list2 = getFileList(dir2); // gives ImageJ a list of all files in the folder to work through for directory2
extension2 = ".tif"; //defines file type variable
print("number of files in dir2 Image",list2.length); // optional prints the number of files in the folder
dir3= getDirectory("Choose output Directory"); //promts user to select folder on Images for Results
setBatchMode(true); // runs up to 6 times faster, without showing images onscreen. Turn off during troubleshooting steps??
dbugp = 1; //verbose print for debug
// Note that the above processes are outside the loop brackets { },
// so they will only be called once at the beginning of the macro
print("START...");
// main files loop
// (process every image until you get to the bottom of the list)
for (f=0; f<list.length; f++) {
path = dir+list[f]; // creates the filepath for reading Segmentation files
if(dbugp>0) {
// optional prints the path & file name to a log window
print("Name of path reading file from dir1",path);
}
showProgress(f, list.length);
// optional progress monitor displayed at top of Fiji
if(!endsWith(path,"/")) {
open(path);
}
// if subdirectory, push down into it Still have to open Path
/*
if (nImages>=1) { // stop when there
are no more open images */
t=getTitle(); // gets the name of the image being processed
//add specific steps to create threshold and Roi
run("Analyze Particles...", "display exclude include summarize add in_situ");
n=roiManager("count");
print("ROIi_number=" + n);
//roiManager("Rename",tt+"roi"+n);
if(roiManager("count")>0) {
roiManager("Save", dir3 + t +"roi"+n +".zip");
for(i=0; i<n; i++) {
roiManager("Select",i);
run("GLCM Texture", "enter=i select=[0 degrees] angular contrast correlation inverse entropy");
//Now open t again or return to original do you GLCM process
}
}
roiManager("Deselect");
roiManager("Delete");
}
selectWindow("Results");
saveAs(dir3+"WantedFileName.txt");
selectWindow("Log");
saveAs(dir3+"runlog.txt");
// END processing per image
Posted Aug 25, 2016, 1:51 AM UTC · edited
Why not just make a 2nd macro to open the saved results files and merge them into one big file?
Right now the results table shows the measured qualities but the item number is 1. Then the table clears and the second ROI is analyzed from a given image - and shows up as item 1 because the table was cleared. So I'd end up with a lot of measures and no way to tell which ROI it was because the unique identifier would be lost this way.
Well, that method might be a bit hard, so scrap that idea for now.
An alternative is to temporarily store the data in arrays (see the links on the sidebar to learn about arrays in the macro language).
What you can do is somewhere at the beginning of your code, for each item that you want to store, you need to create either one array that will be indexed or multiple arrays (one for each label in the results table). Presuming the latter:
At the beginning:
"L1" can be the label of the item or whatever you want... just having the same label makes life easier.
Then after a measurement is done and added to the results table:
With <column L1> being replaced by whatever the column's label is.
Then, after the code has run for all of the ROIs, at the end, you need to fill the Results Table:
This isn't the only method, but it's probably adequate.