print("\\Clear") // MIT License // Copyright (c) 2018 Nicholas Condon n.condon@uq.edu.au // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. //IMB Macro Splash screen (Do not remove this acknowledgement) scripttitle="Dual Camera Alignment Batch Processor"; version="2.0"; versiondate="18/06/2019"; description="This macro allows for manual re-alignment of two channel images in a batch mode.

"+ "Initially only one image will open and be maximum projected (if required). Following this, the user has the option to adjust"+ " the following parameters on the channel of their choice, X/Y translation, rotation, and both horizontal & vertical flipping."+ "

NOTE: The macro requires all images within a directory have the same file extension (eg .tif). Output files will be "+ "placed into a sub directory within the working directory, along with a log file of the parameters chosen."; showMessage("Institute for Molecular Biosciences ImageJ Script", "" +"

ACRF: Cancer Biology Imaging Facility

+"

The Institute for Molecular Bioscience
The University of Queensland

+"

ACRF: Cancer Biology Imaging Facility<\h4>" +"

ImageJ Script Macro: "+scripttitle+"

" +"Version: "+version+" ("+versiondate+")" +"

Created by Nicholas Condon

" +" contact n.condon@uq.edu.au \n " +" Available for use/modification/sharing under the "+"MIT License<\h4> " +"

<\h3>" +""+description+"" +"

" +" " +""); //Log Window Title and Acknowledgement print(""); print("FIJI Macro: "+scripttitle); //Reports to log Script title print("Version: "+version+" Version Date: "+versiondate); //Reports to log Script Version and version date print("ACRF: Cancer Biology Imaging Facility"); //Reports to log Facility information print("By Nicholas Condon (2019) n.condon@uq.edu.au") //Reports to log Script author details print(""); getDateAndTime(year, month, week, day, hour, min, sec, msec); //Creates date and time Variables print(""); print("Script Run Date: "+day+"/"+(month+1)+"/"+year+" Time: " +hour+":"+min+":"+sec); //Reports script run date and time ext = ".czi" //Variable for file extension default (string) Dialog.create("Select Global Parameters"); //Creates dialog for Global parameter options Dialog.addChoice("Type:", newArray("GFP-RFP", "CFP-YFP")); //Dialog input for channel merging options Dialog.addRadioButtonGroup("Offset Parameters", newArray("Unknown", "Known"), 1, 2, "Unknown"); //Dialog input for parameter input radio buttons Dialog.addString("File extension:", ext); //Dialog input for file extension Dialog.addChoice("Run Z-Projection (Parameter Mode)", newArray("Max Intensity", "Min Intensity", "Average Intensity", "Sum Slices", "No Projection")); //Dialog input for interactive mode z-projections Dialog.addChoice("Run Z-Projection (Output Mode)", newArray("No Projection", "Min Intensity", "Average Intensity", "Sum Slices", "Max Intensity")); //Dialog input for output mode z-projections Dialog.addCheckbox("Batch Mode On", 1); //Dialog input for batch mode Dialog.show(); dye = Dialog.getChoice(); //Variable for dye selection for channel merging settings (String) ParameterMode = Dialog.getRadioButton(); //Variable for manual input of translation values or interactive mode (String) ext = Dialog.getString(); //Variable for file extension (String) Paramprojectiontype = Dialog.getChoice(); //Variable for interactive mode z-projection (String) Outputprojectiontype = Dialog.getChoice(); //Variable for output mode z-projection (String) batch = Dialog.getCheckbox(); //Variable for batch mode (Boolean) print(""); print("***** Global Macro Parameters *****") //Reports to log Global Parameters print("Dye Output Option Selected = "+dye); //Reports to log dye settings if (ParameterMode == "Unknown"){print("Paramater determination Mode has been selected"); //Reports to log Interactive mode for Parameter determination ManualMode = 1; endManual = 0; testXoffset = 0; testYoffset = 0; testRoffset = 0; flipH = 0; flipV = 0;} //Defines variable status for interactive mode if (ParameterMode == "Known"){print("Manual Input Mode selected"); //Reports to log Manual input mode has been selected endManual = 0; ManualMode = 0;} //Defines variable status for manual mode print("File extension = "+ext); //Reports to log file extension filter print("Z Projection option for Interactive Parameter Mode: "+Paramprojectiontype); //Reports to log interactive mode projection type print("Z Projection option for Output Mode: "+Outputprojectiontype); //Reports to log output mode projection type if (batch==1){setBatchMode(true); print("Running in batch mode.");} //Reports to log batch mode status if (batch==0){setBatchMode(true); print("Not Running in batch mode.");} //Reports to log batch mode status if (ParameterMode == "Known") { //Enters into manual input mode if selected Dialog.create("Enter Existing Parameters"); //Creates existing parameter input dialog Dialog.addNumber("Channel to perform manipulations on:", 1); //Dialog input for channel number to perform manipulations on Dialog.addNumber("X-Offset", 0); //Dialog input for x-offset translation value Dialog.addNumber("Y-Offset", 0); //Dialog input for y-offset translation value Dialog.addCheckbox("Horizontal Flip",0); //Dialog input for Horizontal flip Dialog.addCheckbox("Vertical Flip",0); //Dialog input for Vertical flip Dialog.addNumber("Image Rotation", 0); //Dialog input for rotation value Dialog.show(); workingCh = Dialog.getNumber(); //Variable for working channel selection (Number) testXoffset = Dialog.getNumber(); //Variable for x-offset translation value (Number) testYoffset = Dialog.getNumber(); //Variable for y-offset translation value (Number) flipH = Dialog.getCheckbox(); //Variable for Horizontal flip (Boolean) flipV = Dialog.getCheckbox(); //Variable for Vertical flip (Boolean) testRoffset = Dialog.getNumber(); //Variable for image rotation (Number) print(""); print("***** Manual Offsets *****"); //Reports to log manual offset configuration print("Working channel for Manipulations: "+workingCh); //Reports to log working channel print("X Offset Chosen: "+testXoffset); //Reports to log X-offset translation value print("Y Offset Chosen: "+testYoffset); //Reports to log Y-offset translation value if (flipH== 0){print("Channel Flipped Horizontally: No");} //Reports to log horizontal flip status if (flipH== 1){print("Channel Flipped Horizontally: Yes");} //Reports to log horizontal flip status if (flipV== 0){print("Channel Flipped Vertically: No");} //Reports to log vertical flip status if (flipV== 1){print("Channel Flipped Vertically: Yes");} //Reports to log vertical flip status print("Image Rotation Angle: "+testRoffset); //Reports to log rotation value } path = getDirectory("Choose Source Directory "); //Dialog input for directory location list = getFileList(path); //Variable for file list (Array) resultsDir = path+"Corrected-Output_"+"_"+year+"-"+month+"-"+day+"_at_"+hour+"."+min+"/"; //Variable for output directory (String) File.makeDirectory(resultsDir); //Creates output directory while (endManual == 0 && ManualMode == 1){ //Enters into interactive mode setBatchMode(false); //Turns off batch mode open(path+list[1]); //Opens the first available image for alignment windowtitle = getTitle(); //Variable for image file name (String) if (Paramprojectiontype!="No Projection") { //Enters into projection loop if required print("Performing Z-Projection on parameter check image"); //Reports to log z-projection has been done run("Z Project...", "projection=["+Paramprojectiontype+"] all");} //Completes Z-projection as per user input setSlice(1); run("Enhance Contrast", "saturated=0.35"); //Sets Brightness & Contrast for Ch1 to 35% saturated setSlice(2); run("Enhance Contrast", "saturated=0.35"); //Sets Brightness & Contrast for Ch2 to 35% saturated run("Duplicate...", "title=test duplicate"); //Creates a working copy of the image run("Duplicate...", "title=test-1 duplicate"); //Creates a backup copy of the image testtitle = getTitle(); //Variable for interactive test image (String) getDimensions(width, height, channels, slices, frames); //Gets image dimensions Dialog.create("Manipulation Options"); //Creates dialog for Interactive mode image manipulations Dialog.addSlider("Channel to perform manipulations on:", 1, channels, 1); //Dialog input for working channel Dialog.addSlider("X offset", -20, 20, testXoffset); //Dialog input for X-offset translations Dialog.addSlider("Y offset", -20, 20, testYoffset); //Dialog input for Y-offset translations Dialog.addCheckbox("Flip Channel Horizontally?", flipH); //Dialog input for horizontal flip Dialog.addCheckbox("Flip Channel Vertically?", flipV); //Dialog input for vertical flip Dialog.addSlider("Rotate Channel (degrees)", -180, 180, testRoffset); //Dialog input for image rotations Dialog.show(); workingCh = Dialog.getNumber(); //Variable for working channel selection (Number) testXoffset = Dialog.getNumber(); //Variable for x-offset translation value (Number) testYoffset = Dialog.getNumber(); //Variable for y-offset translation value (Number) flipH = Dialog.getCheckbox(); //Variable for Horizontal flip (Boolean) flipV = Dialog.getCheckbox(); //Variable for Vertical flip (Boolean) testRoffset = Dialog.getNumber(); //Variable for image rotation (Number) run("Split Channels"); //Splits channels selectWindow("C1-"+testtitle); //Selects Channel 1 rename("red"); //Re-names channel to 'red' selectWindow("C2-"+testtitle); //Selects Channel 2 rename("green"); //Re-names channel to 'green' if (workingCh == 1) {selectWindow("red");} //Sets red working channel if (workingCh == 2) {selectWindow("green");} //Sets green working channel if (flipH == 1) {run("Flip Horizontally", "stack");} //Flips horizontally if selected if (flipV == 1) {run("Flip Vertically", "stack");} //Flips vertical if selected if (testRoffset != 0) {run("Rotate... ", "angle="+testRoffset+" grid=1 interpolation=Bilinear");} //Runs rotation if selected run("Translate...", "x="+testXoffset+" y="+testYoffset+" interpolation=None stack"); //Runs XY translation if (workingCh == 1) {imageCalculator("Difference create", "red","green");} //Creates a difference image if required based on channel selection if (workingCh == 2) {imageCalculator("Difference create", "green","red");} //Creates a difference image if required based on channel selection if (dye=="CFP-YFP"){ //Loop for channel merging run("Merge Channels...", "c5=red c7=green create ignore"); //CFP-YFP merge output } else {run("Merge Channels...", "c1=red c2=green create ignore");}; //GFP-RFP merge output Dialog.create("Exit Parameter Mode"); //Creates Dialog for loop exit Dialog.addCheckbox("I'm happy with these settings and ready to move to entire data-set", 0); //Dialog input for loop exit Dialog.show(); endManual = Dialog.getCheckbox(); //Variable for loop exit (Boolean) if (endManual == 1){ //Case for loop exit Dialog.create("Manipulation Settings"); //Creates dialog box for final parameters Dialog.addMessage("The following settings were chosen:"); //Dialog message description Dialog.addMessage("Channel for Manipulation: "+workingCh); //Dialog for working channel Dialog.addMessage("X Offset: "+testXoffset); //Dialog for X-offset Dialog.addMessage("Y Offset: "+testYoffset); //Dialog for Y-offset if (flipH== 0){Dialog.addMessage("Channel Flipped Horizontally: No");} //Dialog for Horizontal flip if (flipH== 1){Dialog.addMessage("Channel Flipped Horizontally: Yes");} //Dialog for Horizontal flip if (flipV== 0){Dialog.addMessage("Channel Flipped Vertically: No");} //Dialog for Vertical flip if (flipV== 1){Dialog.addMessage("Channel Flipped Vertically: Yes");} //Dialog for Vertical flip Dialog.addMessage("Image Rotation Angle: "+testRoffset); //Dialog for rotation Dialog.show(); print(""); print("***** Determined Offsets *****"); //Reports to log Determined offsets print("Working channel for Manipulations: "+workingCh); //Reports to log the chosen working channel print("X Offset Chosen: "+testXoffset); //Reports to log X-offset translation value print("Y Offset Chosen: "+testYoffset); //Reports to log Y-offset translation value if (flipH== 0){print("Channel Flipped Horizontally: No");} //Reports to log Horizontal flip status if (flipH== 1){print("Channel Flipped Horizontally: Yes");} //Reports to log Horizontal flip status if (flipV== 0){print("Channel Flipped Vertically: No");} //Reports to log Vertical flip status if (flipV== 1){print("Channel Flipped Vertically: Yes");} //Reports to log Vertical flip status print("Image Rotation Angle: "+testRoffset); //Reports to log Rotation value while (nImages>0){close();} //Closes all open windows }} start = getTime(); //Start of internal batch timer if (batch==1){setBatchMode(true);} //Turns on batch mode if selected for (i=0; i0){close();} //Closes all open windows }} print(""); print("Batch Completed"); //Reports to log batch completion print("Total Runtime was: "+((getTime()-start)/1000)+" seconds"); //Reports to log total batch runtime selectWindow("Log"); saveAs("Text", resultsDir+"Log.txt"); //Saves log file to output directory title = "Batch Completed"; //Batch completion message box. msg = "Image correction completed"; waitForUser(title, msg);