// This version uses the built-in selection Convex Hull (for Start Mask) and Fit Ellipse (for centering Start) features of ImageJ. // It is based on v7, which uses the ImageJ Fit Spline for the start mask and convex hull for centering. requires("1.43s"); run("Tile"); Dialog.create("Input Filenames"); Dialog.addMessage("Type the names of\nthe start and end\nimages below."); Dialog.addString("Start =:", "?.tif"); Dialog.addString("End =:", "?.tif"); Dialog.show(); startimage = Dialog.getString(); endimage = Dialog.getString();; selectImage(startimage); run("Duplicate...", "title=Start"); selectImage(endimage); run("Duplicate...", "title=End"); //setBackgroundColor(0, 0, 0); setForegroundColor(0, 0, 0); roiManager("Centered", "false"); selectImage("Start"); run("Subtract Background...", "rolling=50"); run("Brightness/Contrast..."); run("Enhance Contrast", "saturated=0.5"); run("8-bit"); run("Make Binary"); //Or, the following may be sufficient for brighter images... // run("Subtract Background...", "rolling=50"); // run("8-bit"); // run("Make Binary"); //The following eliminates far-outliers in the Start image by dilating the central array of //nuclei to a 'singularity', then erasing everything outside the bounds of this cluster. run("Duplicate...", "title=Start_Dilated"); run("Options...", "iterations=10 black count=1"); // Note that originally, we used iterations=10. The lower value here results in exclusion of more distant nuclei. // Indeed, if the 'End' image is such that cells along the periphery have moved considerable distances away // from their nearest neighbor, the iteration value of 15 in the section below could increased empirically. run("Dilate"); run("Fill Holes"); w=getWidth(); h=getHeight(); wandx=w/2; wandy=h/2; //setTool(8); doWand(wandx, wandy); run("Add to Manager "); roiManager("Add"); selectWindow("Start"); roiManager("Select", 0); run("Clear Outside"); // The following finds the minimum bounding circle of the nuclei, adds the region to the // Manager, uses it to find the center of the image, then crops the image so as to // center the nuclei in the frame. run("Convex Hull"); roiManager("Add"); run("Fit Ellipse"); roiManager("Add"); roiManager("Select", 3); smx = 0; smy = 0; getSelectionBounds(x, y, w, h); smx=x+(w/2); smy=y+(h/2); scanvasw=getWidth(); scanvash=getHeight; snw=0; snh=0; if (smx < scanvasw/2) snw = 2*smx; else snw=2*(scanvasw-smx); if (smy < scanvash/2) snh = 2*smy; else snh=2*(scanvash-smy); run("Specify...", "width="+snw+" height="+snh+" x="+smx+" y="+smy+" centered"); run("Crop"); selectImage("End"); run("Subtract Background...", "rolling=50"); run("Brightness/Contrast..."); run("Enhance Contrast", "saturated=0.5"); run("8-bit"); run("Make Binary"); //The following eliminates far-outliers in the End image by dilating the central array of //nuclei to a 'singularity', then erasing everything outside the bounds of this cluster. // Note that if the 'End' image is such that cells along the periphery have moved considerable // distances away from their nearest neighbor, the number of iterations - currently 15 - below // could increased empirically. run("Duplicate...", "title=End_Dilated"); run("Options...", "iterations=15 black count=1"); run("Dilate"); run("Fill Holes"); w=getWidth(); h=getHeight(); wandx=w/2; wandy=h/2; //setTool(8); doWand(wandx, wandy); run("Add to Manager "); roiManager("Add"); selectWindow("End"); roiManager("Select", 4); run("Clear Outside"); //The following centers the End image, 'substracts' the Start image particles, // and counts the remaining particles. run("Fit Ellipse"); roiManager("Add"); emx = 0; emy = 0; roiManager("Select", 6); getSelectionBounds(x, y, w, h); emx=x+(w/2); emy=y+(h/2); ecanvasw=getWidth(); ecanvash=getHeight; enw=0; enh=0; if (emx < ecanvasw/2) enw = 2*emx; else enw=2*(ecanvasw-emx); if (emy < ecanvash/2) enh = 2*emy; else enh=2*(ecanvash-emy); run("Specify...", "width="+enw+" height="+enh+" x="+emx+" y="+emy+" centered"); run("Crop"); run("Duplicate...", "title=End-unmasked"); selectWindow("End"); roiManager("Centered", "true"); roiManager("Select", 2); run("Clear"); run("Select None"); run("Make Binary"); run("Analyze Particles...", "size=1.50-Infinity circularity=0.00-1.00 show=Masks exclude clear summarize"); //Data presentation and window clean-up selectWindow("B&C"); run("Close"); //selectWindow("ROI Manager"); //run("Close"); if (isOpen("Mask of End")==1) { selectWindow("End"); run("Set... ", "zoom=25"); } selectWindow("End"); run("Set... ", "zoom=25"); selectWindow("End-unmasked"); run("Set... ", "zoom=25"); selectWindow("End_Dilated"); run("Close"); selectWindow("Start"); run("Set... ", "zoom=25"); selectWindow("Start_Dilated"); run("Close"); run("Tile"); if (isOpen("Summary")==1) selectWindow("Summary"); else print("Number of migrated cells = 0 for this image pair.");