Search code examples
javajavascriptimageloopsimagej

ImageJ JavaScript, how do I cycle through directories?


I am trying to create a script that will cycle through directories and open an image and analyse it etc..

so I would like to convert something like the script below into a loop;

//sets the pixel height and width

height = 15; 
width = 15;

//navigates to the folder and opens the image

IJ.run("Raw...", "open=[C:\\Users\\Documents\\Ru\\simulations_Ru\\Batch1_sc\\1 Atoms\\15x15_stem_image00001_total_df_00001.bin] image=[64-bit Real] width=15 height=15 offset=0 number=1 gap=0");


imp = IJ.getImage();

//selects a region of interest I want to make measurements from

imp.setRoi(0, 0, width, height);


//makes the measurement

IJ.run(imp, "Measure", "");


//closes the image

imp.close();

What I'd like to know is how can I turn this into a loop (instead of having to type commands for each folder) so it iterates over the number of specific folders


Solution

  • height = 15; 
    width = 15;
    
    var cmds = //cmds is a shortage of commands
    [
         "open=[C:\\Users\\Documents\\Ru\\simulations_Ru\\Batch1_sc\\1 Atoms\\15x15_stem_image00001_total_df_00001.bin] image=[64-bit Real] width=15 height=15 offset=0 number=1 gap=0",
         "another command",
         "and so on..."
    ];
    
    for(var i in cmds)
    {
      IJ.run("Raw...", cmds[i]);
    
    
      imp = IJ.getImage();
      imp.setRoi(0, 0, width, height);
      IJ.run(imp, "Measure", "");
    
      imp.close();
    }