Login  Register

Problem about macro Math function--add variable values from an array to a stack

Posted by Hailin CHEN on Nov 09, 2015; 1:50pm
URL: http://imagej.273.s1.nabble.com/Problem-about-macro-Math-function-add-variable-values-from-an-array-to-a-stack-tp5014898.html

Hello,

I am a new Image J macro writing, I want to use math function in Fiji, to add values from an array table to each slice of a stack.But it told me that the values are not numeric.Hope someone helps me out, thanks a lot!
Here is my marco:
   run("Close All");
   run("Clear Results");
    path = File.openDialog("Select a File");
    dir = File.getParent(path);
    name = File.getName(path);
      open(path);
       //duplicates to do Gaussian Blur
         run("Duplicate...", "duplicate channels=1");
         n1=nSlices();
         run("Gaussian Blur...", "sigma=100 stack");
       //measure mean intensity of each slices, put them in an array
            Ar=newArray(n1);
              h=getHeight();
              w=getWidth();
              for (i=0;i<n1;i++){
                   setSlice(i+1);
                   makeRectangle(0,0,w,h);
                   run("Measure");
                  Ar[i]= getResult("Mean",i);                                            
                                                               }                                            
              // duplicate window and change format to 32bit                                  
              selectWindow(name);
                run("Duplicate...", "duplicate channels=1");
                run("32-bit");
                // Add intensity value in array I to each slice respectively
                for (i=1;i<=n1;i++){
                setSlice(i);
                run("Add...", "value=Ar[i-1] Slice");
                }