This entry is somewhat similar to this one. I am trying to design a simple script to plot graphs semi-interactively:
- the user first selects and records any number of ROIs on different images using the ROI manager,
- the script then plots the graphs, one per image with a curve for each ROI.
The problem is that the
Roi.getImage() method returns
null on the ROIs selected from the ROI manager. Here’s a Groovy example:
import ij.* import ij.plugin.frame.RoiManager // Get active image, set roi, add it to roi manager, select it from the roi manager imp = IJ.getImage() imp.setRoi(0, 0, 10, 10) roi = imp.getRoi() IJ.log("Before: " + roi.getImage().toString()) rm = RoiManager.getRoiManager() rm.addRoi(roi) roi = rm.getRoi(rm.getCount()-1) IJ.log("After: " + roi.getImage().toString())
Here’s the output with a random image:
Before: img["Untitled" (-2), 8-bit, 400x400x1x1x1] After: null
Am I missing something?
Good news is that the ImageID property is not lost:
roi.getImageID() will return the same value before and after recording, therefore I can devise a workaround by using the
WindowManager class to select the images based on their IDs. But it’s less satisfying than just getting them directly from the ROI manager.
Thank you for your comments.