Apply overlay to a different stack without using the ROI manager

imagej

#1

Hello,

I am trying to write an .ijm macro in which I:

  • duplicate and filter a stack
  • get coordinate arrays from thresholded structures
  • apply an overlay of these structures on their respective slices
  • Define ROIs based on the location of thresholded structures
  • send the ROIs to the ROI manager

At the moment I can do all these steps but I can only apply the overlay to the filtered stack. Because I am in a “for” loop based on the filtered stack, I don’t know how to send the overlays to their respective slices on the original stack.

The only way I can think of is to send the overlays to the ROI manager but they would then be mixed with the ROIs that I already save in this step… Here is a summary of the code structure (the original stack is called “raw” and the filtered one is called “filtered”):

selectImage("filtered");
W = getWidth; 
H = getHeight;
ARRAY = newArray(W); 
for (j=1; j<=slices; j++) { 
    showProgress(j, slices); 
    setSlice(j); 
    name = getInfo("slice.label");
    findStructures (); // Function to detect the structures
    getCurve(ARRAY); // Function to fit some structures with a line and fill ARRAY
    applyOverlay(ARRAY); // Function to apply overlay from ARRAY
    calculateROI (); // Function to calculate coordinates of rectangle ROI, relative to ARRAY
    makeRectangle (x, y, w, h);
    roiManager("Add");
    run("Select None"); }

Olivier


#2

What about getting the image IDs for both the filtered and original stacks prior to entering the loop? Then you could pass those values to your applyOverlay function and have it apply the overlay to both. Or perhaps I am missing something, I don’t fully understand what your procedure is.


#3

That was it! It is simple but I didn’t know about it. Many thanks!