Help with macro z stack analysis

imagej1
macro
macrorecorder
code
z-stack
imageanalysis

#1

Hello

I am trying to make this macro to analyse some ratiometric z stack (see NUMBER 1) , however, I kept getting an error at line 37 but I cannot figure it out what is wrong with the macro.
Can someone to guide me or point my error, please?
NUMBER 1

path    = getDirectory("Choose a Directory");
  list    = getFileList(path);
  length  = list.length;

  File.makeDirectory(path + "zstack/");

  //Calculation

  for (i=0; i<length; i++) {
             
    n=i+1;
    open(path+list[i]);
    img = File.nameWithoutExtension();
    selectWindow(img+".lsm");
selectWindow("z stack FRET.lsm");
run("StackReg", "transformation=Translation");
run("Subtract Background...", "rolling=300 stack");
run("Split Channels");
selectWindow("C1-z stack.lsm");
run("Z Project...", "projection=[Sum Slices]");
selectWindow("C3-z stack.lsm");
run("Z Project...", "projection=[Sum Slices]");
selectWindow("SUM_C1-z stack.lsm");
run("Median...", "radius=1.2");
run("Threshold...");
    setAutoThreshold("Default dark");
    waitForUser("Apply Threshold y click OK");
selectWindow("SUM_C3-z stack.lsm");
run("Median...", "radius=1.2");
run("Threshold...");
    setAutoThreshold("Default dark");
    waitForUser("Apply Threshold y click OK");
imageCalculator("Divide create 32-bit", "SUM_C3-z stack.lsm","SUM_C1-z stack.lsm");
selectWindow("Result of SUM_C3-z stack.lsm");
waitForUser ("Brightness/Contrast...")
selectWindow("Result of SUM_C3-z stack.lsm");
	run ("rainbow");
	run ("Calibration Bar...");
saveAs ("Tiff", path + "zstack/map AP");
run("Close All");
}

Furthermore, I would like to add another macro at NUMBER 1 - replacing the “runsubstract” -for NUMBER 2.Please see below
I want to use the option “Waitforuser” so I can draw a ROI and substract the background.
But I cannot make it work.
NUMBER 2

  macro "Subtract Measured Background 1" {
      if (selectionType==-1)
         exit("This macro requires an area selection");
      for (i=1; i<=nSlices; i++) {
          setSlice(i);
          getStatistics(area, mean);
          run("Select None");
          run("Subtract...", "value="+mean);
          run("Restore Selection");
      }
  }

I hope someone can help me with this doubts.

Thanks in advance

Pablo


#2

Does the image “Result of SUM_C3-z stack.lsm” exist?


#3

Hi Gabriel
Yes, is the result of my division between C3 and C1. After that I am getting the error


#4

There is a missing “;” after the waitForUser() call.


#5

Thank you very much Gabriel :slight_smile: I fixed it