0

I'm exceptionally new to python/scripting and I'm having a problem. I'm writing the following in Fiji (shortened version of the script is below...)

from ij import IJ, ImagePlus
from java.lang import Runtime, Runnable

import os

filepaths = []

for folder, subs, files in os.walk('location/of/files/'):
    for filename in files:
        #the next part stops it appending DS files
        if not filename.startswith('.'):
            filepaths.append(os.path.abspath(os.path.join(folder, filename,)))   

for i in filepaths:
    IJ.open(i);
    IJ.close();

Basically I want to open an image, do stuff, and then close the processed image using IJ.close(). However it gives the following error:

AttributeError: type object 'ij.IJ' has no attribute 'close'

Any idea how to get around this?

Thanks!

2 Answers 2

0

The IJ class does not have a close() method. You probably want to call the close() method of ImagePlus, which is the class for the image objects themselves.

Try something like:

IJ.open(i)
imp = IJ.getImage()
imp.getProcessor().setf(100, 100, 3.14159) # or whatever
IJ.save(imp, "/path/to/myShinyModifiedImage.tif")
imp.close()

If you need to operate over multiple slices of a multi-plane image, see also the "Loop over slices" template (Templates > Python menu of the Script Editor).

Note also that Jython does not have trailing semicolons on statements.

Sign up to request clarification or add additional context in comments.

Comments

0

For anyone else who is scripting with jython (python in ImageJ/Fiji), the Java docs always help in getting an overview of the modules and their classes/functions: Here for example for the module ij

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.