Disabling dialog box or overwriting user inputs

imagej

#1

Hello everyone! I am still new to ImageJ and am stuck on one problem. I couldn’t find anything else on the internet.

I have one macro for characterizing particles in an image and it works great. It takes user inputs as some variables and produces the results. I need to repeat this for multiple similar images, so i decided to make a batch macro. The batch macro also works great, opening the image calling on macro 1, saving all the results to a new folder, closing everything and opening the next image. At this step, however, the user input dialog box opens up again (these inputs should be the same for all images). Is there a way to disable the dialog box of the first macro, through the second one?

First macro:

    run("Set Measurements...", "area feret's redirect=None decimal=4");

    //Setting the scale
     Dialog.create("Lets define some variables");
     Dialog.addNumber("Distance in pixels:" , 213);
     Dialog.addNumber("Known distance:", 1);
     Dialog.addNumber("Pixel aspect ratio:", 1);
     Dialog.addString("Units", "um");
     Dialog.addCheckbox("Need crop?", true); 
     Dialog.addNumber("% bottom cropped:", 7);
     Dialog.addNumber("Smallest particle area [px]:", 15);
     Dialog.addNumber("Largest particle area [px]:", 10000);
     Dialog.addNumber("Minimum particle circularity:", 0.3);
     Dialog.addNumber("Maximum particle circularity:", 1);
     Dialog.addNumber("Outlier radius [px]:", 2);
     Dialog.addCheckbox("Dark background", false); 
     Dialog.show();
     d=Dialog.getNumber();
     D=Dialog.getNumber();
     p=Dialog.getNumber();
     u=Dialog.getString();
     crop=Dialog.getCheckbox();
     bc=Dialog.getNumber();
     s=Dialog.getNumber();
     L=Dialog.getNumber();
    mc=Dialog.getNumber();
    Mc=Dialog.getNumber();
    CO=Dialog.getNumber();
    bac=Dialog.getCheckbox();

  run("Set Scale...", "distance="+d+" known="+D+" pixel="+p+" unit="+u);
  more code...

Second macro:

input = getDirectory("Input directory");
output = getDirectory("Output directory");

suffix = ".tif";  //you only want to apply to tiff images, no need to ask

processFolder(input);

function processFolder(input) {
list = getFileList(input);
for (i = 0; i < list.length; i++) {
    if(File.isDirectory(input + list[i]))   //if it's a directory, go to subfolder
        processFolder("" + input + list[i]);
    if(endsWith(list[i], suffix))   //if it's a tiff image, process it
        
        processFile(input, output, list[i]);
        Out = output + "/" + list[i] + "/";
        File.makeDirectory(Out);
     	selectWindow("Overlay-1.TIF"); 
     	saveAs("Tiff", Out + "Overlay"); 
     	selectWindow("Binary.TIF");
     	saveAs("Tiff", Out + "Binary"); 
     	run("Close All"); 
  }       
} 

function processFile(input, output, file) {
print("Processing: " + input + file);
open(input + file);  //open image
run("Macro1" );
}

#2

@Stoichko_Antonov

As opposed to those older Dialog calls - have a look at Script Parameters… they will be a life-saver - trust me! :slight_smile: There is a great example in the Script Editor showing off all the types of Parameters - just go to Templates > Intro > Widgets (either example script there). And then you should be able to merge those two ‘macros’ together …

Hope this helps a bit!

eta :slight_smile: