//Works with ImageJ 1.52n and Fiji //Bio-formats release version: 5.2.1 //Developed using Nikon nd2 files //Only works for 2 or 3 channel pictures currently //Pictures don't need to be split //Make sure there are no other images open. //You might as well make the Bio-formats "windowless" since it will pop up every time that you open a picture. //This is version 2.0 of this macro. Updated 04/22/2019 waitForUser("Make sure that you do not have any images open that need to be saved.\nThe macro will close them all if not."); //This allows this macro to be utilized for other measurements. //There is a "setOption" parameter down in the ROI section that forces the "display label" so that all measurements are labeled with the picture name. run("Set Measurements..."); //this is the directory with your pictures. //make sure there are no subfolders! dir1 = getDirectory("Choose your folder with your original pictures"); list = getFileList(dir1); //for the batch to work setBatchMode(true); run("Close All"); open(dir1+list[0]); if(nImages==1){ Imagessplit=0; //0 = no getDimensions(w, h, channels, slices, frames); Stack.getPosition(channel, slice, frame); //print(" Channels: "+channels); } else if(nImages>1){channels=nImages; //print(channels); Imagessplit=1; //1 = yes } run("Close All"); setBatchMode(false); Total = channels; if(channels>3){ waitForUser("This macro does not work with images that have less than two or more than three.\nThis image has "+channels+" channels."); } if(channels<2){ waitForUser("This macro does not work with images that have less than two or more than three.\nThis image has "+channels+" channels."); } //dialog boxes -which channels need threshold Dialog.create("Threshold"); Dialog.addMessage("Which channels need to a threshold?"); Dialog.addCheckbox("Channel 1", true); if(Total>=2) { Dialog.addCheckbox("Channel 2", true); } if(Total==3) { Dialog.addCheckbox("Channel 3", false); } Dialog.show(); Ch1 = Dialog.getCheckbox(); Ch2 = Dialog.getCheckbox();; if(Total==3) {Ch3 = Dialog.getCheckbox();;;} else Ch3=0; if(Total==3) totalchan=3; else if(Total>=2) totalchan=2; else totalchan=1; //dialog boxes -what are the threshold values Dialog.create("Threshold Values"); if(Ch1==true) { Dialog.addNumber("Channel 1 Lower Threshold value:", 900); } if(Ch2==true) { Dialog.addNumber("Channel 2 Lower Threshold value:", 900); } if(Ch3==true) { Dialog.addNumber("Channel 3 Lower Threshold value:", 1000); } Dialog.show(); if(Ch1==true) { Lowch1=Dialog.getNumber(); } if(Ch2==true) { Lowch2=Dialog.getNumber();; } if(Ch3==true) { Lowch3=Dialog.getNumber();;; } Dialog.create("Analysis"); Dialog.addMessage("Which channels need to be measured?"); Dialog.addCheckbox("Ch. 1", true); if(Total>=2) { Dialog.addCheckbox("Ch. 2", true); } if(Total==3) { Dialog.addCheckbox("Ch. 3", false); } Dialog.show(); Ch1measure = Dialog.getCheckbox(); Ch2measure = Dialog.getCheckbox();; if(Total==3) {Ch3measure = Dialog.getCheckbox();;;} else Ch3measure=0; //batch opening stuff goes here: list = getFileList(dir1); //for the batch to work for (i=0; i=2) { selectWindow("C2-"+originaltitle); rename(originaltitle+" - C=1"); C1=getTitle(); } if(totalchannels==3) { selectWindow("C3-"+originaltitle); rename(originaltitle+" - C=2"); C2=getTitle(); } selectWindow("C1-"+originaltitle); rename(originaltitle+" - C=0"); C0=getTitle(); } if(Imagessplit==1) { if(totalchan!=totalchannels){ print("Channel numbers are not the same for all the pictures"); waitForUser("Please make sure all the images have the same number of channels.\nThe macro is currently set for "+totalchan+" channels.\nThis image has "+totalchannels+" channels."); kill //this isn't a real function. it will just kill the macro or at least through it to the debug screen. } originaltitle=File.name; totalchannels=nImages(); if(totalchannels>=2) { selectWindow(originaltitle+" - C=1"); C1=getTitle(); } if(totalchannels==3) { selectWindow(originaltitle+" - C=2"); C2=getTitle(); } selectWindow(originaltitle+" - C=0"); rename(originaltitle+" - C=0"); C0=getTitle(); } //start of individual picture analysis selectWindow(C0); run("Z Project...", "projection=[Max Intensity]"); C0max=getTitle(); selectWindow(C0); close(); if(totalchannels>=2) { selectWindow(C1); run("Z Project...", "projection=[Max Intensity]"); C1max=getTitle(); selectWindow(C1); close(); } if(totalchannels==3) { selectWindow(C2); run("Z Project...", "projection=[Max Intensity]"); C2max=getTitle(); selectWindow(C2); close(); } //threshold if(Ch3==true) { selectWindow(C2max); setAutoThreshold("Default dark"); // run("Threshold..."); getThreshold(lower, upper); setThreshold(Lowch3, upper); setOption("BlackBackground", true); run("Convert to Mask"); } if(Ch2==true) { selectWindow(C1max); setAutoThreshold("Default dark"); // run("Threshold..."); getThreshold(lower, upper); setThreshold(Lowch2, upper); setOption("BlackBackground", true); run("Convert to Mask"); } if(Ch1==true) { selectWindow(C0max); setAutoThreshold("Default dark"); // run("Threshold..."); getThreshold(lower, upper); setThreshold(Lowch1, upper); setOption("BlackBackground", true); run("Convert to Mask"); } waitForUser("Please find your ROI.\nClick \"OK\" once you have."); n = roiManager("count"); if(n == 0) { waitForUser("No ROI found.\nPlease find your ROI.\nClick \"OK\" once you have."); } setOption("Display label", true); //this is here to make sure that each measurement is labeled with the picture it came from. Comment it out if you don't want it if(Ch1measure==true){ selectWindow(C0max); //run("Set Measurements...", "area integrated display redirect=None decimal=3"); rename(C0); roiManager("Measure"); } if(Ch2measure==true){ selectWindow(C1max); //run("Set Measurements...", "area integrated display redirect=None decimal=3"); rename(C1); roiManager("Measure"); } if(Ch3measure==true){ selectWindow(C2max); rename(C2); //run("Set Measurements...", "area integrated display redirect=None decimal=3"); roiManager("Measure"); } run("Close All"); roiManager("Deselect"); roiManager("Delete"); }//needed for batch