Displaying Slice's overlays in a stacked image

Is there a way to display the overlay that each slice have in a stack?? I explain it further, I have a stack, I set one different overlay to each slice in the stack, I want the final image to show each overlay in each slice when navigating through the stack.
Regards

If you add an overlay to a slice of a stack (except VirtualStacks) it will be shown in the selected slice and can be saved and reopened (*.tif).

Was this the point of your question?

The behavior you describe is not what happens in my system (Windows 8.1x64, latest fiji, legacy mode), can you provide a minimal working example in java?

I fear that this issue is a little more complicated. Execute the following Groovy script from the editor after opening the Mitosis sample:

// @ImagePlus imp

import ij.gui.Overlay;
import ij.gui.Roi;

overlay = new Overlay();

r0 = new Roi(12, 20, 10, 10);
r0.setPosition(0, 0, 0);
// Usage: setPosition(channel, slice, frame);
overlay.add(r0);
// Roi is shown on all positions

r1 = new Roi(50, 20, 10, 10);
r1.setPosition(1, 0, 1);
overlay.add(r1);
// Roi is shown on first channel and and first time point (no matter which slice)

r2 = new Roi(90, 20, 10, 10);
r2.setPosition(0, 0, 2);
overlay.add(r2);
// Roi is shown on all channels and slices but only on second time point

imp.setOverlay(overlay);

Where the Rois are shown is noted as comments in this snippet. So one issue might be, that the parameters to Roi.setPosition are 1-based, where 0 means that the ROI is shown on all positions in that “dimension”.

1 Like

I think this is an example (ImageJ macro language) of the behaviour described by Bio7

run("Bat Cochlea Volume (19K)");
for (i=1; i<nSlices; i++) {
	setSlice(i);
	makeOval(i, i*2, 10, 10);
	roiManager("Add");
}
run("From ROI Manager");//add from ROI Manager to overlay
selectWindow("ROI Manager");
run("Close");
doCommand("Start Animation [\\]");

yep, the roi.setPosition(slice); before adding it to the overlay solves this thing. Thanks for everything

There is a JavaScript example in the Help>Examples>JavaScript menu (reproduced below) that shows how to add overlays to a stack.

// This script demonstrates the use of the roi.setPosition()
// and IJ.pad() methods by adding an overlay to a stack.

  img = IJ.openImage("http://imagej.nih.gov/ij/images/bat-cochlea-volume.zip");
  IJ.setThreshold(img, 255, 255);
  font = new Font("SansSerif", Font.PLAIN, 18);
  overlay = new Overlay();
  n = img.getStackSize();
  for (i=1; i<=n; i++) {
     img.setSlice(i);
     roi = ThresholdToSelection.run(img);
     roi.setPosition(i);
     roi.setStrokeColor(Color.red);
     roi.setStrokeWidth(2);
     overlay.add(roi);
     roi = new TextRoi(5, 5, IJ.pad(i,3), font);
     roi.setStrokeColor(Color.white);
     roi.setPosition(i);
     overlay.add(roi);
  }
  img.setOverlay(overlay);
  IJ.resetThreshold(img);
  img.show();
  IJ.run(img, "Set... ", "zoom=200");
  IJ.run(img, "Animation Options...", "speed=7");
  IJ.doCommand(img, "Start Animation [\\]");
3 Likes