Create Selection not consistent in macro after saving file

Dear all and @Wayne,

I noticed a weird behaviour of the function →Edit →Selection →Create Selection in macros.

If an image is thresholded and you use the function above on the binary it creates the outline selection. Now, the strange thing is that after saving the image (I tried tif, png and jpg) the selection is created in an inverse manner and needs the →Make Inverse command to get the actual selection as before.
Finally, this seems to be dependent on the setOption("BlackBackground, boolean); setting. If I set it to true it is inconsistent, while setting it to false creates the same selection each time.

Actually, worse is that in my hands using the macro below, the area fraction is determined as well inverse after saving the image, which would be a fatal outcome if not being aware of this.

The following macro should reproduce that “bug” (?)

setOption("BlackBackground", true); //switch true and false to see differences in outcome
run("Set Measurements...", "area area_fraction display redirect=None decimal=5");
run("Blobs (25K)");
imageID = getImageID();
setThreshold(126, 255);
run("Convert to Mask");
run("Create Selection");
run("Select None");
run("Duplicate...", " ");
save(getDirectory("temp") + "blobs.tif");
run("Create Selection");
run("Select None");

I struggled with this already for quite some time and this might create problems in macro usage depending on if there is any saving command before or after the create selection command.

Funny thing: adding the run("Make Binary"); command after the saving command seems to solve the problem :thinking:

Potentially, I missed the point of this behaviour or any crucial step but it seems odd to me.

This bug is fixed in the latest ImageJ daily build (1.52r37). The Edit>Selection>Create Selection command was ignoring the “Black background” flag with non-thresholded binary images.

1 Like