Good evening everyone
I wrote a macro which first segments the nuclei of cells. I apply this mask on a second channel and I ask to create an image for each nuclei. Secondly, I look for foci in each nucleus which I will then count and whose intensity I will look at. My experience totaled about 3.6 million nuclei. The macro ran for 3 days! :-( Do you see any points that could be improved and that could reduce the processing time? Thank you all for the improvements you can make to this macro. Have a good Easter weekend Patricia Here is my code : // 1rst part dir = getDirectory("Choose a Directory "); dir2 = getDirectory("Choose_ Destination Directory "); list = getFileList(dir); setBatchMode(false); for (i=0; i<list.length; i++) { if (endsWith(list[i], "d1.C01")){ path = dir+list[i]; open(path); rename (list[i]+"_Foci"); //ouvrir image des noyaux pathNuc = replace(path, "d1.C01", "d0.C01"); fileNuc = replace(list[i], "d1.C01", "d0.C01"); open(pathNuc); rename (list[i]+"_Nuclei"); //Create Mask on nuclei setAutoThreshold("Default dark"); setOption("BlackBackground", false); run("Convert to Mask"); run("Fill Holes"); run("Watershed"); run("Set Measurements...", "area display redirect=None decimal=5"); run("Analyze Particles...", "size=10-Infinity exclude add"); roiManager("show All"); saveAs("Tiff", dir2+list[i]+"mask_nuclei"); selectWindow(list[i]+"_Foci"); nROI=roiManager("count"); for (j = 0; j < nROI; j++) { selectWindow("ROI Manager"); roiManager("Select", j); run("Colors...", "foreground=white background=black selection=yellow"); run("Duplicate...", "title="+j); run("Clear Outside"); saveAs("Tiff", dir2+list[i]+"_"+j); close(); } selectWindow("ROI Manager"); roiManager("Reset"); close(); } } run("Close All"); print("Partie 1 achevée"); // 2nd part dir2 = getDirectory("Choose_ a Directory "); //choisir le dossier dir2 de la 1ere partie dir3 = getDirectory("Choose_ Destination Directory "); list = getFileList(dir2); setBatchMode(true); for (k=0; k<list.length; k++) { if (endsWith(list[k], ".tif")){ path = dir2+list[k]; open(path); run("Enhance Contrast", "saturated=0.35"); Titre = getTitle(); run("Duplicate...", "title=[] use"); run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); setAutoThreshold("Default dark"); rename(Titre); run("Convert to Mask"); run("Set Measurements...", "area mean integrated area_fraction display redirect=None decimal=2"); run("Analyze Particles...", "size=1-50 pixel circularity=0.00-1.00 show=Overlay display summarize add"); if (roiManager("count")>0) { //recuperer la taille de l image puis Ouvrir une image vierge (toutes les images ont des tailles differentes !!) getDimensions(width, height, channels, slices, frames); //print("The image has a size of "+width+" x "+height+" pixels and "+channels+" channels."); newImage("New Image", "8-bit black", width, height, 1); roiManager("show All without labels"); //"show All with labels" run("Flatten"); run("8-bit"); pathm = dir3 + replace(list[k], ".tif", "_maskFoci.tif"); saveAs("Tiff", pathm); fileMask = replace(list[k], ".tif", "_maskFoci.tif"); //Faire le merge des 2 images channels = "c4=["+list[k]+"] c6=["+fileMask+"] keep "; run("Merge Channels...", channels); pathRGB = dir3 + replace(list[k], ".tif", "_cellFoci.tif"); saveAs("Tiff", pathRGB); //Vider la table Results selectWindow("Results"); run("Clear Results"); //Appliquer les ROI a l image native puis mesurer les intensites selectWindow(list[k]); roiManager("Show All without labels"); run("Flatten"); run("8-bit"); pathm = dir3 + replace(list[k], ".tif", "_mask.tif"); saveAs("Tiff", pathm); run("Close"); selectWindow(list[k]); roiManager("Show All"); roiManager("Measure"); selectWindow("Results"); saveAs("Results",dir3+list[k]+"_Results.xls"); run("Close"); run("Close All"); if (roiManager("count")>0) roiManager("reset"); } } } selectWindow("Summary"); saveAs("Text",dir3+"Summary.xls"); run("Close"); print("C'est fini"); _______________________________________ [http://www.cea.fr/var/cea/signatures/cea_logo.jpg]<http://www.cea.fr/> Patricia OBEÏD Ingénieur de Recherche /Animateur Informatique Biomics Institut de Recherche Interdisciplinaire de Grenoble CEA/DRF/IRIG/DS U1292 /BGE (U1038)/Biomics/Bât 4020 17 rue des martyrs 38054 Grenoble Cedex 9 Commissariat à l'énergie atomique et aux énergies alternatives Email : [hidden email]<mailto:[hidden email]> Tél : (+33)4 38 78 47 12 Fax : (+33)4 38 78 59 17 Toute notre actualité sur www.cea.fr et sur http://www.bge-lab.fr/Pages/Biomics/Presentation.aspx <http://www.cea.fr/drf/big/bge/biomics> <http://www.cea.fr/>Suivez-nous également sur Twitter : @CEA_Recherche<https://twitter.com/#!/CEA_Recherche> et sur https://twitter.com/BiomicsLab -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html image001.jpg (11K) Download Attachment |
Patricia,I suspect that most of the time is spent on file I/O, as you are storing millions of images with one nucleus each in the 1st part and then reading them back in and processing them in the 2nd part. Is it the case that each of the original images has many nuclei? If so, then it may be more efficient to read in an image, identify the nuclei, process each of these, and write the results to the Results Table. (In RAM, not saving any files until you are finished with at least a whole image.) Then read in the second image, process it, and so on. If the only product you need is the results table, then you may not need to spend time saving intermediate images.Bob
Sent from Smallbiz Yahoo Mail for iPhone On Saturday, April 3, 2021, 10:26 AM, OBEID Patricia 154904 <[hidden email]> wrote: Good evening everyone I wrote a macro which first segments the nuclei of cells. I apply this mask on a second channel and I ask to create an image for each nuclei. Secondly, I look for foci in each nucleus which I will then count and whose intensity I will look at. My experience totaled about 3.6 million nuclei. The macro ran for 3 days! :-( Do you see any points that could be improved and that could reduce the processing time? Thank you all for the improvements you can make to this macro. Have a good Easter weekend Patricia Here is my code : // 1rst part dir = getDirectory("Choose a Directory "); dir2 = getDirectory("Choose_ Destination Directory "); list = getFileList(dir); setBatchMode(false); for (i=0; i<list.length; i++) { if (endsWith(list[i], "d1.C01")){ path = dir+list[i]; open(path); rename (list[i]+"_Foci"); //ouvrir image des noyaux pathNuc = replace(path, "d1.C01", "d0.C01"); fileNuc = replace(list[i], "d1.C01", "d0.C01"); open(pathNuc); rename (list[i]+"_Nuclei"); //Create Mask on nuclei setAutoThreshold("Default dark"); setOption("BlackBackground", false); run("Convert to Mask"); run("Fill Holes"); run("Watershed"); run("Set Measurements...", "area display redirect=None decimal=5"); run("Analyze Particles...", "size=10-Infinity exclude add"); roiManager("show All"); saveAs("Tiff", dir2+list[i]+"mask_nuclei"); selectWindow(list[i]+"_Foci"); nROI=roiManager("count"); for (j = 0; j < nROI; j++) { selectWindow("ROI Manager"); roiManager("Select", j); run("Colors...", "foreground=white background=black selection=yellow"); run("Duplicate...", "title="+j); run("Clear Outside"); saveAs("Tiff", dir2+list[i]+"_"+j); close(); } selectWindow("ROI Manager"); roiManager("Reset"); close(); } } run("Close All"); print("Partie 1 achevée"); // 2nd part dir2 = getDirectory("Choose_ a Directory "); //choisir le dossier dir2 de la 1ere partie dir3 = getDirectory("Choose_ Destination Directory "); list = getFileList(dir2); setBatchMode(true); for (k=0; k<list.length; k++) { if (endsWith(list[k], ".tif")){ path = dir2+list[k]; open(path); run("Enhance Contrast", "saturated=0.35"); Titre = getTitle(); run("Duplicate...", "title=[] use"); run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); setAutoThreshold("Default dark"); rename(Titre); run("Convert to Mask"); run("Set Measurements...", "area mean integrated area_fraction display redirect=None decimal=2"); run("Analyze Particles...", "size=1-50 pixel circularity=0.00-1.00 show=Overlay display summarize add"); if (roiManager("count")>0) { //recuperer la taille de l image puis Ouvrir une image vierge (toutes les images ont des tailles differentes !!) getDimensions(width, height, channels, slices, frames); //print("The image has a size of "+width+" x "+height+" pixels and "+channels+" channels."); newImage("New Image", "8-bit black", width, height, 1); roiManager("show All without labels"); //"show All with labels" run("Flatten"); run("8-bit"); pathm = dir3 + replace(list[k], ".tif", "_maskFoci.tif"); saveAs("Tiff", pathm); fileMask = replace(list[k], ".tif", "_maskFoci.tif"); //Faire le merge des 2 images channels = "c4=["+list[k]+"] c6=["+fileMask+"] keep "; run("Merge Channels...", channels); pathRGB = dir3 + replace(list[k], ".tif", "_cellFoci.tif"); saveAs("Tiff", pathRGB); //Vider la table Results selectWindow("Results"); run("Clear Results"); //Appliquer les ROI a l image native puis mesurer les intensites selectWindow(list[k]); roiManager("Show All without labels"); run("Flatten"); run("8-bit"); pathm = dir3 + replace(list[k], ".tif", "_mask.tif"); saveAs("Tiff", pathm); run("Close"); selectWindow(list[k]); roiManager("Show All"); roiManager("Measure"); selectWindow("Results"); saveAs("Results",dir3+list[k]+"_Results.xls"); run("Close"); run("Close All"); if (roiManager("count")>0) roiManager("reset"); } } } selectWindow("Summary"); saveAs("Text",dir3+"Summary.xls"); run("Close"); print("C'est fini"); _______________________________________ [http://www.cea.fr/var/cea/signatures/cea_logo.jpg]<http://www.cea.fr/> Patricia OBEÏD Ingénieur de Recherche /Animateur Informatique Biomics Institut de Recherche Interdisciplinaire de Grenoble CEA/DRF/IRIG/DS U1292 /BGE (U1038)/Biomics/Bât 4020 17 rue des martyrs 38054 Grenoble Cedex 9 Commissariat à l'énergie atomique et aux énergies alternatives Email : [hidden email]<mailto:[hidden email]> Tél : (+33)4 38 78 47 12 Fax : (+33)4 38 78 59 17 Toute notre actualité sur www.cea.fr et sur http://www.bge-lab.fr/Pages/Biomics/Presentation.aspx <http://www.cea.fr/drf/big/bge/biomics> <http://www.cea.fr/>Suivez-nous également sur Twitter : @CEA_Recherche<https://twitter.com/#!/CEA_Recherche> et sur https://twitter.com/BiomicsLab -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |