Get the overlay from one slice

I have a .tif file which is a stack. Each slice has a different overlay. How can I get an overlay from one slice? I tried getting the overlay and then cropping it: (there are 9 slices and I want slice 1, for example)

sliceOvr = imp.getOverlay();
var sliceOvrSize = sliceOvr.size();

The problem is that the number of ROIs in the overlay remained the total number of ROIs from all of the overlays of all of the slices. How can I get the overlay from only the slice I’m interested in?


Hello Avital,

does this example help you (an overlay have to be associated with a slice):

Does it help if you use the image slice ImageProcessor before (not tested!):

stack = imp.getImageStack();
/* Get the image processor of the slice! */
ip = stack.getProcessor(selectedSlice);
1 Like

Thanks - now I understand how to associate Rois with specific slices. And is there a way to do the opposite, i.e., to associate certain Rois with all of the slices of the stack?

Would’nt it be enough to set the overlay to the ImagePlus object?

ImageJ API:

Thanks - I set it with the gui, but somehow some of the Rois are associated with a specific slice.