Closing ImageJ image without saving changes dialog box

This is my first time posting in a forum like this, so I apologize if the formatting is off! I have a jython script which iterates through a large folder of images, opening them in imageJ and opening the corresponding ROI zip files. It then sets the scale and performs measurements based on the rois. When closing the images, because I set the scale, it gives me the “Do you want to save changes dialog box?” I want to set it so that this dialog does not pop up so that the script can run without any interaction from the user. In my research, I’ve only been able to find how to do this in imageJ macros language, not python. Currently I just have:

imp = IJ.getImage()
imp.close()

In imageJ macros, it seems this is possible through:

imp.changes = false;
imp.close();

I don’t know how to set change to false in Jython, but I feel like there should be an easy way to do it. My only other thought/back up plan is to write an imageJ macro to close my images and executing it through the MacroRunner in my jython script, but this seems unnecessarily cumbersome.

Hello Rose,

welcome to the forum, and no worries, I just formatted the code block in your message using ``` on the lines before and after the code. If you want to learn more about the possible formatting, you can follow the bot tutorial in your forum message inbox.

To be honest, I never came across that scenario and there is indeed no dedicated command in the ImagePlus class javadoc.
However, I just tried directly changing the attribute and that worked for me:

Try to past this jython code in the script editor of Fiji
And open a new image (without changing it), then run this code, it should print False and then True.
(btw #@ ImagePlus imp is like the IJ.getImage() just a bit more straightforward)

#@ ImagePlus imp
print imp.changes
imp.changes = True # or False as you want
print imp.changes

Here is the relevant API part:

https://imagej.nih.gov/ij/developer/api/ij/ImagePlus.html#close--

So in the Jython case:

imp.changes = False

1 Like