Closed haesleinhuepf closed 2 years ago
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/macro-results-vary-when-calling-it-via-pyimagej/57744/5
The Troubleshooting doc now mentions this issue as of imagej/pyimagej@e1b255450942dac1ea9a3e3f3afa85ee225c89b0. But no one has had time to solve it, unfortunately.
I commented on the forum thread with some insights:
For what it’s worth, I was able to reproduce the issue within Fiji’s script editor (i.e., independent of #pyimagej). Running the following macro code repeatedly:
run("Blobs (25K)"); setAutoThreshold("Otsu"); setOption("BlackBackground", true); run("Convert to Mask"); run("Analyze Particles...", " show=[Count Masks]"); getStatistics(area, mean, min, max, std, histogram); print(max);
… will print ever increasing values. It seems like there’s a counter for the Count Masks images that doesn’t get reset properly.
Judging from this line: https://github.com/imagej/ImageJ/blob/152c3d3def253a9c55f03214995b683f6f7008eb/ij/plugin/filter/ParticleAnalyzer.java#L1009-L1009
case ROI_MASKS: drawRoiFilledParticle(drawIP, roi, mask, rt.size()); break;
… the value for each drawn ROI is determined from the size of the internal
ResultsTable
(rt.size()
).
I can work around the issue by adding
Table.reset("Results");
to my macro code:run("Blobs (25K)"); setAutoThreshold("Otsu"); setOption("BlackBackground", true); run("Convert to Mask"); run("Analyze Particles...", " show=[Count Masks]"); getStatistics(area, mean, min, max, std, histogram); Table.reset("Results"); print(max); // will now always print 64
@imagejan Would you consider this a bug in ImageJ? I.e. should we move this issue to imagej/ImageJ?
Would you consider this a bug in ImageJ?
Yes. I just tested it with plain ImageJ, and observe the same behavior as seen with Fiji.
@rasband I transferred this issue here from PyImageJ. Based on your forum post I infer this might actually be working as intended, in which case this issue could be closed as not planned.
The particle analyzer is working as expected. The Count Masks are filled with a grayscale value corresponding to the particle number. To insure the particle numbers start at 1, use the “Clear results” option, as in this example:
run("Blobs (25K)");
setAutoThreshold("Otsu");
setOption("BlackBackground", true);
run("Analyze Particles...", "clear show=[Count Masks]");
getStatistics(area, mean, min, max, std, histogram);
print(max);
Repeatedly calling the same macro code from pyimagej leads to different results.
See detailed description: https://forum.image.sc/t/macro-results-vary-when-calling-it-via-pyimagej/57744