/* Calibration_Menu.ijm * https://github.com/tferr/Scripts#scripts * An IJ Menu Tool providing shortcuts for spatial calibration of images lacking metadata. * * - Place this file in ImageJ/plugins/Tools/. Re-start ImageJ. Load it using the ">>" * drop-down menu in the main ImageJ window * - Create "Calibration files" for each of your microscopes. These are simple 3-column * .csv tables listing the objective, pixel size and unit. Choose "Demo File..." for * more details * - Settings are stored in the image header (Image>Show Info...) upon calibration */ // Editable variables var prmpt= false; // With stacks and hyperstacks, should you be prompted for voxel depth? var cpath= getDirectory("imagej") + "Microscope Profiles Collection/"; // Path to calibration files var tpath= getDirectory("plugins") + "Tools/Calibration_Menu.ijm"; // Path to this file // Fixed variables var cFile= call("ij.Prefs.get", "qcm.file", " "); var fList= extractListfromFile(""+ cpath +""+ cFile); var oList= getArrayfromList("Lns", true, cFile); var cList= getArrayfromList("Cal", false, "-"); var uList= getArrayfromList("Unt", false, "-"); var fMenu= newMenu("Calibration Menu Tool", oList); macro "Calibration Menu Tool - C037L101fL0020L0f2fL0323L0626L0929L0c2c D4fD5fD68D69D6aD6fD76D7aD7bD7cD7dD7fD8aD8fD90D91D92D93D94D95D96D97D98D9aD9dD9fDaaDafDbfD86D77DbaD5eD6eD7eD8eD9eDa3Da4Da5Da6Da7DaeDbeD85D67DcfD78D79D87D8bD8cD8dDa0Da1Da2Da8Dad" { cmd= getArgument(); if (endsWith(cmd, ".csv") || endsWith(cmd, "not defined...")) getCSVchoice(); else if (endsWith(cmd, "Scale Bar...")) run(cmd); else if (cmd=="Remove Scale") setVoxelSize(1, 1, 1, "pixels"); else if (cmd!="-") { for (i=0; i1 || frames>1)) run("Properties..."); } } } } function extractListfromFile(calFile) { if (File.exists(calFile)) { rawCal= File.openAsRawString(calFile); list= split(rawCal,"\n"); lgth= list.length; for (i=1; iUse this Menu Tool to spatially calibrate images lacking detailed metadata.

" +"Select the csv file corresponding to the device used to acquire the image.

" +"Select Demo File... to generate a template to be edited by an external spreadsheet

" +"application.

" +"To apply global calibrations, i.e., to propagate the chosen calibration to all open

" +"images, activate the Global checkbox in Image>Properties... [P] (titles of image

" +"windows will be labeled with a '(G)').

" +"Calibration settings are loaded from .csv files stored in:

" +"  "+ cpath +""); Dialog.setInsets(-2, 105, 10); Dialog.addCheckbox("Open selected file", false); Dialog.addCheckbox("Prompt for voxel depth", prmpt); Dialog.show; file= Dialog.getChoice; opn= Dialog.getCheckbox; prmpt= Dialog.getCheckbox; if (file==list[count]) { if (!File.exists(cpath+"DemoMicroscope.csv")) { f= File.open(cpath+"DemoMicroscope.csv"); print(f, "Lens, Pixel Size, Unit, Comments"); print(f, "10x Ph2 NEOFL, 0.660, um, some comment here"); print(f, "20x Plan 0.65, 0.331, um, some other comment here"); File.close(f); } file= "DemoMicroscope.csv"; } if (opn) open(cpath+file); if (file!=cFile) { call("ij.Prefs.set", "qcm.file", file); if (File.exists(tpath)) run("Install...", "install=["+ tpath +"]"); else showMessage("Tool could not be reloaded", tpath +"\nwas not found. You must install the tool manually to reload the new settings."); } }