Importing ROI coordinates for an image stack

I have an image stack and would like to draw ROIs with specific coordinates on the images. Each image in the stack would have a different ROI. Is there a way to do this if I had, for instance, a text file with the XY coordinates for the ROI and the corresponding image frame?
Edit/Selection/Specify would let me input the coordinates manually slice by slice, but my stacks are quite large (few hundred slices), so I am wondering if there is a faster way.
File/Import/XY Coordinates only allows one set of coordinates to be imported, so the same ROI gets added to every slice.
Thank you!

Use the ROI Manager to draw your ROI on the specific slice. You can save and reload your ROI’s easily, see:

If you want to import custom x,y values as ROI’s use the macro language to read the file and create your ROI’s on a specific slice which you can then add to the ROI Manager.

A builtin command is available, too, see:

1 Like

Use the Macro Recorder of ImageJ to get the commands to read,create ROI’s and add them to the ROI Manager:

1 Like

Thank you very much for the reply! The ROI importer command is almost exactly what I need, except it only lets you import one set of coordinates for the stack, and the resulting ROI is placed on each slice in the stack.
Is there is a way to import XY coordinates that are unique to each slice (the coordinates would all be contained in a single txt file)?
Thank you again for your help.

So basically each ROI has a X,Y but also Z coordinates if we consider the slice position.
Well if you feel confortable with another scripting language than the IJ1macro you can use the Roi and RoiManager class, in a script that would loop over the file lines.

For instance with Jython it would look like (I did not tested it and you need to rearrange according to the content of your file):

from ij.gui import Roi
from ij.plugin.frame import RoiManager

yourFile = open("PathtoFile.txt", 'r')

RM = RoiManager()
rm = RM.getRoiManager()

for line in yourFile: # assumning 1 Roi per line
      X, Y, Z, Width, Height = line.rstrip().split(',')     
      roi = Roi(int(X), int(Y), int(Width), int(Height)) #  if you have rectangular ROI
      roi.setPosition(Z) # set ROI Z-position/slice 

      rm.add(None, roi, line) # Trick to be able to set Z-position when less images than the number of ROI. line will appear as a digit index before the Roi Name  

# close file once done
# Show All ROI + Associate ROI to slices  
rm.runCommand("Associate", "true")	 
rm.runCommand("Show All with labels")
1 Like

Sorry for the late reply.
This is exactly the solution I was looking for. Thank you so much!