Open Roi file without RoiManager

I am wondering if there is a way to open a roi file (previously saved via the RoiManager) in a script without having to use the RoiManager (rm) like
rm.runCommand("Open", RoiPath.toString()).
which is adding the roi to the RoiManager.

While I would prefer to store directly the content of the file in a Roi object, so something like
myRoi = IJ.openRoi(RoiPath.toString())
but I could not find such thing.

The idea is to feed the Roi from file to a batch processing script. While I would keep the RoiManager for the output of the script. I still can do it with the previous command but it is a bit more of boilerplate code.

Thanks

There’s ij.io.RoiDecoder and ij.io.RoiEncoder that contain static methods to open and save ImageJ1 ROIs.

#@ File roiFile
#@ File (style="save") outputFile

import ij.io.RoiDecoder
import ij.io.RoiEncoder

roi = RoiDecoder.open(roiFile.getPath())
// process your roi here
success = RoiEncoder.save(roi, outputFile.getPath())
3 Likes