Почему мой для l oop не увеличивается с шагом? - PullRequest
0 голосов
/ 05 марта 2020

Я пишу макрос в imagej для пакетного анализа фотографий в папке. Когда я запускаю макрос, кажется, что код выполняется только один раз и не переходит к следующему файлу. Я считаю, что это проблема в моем блоке кода, а не фактическая для утверждения. Если бы кто-нибудь мог указать, что может быть причиной этого, я был бы очень признателен. Код скопирован ниже. For for l oop начинается в строке 23, а выполняемая функция - в строке 32.

Dialog.create("Our Batch Analysis");    //providing choises about analysis 
Dialog.addNumber("Min Size", 1000);
Dialog.addNumber("Max Size", 9999999);
Dialog.addCheckbox("View Obect Outlines", false);

smoothArray=newArray("Mean...", "Median...", "None");
Dialog.addChoice("Smooth Filter", smoothArray, "Mean");

Dialog.show();

our_min=Dialog.getNumber();     //assigning the collected values to variables to be used in analyzeImage
our_max=Dialog.getNumber();
our_outlines=Dialog.getCheckbox();
our_smooth=Dialog.getChoice();

our_dir=getDirectory("Choose Source Directory");    //Choosing the folder to analyze 
our_list=getFileList(our_dir);


for(i=0; i<our_list.length; i++)    //cycling through images in folder
{
if(endsWith(our_list[i],".jpg"))        //only analyzing images no text files
{
open(our_dir + our_list[i]);
analyseImage();
}
}

analyseImage();     //declaring function 
function analyseImage()
{
origTitle= getTitle () ;    //creating a callable title 
run("Duplicate...", "title=duplicate");  //making a duplicate file to work with without affecting original
run("Gaussian Blur...", "sigma=2");
if(our_smooth!="None")      //making smoothing conditional
{run(our_smooth, "radius=2");
setAutoThreshold("Default");        //setting a threshold to differentiate background
setThreshold(0, 127); 
setOption("BlackBackground", true);
run("Convert to Mask");     //turning the image binary
run("Watershed");
run("Set Measurements...", "area mean shate display redirect=[" + origTitle + "] decimal =2");

if(our_outlines==true)
{
run("Analyze Particles...", "size=" +our_min+"-"+our_max+" circularity =0.80-1.00 show=Outlines display exclude");  
rename(origTitle+"-outlines");
selectWindow(origTitle+"-outlines");
close();
}
else
{
run("Analyze Particles...", "size=" +our_min+"-"+our_max+" circularity =0.80-1.00 show=Nothing display exclude");   //counting how many particles exist based on given parameters
}

selectImage(origTitle); //closing unwanted tabs
close();    
selectImage("duplicate");
close();
}

1 Ответ

0 голосов
/ 06 марта 2020

Функция не завершилась sh, поэтому значение l oop не увеличилось. Вы можете добавить оператор return в конце вашей функции, чтобы сообщить l oop, что функция завершена. Я также улучшил читабельность вашего кода. Обратите внимание, что дополнительный вызов analyseImage() не был необходим.

Dialog.create("Our Batch Analysis");    //providing choices about analysis 
Dialog.addNumber("Min Size", 1000);
Dialog.addNumber("Max Size", 9999999);
Dialog.addCheckbox("View Obect Outlines", false);

smoothArray=newArray("Mean...", "Median...", "None");
Dialog.addChoice("Smooth Filter", smoothArray, "Mean");

Dialog.show();

our_min=Dialog.getNumber();     //assigning the collected values to variables to be used in analyzeImage
our_max=Dialog.getNumber();
our_outlines=Dialog.getCheckbox();
our_smooth=Dialog.getChoice();

our_dir=getDirectory("Choose Source Directory");    //Choosing the folder to analyze 
our_list=getFileList(our_dir);

//cycling through images in folder
for(i=0; i<our_list.length; i++) {
    //only analyzing images no text files
    if(endsWith(our_list[i],".jpg"))    {
        open(our_dir + our_list[i]);
        analyseImage();
    }
}

//analyseImage();     //declaring function 
function analyseImage() {
    origTitle= getTitle () ;    //creating a callable title 
    run("Duplicate...", "title=duplicate");  //making a duplicate file to work with without affecting original
    run("Gaussian Blur...", "sigma=2");
    if(our_smooth!="None")      //making smoothing conditional
        {run(our_smooth, "radius=2");
    setAutoThreshold("Default");        //setting a threshold to differentiate background
    setThreshold(0, 127); 
    setOption("BlackBackground", true);
    run("Convert to Mask");     //turning the image binary
    run("Watershed");
    run("Set Measurements...", "area mean shate display redirect=[" + origTitle + "] decimal =2");

    if(our_outlines==true)  {
        run("Analyze Particles...", "size=" +our_min+"-"+our_max+" circularity =0.80-1.00 show=Outlines display exclude");  
        rename(origTitle+"-outlines");
        selectWindow(origTitle+"-outlines");
        close();
    } else {
        run("Analyze Particles...", "size=" +our_min+"-"+our_max+" circularity =0.80-1.00 show=Nothing display exclude");   //counting how many particles exist based on given parameters
    }

    selectImage(origTitle); //closing unwanted tabs
    close();    
    selectImage("duplicate");
    close();
    return 0;
}
...