Analyze particles distorts the image?

I am trying to run a macro that rotates an image and analyze particles. What seems odd to me is how the images look if the analysis is not run. Here is the macro I’m attempting to run on an image:

run("8-bit");
setAutoThreshold("Default");
//run("Threshold...");
setThreshold(116, 147);
run("Set Measurements...", "bounding redirect=None decimal=3");
snapshot;
for (i=0; i<=180; i+=1) {
    run("Analyze Particles...", "size=500-Infinity display");
    reset;
    run("Arbitrarily...", "interpolate angle="+i);
}

Here is the result I get:

If I take out the analyze particle part of the code:

run("8-bit");
setAutoThreshold("Default");
//run("Threshold...");
setThreshold(116, 147);
run("Set Measurements...", "bounding redirect=None decimal=3");
snapshot;
for (i=0; i<=180; i+=1) {
    //run("Analyze Particles...", "size=500-Infinity display");
    reset;
    run("Arbitrarily...", "interpolate angle="+i);
}

then I get this as the result:

Am I doing something wrong? Why would running an analysis change the image as much as it does? Any help would be greatly appreciated!

Hey @Dooz,

most of your issues are resulting from a misinterpretation of what reset does. The macro language documentation on that topic says:

reset
Restores the backup image created by the snapshot function. Note that reset() and run(“Undo”) are basically the same, so only one run() call can be reset.

Especially the latter part is of interest here since the reset will not actually reset to the image at the call to snapshot but only to the one of the last rotation. In the end, the frayed edges are a cumulative effect of the repeated rotation/interpolation, in my opinion.

Plus, the rotation will fill up missing pixels with 0s (black), effectively creating the circular structure.

I hope those are the two effects you are referring to?

All the best,
Stefan

3 Likes

@Dooz you might want to use run("Revert"); instead:

File > Revert
Reloads the active image, stack or hyperstack from disk, reverting it to its last saved state. It is actually a shortcut for closing the window without saving, and then reopening it. Note that it may not work with Non–native Formats opened through external plugins such as the OME Bio-Formats library.

2 Likes

Thank you both, this works perfectly. I appreciate the help!

1 Like