ImageJ's setResult inserts result into wrong column after loading results from text file

I would like to collect results from a loop in the “Results” table (one row per iteration). However, the “Results” table is used by other operations, so at the end of each iteration, I simply reload the old one, append a row, and save again. However, after a couple of rows, values tend to disappear.

I investigated and came up with the following unrolled-loop minimal example:

// Open a "Results" window first

file = "Results.xls"

run("Clear Results");
saveAs("Results", file);

open(file);
setResult("A", 0, 3);
saveAs("Results", file);

open(file);
setResult("A", 1, 5);
saveAs("Results", file);

The resulting table is this:

	A
1	3
2	0

and the resulting file is this:

 		A
1	3	0
2	0	5

Clearly, I would both expect to be

	A
1	3
2	5

Why am I not getting the expected output?

1 Like

Check if you are saving the columns names. It looks in one of your examples like if the file was loaded without the column name, and when you add to it, IJ created that column “A”.
There is an option for that called Results Table Options
https://imagej.nih.gov/ij/docs/guide/146-27.html#toc-Subsection-27.13

1 Like

Hi @bers,

These steps are the problematic ones. If you clear the results and save a file, you’re saving an empty file (regardless of the input/output settings). I believe that reopening an empty file as a table is what’s causing the issue. The next step:

Results in a malformed table:
imagen

I should take a closer look at how tables are handled to understand why this is happening.

In any case, as long as you are not opening an empty file, this behavior will not show up:

file = "Results.xls"

run("Clear Results");
//saveAs("Results", file);

//open(file);
setResult("A", 0, 3);
saveAs("Results", file);

open(file);
setResult("A", 1, 5);
saveAs("Results", file);

imagen

Cheers,
Nico

Good idea! I verified that this option is checked (I believe this is ImageJ’s default value). Also, I think you see from the output file above that the column headers are included.

Thanks, this looks convincing. We will try that out that workaround in the actual macro next week. (I believe it’s obvious why I did it - I wanted to save an extra if (i>0) in the loop to make it most readable. But it won’t hurt much having it in there.)

Just out of curiosity - you would consider that a bug, right? :wink:

1 Like

You’re not the first one…

That could also be an inconvenient feature :stuck_out_tongue_closed_eyes:

I’ll try to see what’s going on.

Cheers!

News flash:

This behavior is corrected in the latest daily build of ImageJ! :grinning:

Thanks @Wayne for the taking care and upgrading the PR!

Cheers!

Great, thanks! Is that PR public? I have looked in a couple of places, but I haven’t seen any up-to-date ImageJ repository with individual commits. Would love to know when we can expect this to be released, too. :grinning:

Yes, of course: the PR was done to github.com/imagej/ImageJA (this one), but the corresponding commit always get published in @wayne’s repo github.com/imagej/imagej1 (here).
This version is available dayly via Help > Update ImageJ as the latest dayly build (1.52u29, in this case), and periodically (every time imagej1 reaches a Release Version) all these commits make their way into ImageJA and the Fiji distro.

Thanks! I had looked at https://github.com/imagej/ImageJ without noticing that this is ImageJ2…