IJ.close() - Scripting python in ImageJ/FIJI

若如初见. 提交于 2019-12-10 12:04:17

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/27546500/ij-close-scripting-python-in-imagej-fiji

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!