/* * Close image or nonimage window */ function closeAll(type) { if (type=="nonimage") { liste = getList("window.titles"); if (liste.length==0) print("No non-image windows are open"); else { print("Non-image windows:"); for (i=0; i 0) { //Save Roi Set File.makeDirectory(roiDir); roiManager("Save", roiDir+name+".zip"); print("ROI Set Saved for image "+name); } } /* * Allows for easily renaming the last added ROI */ function renameLastRoi(name) { nRois = roiManager("Count"); roiManager("Select", nRois-1); roiManager("Rename", name); } /* add on 2014.12.01 * Allows for easily renaming ROIs , * from the firtROI to the lastRoi(included) * using patternName */ function renameROI(firstROI,lastRoi,patternName,separator, padding){ counter=1; for (currentROI = firstROI ; currentROI <= lastRoi ;currentROI++){ counterPad = IJ.pad(counter, padding); roiManager("select", currentROI); roiManager("Rename", patternName+separator+counterPad); counter++; } } /* * Returns index of first ROI that matches * the given regular expression */ function findRoiWithName(roiName) { nR = roiManager("Count"); for (i=0; i0) { clippedIdx = Array.trim(roiIdx,k); } return clippedIdx; } /* * Saves the current image as a TIFF in the SaveFolder */ function saveCurrentImage() { name = getTitle(); dir = getSaveFolder(); File.makeDirectory(dir); name = getFileNameNoExt(name); saveAs("TIFF", dir+name+".tif"); } /* * Saves the current image as a Specified Format in the SaveFolder */ function saveCurrentImageAs(fileFormat) { name = getTitle(); name = getFileNameNoExt(name); dir = getSaveFolder(); File.makeDirectory(dir); run("Bio-Formats Exporter", "save=["+dir+name+"."+fileFormat+"]"); } /* * Returns the file name witout the extension */ function getFileNameNoExt(file) { // Get the file name without the extension, regex if (matches(file,".+\\.\\w{3,4}")) { file = substring(file,0,lastIndexOf(file,".")); } return file; } /* * Generic function to calculate the calibration of the image based on the * CCD Pixel size, Magnification, c-mount and binning */ function setCalibration() { go = true; // Check if the image is calibrated already getVoxelSize(width, height, depth, unit); if( unit != "pixel") { go = getBoolean("Image already has a calibration. Continue?"); } // Prompt for acquisition details to set calibration if (go) { //Calibration for the image Dialog.create("Set Pixel Size for your data"); Dialog.addNumber("Magnification", 63, 0,5,"x"); Dialog.addNumber("Binning", 1,0,5,"x"); Dialog.addNumber("CCD Size", 6.45, 2,5,"microns"); Dialog.addNumber("c-Mount Size", 1.0, 1,5,"x"); Dialog.show(); // Recover the values for magnification mag = Dialog.getNumber(); bin = Dialog.getNumber(); ccd = Dialog.getNumber(); cm = Dialog.getNumber(); // Basic formula for calculating pixel size of a camera pixelSize=(ccd*bin)/(mag*cm); // If we decided not to set the calibration but use the already existing one } else { pixelSize=width; } // Set the Pixel Size in the Log Window and return it if needed. setData("Pixel Size", pixelSize); return pixelSize; //Does nothing to the image. } /* * This function writes a result to a results table called 'tableName', at : * - a specified row (specify a number) * or * - the current row (nResults-1) * or * - the next row (nResults) */ function writeResults(tableName, column, row, value) { if(isOpen("Results")) { IJ.renameResults("Results","Temp"); } if(isOpen(tableName)) { // The only way to write to a results table in macro language is to // have the table be called "Results", so we rename it if it already exists IJ.renameResults(tableName,"Results"); }else{ run("Set Measurements...", " display redirect=None decimal=5"); run("Measure"); IJ.deleteRows(0, 0); updateResults(); } // Now we can set the data if(row == "Current"){ if( nResults == 0) { setResult(column, nResults,value); // Special case, no results table is open } else { setResult(column, (nResults-1),value); } } else if(row == "Next"){ setResult(column, nResults,value); } else { setResult(column, row,value); } // Call updateResults to have the table appear if it's new updateResults(); // And rename the results to 'tableName' IJ.renameResults("Results", tableName); if(isOpen("Temp")) { IJ.renameResults("Temp","Results"); } } /* * Prepare a new table or an existing table to receive results. */ function prepareTable(tableName) { updateResults(); if(isOpen("Results")) { IJ.renameResults("Results","Temp"); updateResults();} if(isOpen(tableName)) { IJ.renameResults(tableName,"Results"); updateResults();} } /* * Once we are done updating the results, close the results table and give it its final name */ function closeTable(tableName) { updateResults(); if(isOpen("Results")){ IJ.renameResults("Results",tableName); updateResults();} if(isOpen("Temp")) { IJ.renameResults("Temp","Results"); updateResults();} } /* * Function to draw ROIs using right click button. Give it a category name and it will do the rest. */ function DrawRoisL(category) { //defaultROIcolor = Roi.getDefaultColor; if (getVersion>="1.37r") setOption("DisablePopupMenu", true); // Setup some variables. Basically these numbers // Represent an action that has taken place (it's the action's ID) shift=1; ctrl=2; rightButton=4; alt=8; leftButton=16; insideROI = 32; // requires 1.42i or later // Now we initialize the ROI counts and check if there are already ROIs with this name. nRois = roiManager("count"); roiNum = 0; for (i=0; i