/* Bertrand Vernay * Imaging Centre IGBMC * vernayb@igbmc.fr * September 2020 * * Requirement: * - a folder containing a png image and a ROiSet named "image name"_RoiSet.zip * * How to use: * - start the macro * - select the image * - once the macro is finished, open the txt file in Fiji and save as .xml * - the xml file in now readable by LabelImg https://github.com/tzutalin/labelImg * * Improvement: * - why changign txt to xml does not make the xml file readbale. Have to open iin Fiji and save as xml. * */ print("\\Clear"); roiManager("reset"); // Open the png file open(); name = File.nameWithoutExtension; // Get the name of the image containing folder dir = File.directory; parentDir = File.getParent(dir); folder = substring(dir, lengthOf(parentDir)+1, lengthOf(dir)-1 ); //get the dimensions of the image getDimensions(width, height, channels, slices, frames); // Open the corresponding RoiSet open(dir+name+"_RoiSet.zip"); // Tag name selection (single tag for the moment) tagName = getString("Tag for the annotation", "yeast"); // XML format for LabelImg (https://github.com/tzutalin/labelImg) /* " */ // Builging the text file in log for final xml print(""); print("\t"+folder+""); print("\t"+name+".png"); print("\t"+dir+name+".png"); print("\t"); print("\t\tUnknown"); print("\t"); print("\t"); print("\t\t"+width+""); print("\t\t"+height+""); print("\t\t1"+""); print("\t"); print("\t0"); for (i = 0; i"); print("\t\t"+tagName+""); print("\t\tUnspecified"); print("\t\t0"); print("\t\t0"); roiManager("select", i); getBoundingRect(x, y, roiWidth, roiHeight); print("\t\t"); print("\t\t\t"+x+""); print("\t\t\t"+y+""); print("\t\t\t"+(roiWidth+x)+""); print("\t\t\t"+(roiHeight+y)+""); print("\t\t"); print("\t"); } print(""); // Save log window as ."image name".txt selectWindow("Log"); saveAs("Text", dir+name+".txt"); close();