pythonimagejpyimagej

Access FileSaver from pyimagej


How can one access FileSaver from pyimagej?

Everything that I see online is something like this:

from ij.io import FileSaver

But with pyimagej we are loading it differently:

import imagej
ij = imagej.init()

Also ij.io().FileSaver does not exists

Thanks


Solution

  • If your goal is to save an image to disk, use this:

    ij.io().save(myImage, filePath)
    

    Where myImage is the image to save, and filePath is where to save it. The output image format will be inferred from the file extension.

    If your goal is specifically to use ij.io.FileSaver, you can do so as follows:

    import imagej
    from scyjava import jimport
    ij = imagej.init(...) # replace '...' with desired parameters here
    FileSaver = jimport('ij.io.FileSaver')
    imp = ... # get or make an ImagePlus somehow
    fs = FileSaver(imp)