/* This is a macro to analyze intensity of GFP and RFP channels
 *  from mRNA injected embryos. Mask is generated using a RFP channel.
 * When you open your images, rename the gfp channel for 1 and the rfp channel for 2.
 * The odd number in the Result window will be intensity of GFP channel.
 * The even number in the Result window will be intensity of RFP channel.
 * The area represents the pixel number in the region of mask. 
 */

//Get number of z-slices//
selectWindow("1.tif");
slices=nSlices;

//Prepare for counting pixels
	run("Set Scale...", "distance=1 known=1 pixel=1 unit=pix");

//Delete all data on Result window//
run("Clear Results");

//Loop to get fluorescence intensity from both GFP and RFP channels//
for(i = 0; i < slices; i++) {
	//Prepare for counting pixels
	run("Set Scale...", "distance=1 known=1 pixel=1 unit=pix");
	//select a single slice from loop//
	currentslice = i + 1;
	selectWindow("1.tif");
	setSlice(currentslice);
	//duplicate only selected slice from sfGFP stackes//
	run("Duplicate...", "title=sfGFP");
	selectWindow("2.tif");
	setSlice(currentslice);
	//duplicate only selected slice from mScarlet stackes twice//
	run("Duplicate...", "title=mScarlet");
	run("Duplicate...", "title=mask");
	//making mask using one of the duplicated mScarlet image//
	selectWindow("mask");
	//auto-threshold using Otsu method//
	setAutoThreshold("Otsu dark");
	//run("Threshold...");
	setOption("BlackBackground", true);
	run("Convert to Mask");
	selectWindow("mask");
	//limit measurement in threshold region and redirect to the sfGFP image then measure//
	run("Set Measurements...", "area mean min limit redirect=sfGFP decimal=4");
	run("Measure");
	selectWindow("mask");
	//limit measurement in threshold region and redirect to the mScarlet image then measure//
	run("Set Measurements...", "area mean min limit redirect=mScarlet decimal=4");
	run("Measure");
	//close three images which have been used for measuring one z-slice//
	selectWindow("sfGFP");
	close(); 
	selectWindow("mScarlet");
	close();
	selectWindow("mask");
	close();
}
