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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Hailin CHEN
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");
                }
Reply | Threaded
Open this post in threaded view
|

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

Ali_
Original code:
run("Add...", "value=Ar[i-1] Slice");

Modified code:
run("Add...", "value=" + (Ar[i-1]) + " Slice");

The command requires a string. So, the "numerical" value of an array element should be converted to "character".