Macro with Roi manager with empty list

Hello,

I have a problem with my macro, especially when my ROI manager is empty. Let me explain. I have two images, one with my nucleus and another with my green signal. I duplicate my green image then I analyze my green signal with a threshold and a analyse particle . The obtained ROI are stored in the ROI manager. Then I make an overlay of my ROI on the original image with the option overlay -> from ROI manager and I save this in jpg. Everything is ok on the images with green signal but on images controls without signal, I have the window manager that closes and a message telling me that the ROI manager is not open. How could I solve this problem?

Here is the macro in question:

path = getDirectory(""); 
outputFolder = getDirectory(""); 
filelist = getFileList(path); // charge toute les images
for (i=0; i< filelist.length; i++) {
      //Ne marche que sur des .vsi
     if (endsWith(filelist[i], ".vsi")) {
         //Ouverture des fichiers via Bio-format
run("Bio-Formats Importer", "open=[" + path + filelist[i] + "] autoscale color_mode=Default view=Hyperstack stack_order=XYCZT series_1");
run("ROI Manager...");
roiManager("reset")
roiManager("Associate", "true");
imageTitle = getTitle();
run("Split Channels");
selectWindow("C3-"+imageTitle);
close();
selectWindow("C1-"+imageTitle);
run("Subtract Background...", "rolling=50");
run("Auto Threshold", "method=Triangle white");
run("Median...", "radius=2");
run("Fill Holes");
run("Watershed");
run("Analyze Particles...", "size=100-Infinity show=Masks exclude");
//selectWindow("Mask"+imageTitle);
run("Invert");
rename("Noyaux");
selectWindow("C2-"+imageTitle);
run("Subtract Background...", "rolling=50");
run("Duplicate...", "title=Cellules vertes");
run("8-bit");
run("Auto Local Threshold", "method=Phansalkar radius=100 parameter_1=0 parameter_2=0 white");
run("Median...", "radius=2");
run("Analyze Particles...", "size=150-Infinity show=Masks exclude");
run("Invert");
rename("Green");
run("Binary Feature Extractor", "objects=Noyaux selector=Green object_overlap=100 count");
imageCalculator("Add create", "Noyaux","Extracted_Noyaux-1");
selectWindow("Result of Noyaux");
rename("Noyaux "+imageTitle);
run("Set Measurements...", "display redirect=None decimal=2");
run("Analyze Particles...", "exclude summarize add");
selectWindow("C2-"+imageTitle);
setMinAndMax(10,1000 );
run("From ROI Manager");
saveAs("Jpeg", outputFolder+getTitle);
selectWindow("Extracted_Noyaux-1");
close();
selectWindow("Green");
close();
selectWindow("Noyaux");
close();
selectWindow("Noyaux "+imageTitle);
close();
selectWindow("C1-"+imageTitle);
close();
selectWindow("C2-"+imageTitle);
close();
selectWindow("cellules vertes");
close();
selectWindow("BFE_Results");
run("Close")
}
	}

Thank a lot

Romain

Hi Romain,

I think you need to insert something like below for the overlay command that uses the ROIs. On the images where no ROIs were created by Analyze Particles then the line will be skipped and so you should be able to avoid the errors you are getting.

if (roiManager("Count") > 0){
	run("From ROI Manager");
}

Good luck,

Laura

1 Like

Thanks a lot Laura,

It’s works!!

Have a nice day

Romain

1 Like