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!

Dave'o-Telephone
  • 113
  • 1
  • 11

2 Answers2

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.

ctrueden
  • 6,751
  • 3
  • 37
  • 69
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

Lisa B.
  • 235
  • 1
  • 11