/* Martin Fraunholz, Franziska Ruf & Christian Wegener 2016 */ var side = 15; // side length of hatch ROIs in pixels var verbose = 0; // set to 1 for more verbose output to Log-Window; 0 no such messages var semicolon=1; // set to 1 for semicolon delimited output to Log-Window; 0 no such messages var eclosion_plot = 0; // generate a plot of total eclosions per time frame; set to 0 to inactivate var hatch_sensitivity= 10; // alter to adapt sensitivity of detection & to reflect the illumination conditions of monitor // small values (e.g. 1) highly sensitive; large values (100) unsensitive!! //do not alter code below this point, unless you know what you are doing macro "Info Action Tool - C000D6dC000D7dC000C111C222D43C222D53D57D5aD86D92D93D9aDa9C222C333D76C333D5dC333C444D95C444C555D52D6aC555D96C555C666D42DaaC666C777D59D82C777D58D66D67D8aD94D99C777C888D48D49D6bD6cD6eD7aD7bD81D8bDa3Da4C888D77D7cD7eDa5C888D44D47D54D71C999D8dC999D61C999CaaaD56D72D85D9bCbbbD4aD51D5bD5cD5eD91Da2Da8CbbbD98CcccD62CdddD87CdddD33CeeeD63D75D83D8cD8eDa6Db9CeeeD4dCeeeD32D34D41D46D64D69D97DabDbaCfffD4bD4cD4eD65D68D84D89Da1Db8CfffD00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D11D12D13D14D15D16D17D18D19D1aD1bD1cD1dD1eD1fD20D21D22D23D24D25D26D27D28D29D2aD2bD2cD2dD2eD2fD30D31D35D36D37D38D39D3aD3bD3cD3dD3eD3fD40D45D4fD50D55D5fD60D6fD70D73D74D78D79D7fD80D88D8fD90D9cD9dD9eD9fDa0Da7DacDadDaeDafDb0Db1Db2Db3Db4Db5Db6Db7DbbDbcDbdDbeDbfDc0Dc1Dc2Dc3Dc4Dc5Dc6Dc7Dc8Dc9DcaDcbDccDcdDceDcfDd0Dd1Dd2Dd3Dd4Dd5Dd6Dd7Dd8Dd9DdaDdbDdcDddDdeDdfDe0De1De2De3De4De5De6De7De8De9DeaDebDecDedDeeDefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDff"{ print("WEclMon1-ImageJ Toolset for Eclosion detection\n\n"); print("The WEclMon is an open monitoring system that allows\nexperiments under semi-natural conditions.\n\nWEclMon is designed as a camera-based system which is not\n subjected to mechanical agitation. The recorded PNG images\n are opened as image stack in FiJi.\n The Initialize Tool then converts the stack to 8-bit gray scale\n and enhances the contrast.\n\n To minimize effects of different light conditions, \n background is rolling-ball subtracted. \n Images are then converted into binary images and puparia are \n identified by setting a threshold for intensity and subsequent \n particle analysis. Square regions of interest (ROIs) are defined \n around the center of each particle and added to the ROI manager. \n These steps are automatically executed by the macro after \n threshold setting, yet ROIs should be visually checked for \n alignment and -if occuring- false-positive ROIs can be removed \n manually. \n The 'MultiMeasure' tool then monitors the intensity of each ROI \n over the time course of the recorded images. \n The eclosion detection tool then analyses the changes in intensity \n standard deviations between consecutive time points for each ROI. \n If a freely definable threshold of intensity change between two \n images is crossed, this is registered as an eclosion event and \n the according ROI is highlighted."); } // macro "Initialize Action Tool - C854D23CdccD07D18D22D2cD3aD3cD4bD4cD5bD5fD6dD82D94Da4Da5Dd9CccbD0fD1fDbfDcfDdfDeeCddcD06D32D3dD40D4dD50D52D60D61D62C964D13CeccD12CdccD05D08D09D0bD0cD0dD19D1bD1cD1eD29D2aD2bD2eD3bD3fD4fD70D71D7eD80D81D83D8eD8fD90D91D92D93D95D9eD9fDa0Da1Da2Da3DaeDb0Db1Db2Db3Db4Db5Db6DbeDc3Dc4Dc5Dc6Dc7Dd2Dd3Dd4Dd5Dd7Dd8De0De1De2De3De4De5De6De7De8De9Df2Df3Df4Df5Df6Df9DfaCdddD10D42Cc62D37CdccD2dD3eD4eD5cD5dD5eD63D6cD6eD6fD72D73D7dD7fDc0Dc1Dc2Dd0Dd1DeaCdccD0aD0eD17D1aD2fD4aDafDb7Dd6Df0Df1Df7Df8CedcD02D41D51Cc87D96CeddD21Cc51D44CdccD1dD84D8dCdcbD28D39D7cDa6Cc75DbaCeddD00D01D11D20D30D31Ce82D69CcbbD04DfbDfcCa41D8bCb76D27D38Db8Cc73D99Cca9D6bCc62D48D59D9bCcccDedCf94D35D47D68Cf83D45CdbaD03DddC953DccCa76D15Cd71D7aCb99D16Cc52D34D65Cb87D64D8cDdcCd84D98CcbbDffCb53D24Cb86DcdCd63D9aCcaaD9dCc63D26Cf94D46Cf93D56D58CdbbD74Dc8DceDdeC953DbcC965D33Ce61D76Cb97D5aDadDbdCb52D6aD86D97Cd85Da9Ce83D78Ca52D54D9cDa8Cc74D25DaaCca9DdaCe84D36Cf93D67C953DcbCa75DdbCe72D55Cca9D85Ce83D66CcbbDefDfdDfeCa63D75Cb87D43Cd73D8aCcbaD53Cb63Db9Cf94D77Cf84D57Ca52DacCb86D49Dc9Cb63DabC854D14Ca64DcaCca9DebCe84D88C963DbbCb75Da7Ce72D87Ce83D79Ce73D89CcbaDecCb63D7b"{ roiManager("Reset"); print("#WEclMon1-ImageJ Toolset for Eclosionm detection"); run("Set Measurements...", " mean standard display redirect=None decimal=3"); run("Overlay Options...", "stroke=magenta width=0 fill=none"); //get directory, filename, and bitDepth if (lengthOf(getInfo("image.filename"))>0){ origfile=getInfo("image.filename"); }else{ origfile=getTitle; } dir=getDirectory("image"); if ((lengthOf(dir))>0){ print ("#Working Directory: "+dir); }else{ //print("Setting new working directory"); dir=getDirectory("Choose a working directory"); print ("#Set working directory to "+dir); } //save some variable in the imagej properties //may be replace by variables when in toolset call("ij.Prefs.set", "eclosion.filename", origfile ); call("ij.Prefs.set", "eclosion.dirname", dir ); //do some image polishing and change type to 8 bit greyscale title=getTitle(); oid=getImageID(); run("Auto Crop"); run("8-bit"); //run("Stack Deflicker", "frame=0"); run("Enhance Contrast...", "saturated=10 normalize process_all"); run("Subtract Background...", "rolling=4 light stack"); run("Duplicate...", "title="+title+"thresh"); //ADJUST THRESHOLD thresh=getImageID(); run("Threshold..."); waitForUser("THRESHOLD","ROI identification:\nAdjust the threshold, CLICK APPLY,\nand continue by clicking OK."); //test if user really made a binary image //if not, do so with the current threshold settings if (! is("binary") ) { //print("You need a binary image for this macro! Converting ...."); run("Convert to Mask"); } //identify particles (=pupae) by image contrast base on threshold //and add to ROI manager run("Analyze Particles...", "size=10-Infinity circularity=0.00-1.00 show=Nothing display clear summarize add"); roiManager("Show All with labels"); roiManager("Show All"); roiManager("Save", dir+"\\"+origfile+"-roi.zip"); n = roiManager("count"); if (n==0){ exit("Error: Results table is empty. No ROIs identified."); } // FOR EACH ROI, MEASURE MEAN INTENSITY for (i=0; i 0 &isOpen("Results")) { timeline=newArray(nResults); avgs=newArray(a); //for each roi traverse results table for (roi=1;roi<=a;roi++){ var done=false; //for each result for (row=0; row hatch_sensitivity ){ hatches++; if (verbose) { // print ("timepoint;"+row+"; hatch at ROI:"+roi+"; hatchsum:"+hatches) ; //}else{ print ("# Hatch in ROI: "+roi+ "; Timepoint: "+row+"; Total hatches: "+hatches) ; } timeline[row]+=1; selectImage(im); roiManager('select', (roi-1)); run("Add Selection..."); //here we stop the analysis done=true; } } } // end for each results row } // end for reach roi } else { //If no results table exists, something must be wrong! exit ("No result table"); } //GENERATE SOME OUTPUT print ("# Total number of hatches detected: "+ hatches); //a lot of hatches at Time 0 indicate that these positions were probably "bright" to begin with //and thus not occupied at the beginning of the measurement if (semicolon){ ts=0; //hatchsum //print("# frame;hatches[this_frame];hatchsum"); print("# time frame;hatches detected"); hatchsum=newArray(nResults); xcoord=newArray(nResults); for (i=0; i