/** * Cochlea Hair Cell Counting * * The tool expects a stack of segmented hair cells (mask) in the cochlea. * The tool creates the z-projection of the stack and waits for the user to select * the cochlea with a line selection tool using a width of the line that covers the * hair cells. The tool will straigthen the image under the line-selection and count * the cells per segment of a given length. * * written 2016 by Volker Baecker (INSERM) at Montpellier RIO Imaging (www.mri.cnrs.fr) * in cooperation with Aurélie Saleur */ var helpURL = "http://dev.mri.cnrs.fr/projects/imagej-macros/wiki/Cochlea_Hair_Cell_Counting"; var _USE_WATERSHED = true; var _CORRECT_AFTER_STRAIGHTEN = false; var _MIN_SIZE = 10; var _MAX_SIZE = 100; var _SEGMENT_LENGTH = 200; function showHelp() { run('URL...', 'url='+helpURL); } macro "count hair cells [f2]" { countHairCells(); } macro "help [f1]" { showHelp(); } macro "draw grid [f3]" { drawGrid(); } macro "manual count [f4]" { reportCount(); } macro "Help (f1) Action Tool - C000T4b12?" { showHelp(); } macro "Count Hair Cells (f2) Action Tool - C000D00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D11D12D13D14D17D18D19D1aD1bD1cD1dD1eD1fD20D21D22D23D24D26D27D28D29D2aD2bD2cD2dD2eD2fD30D31D32D33D36D37D38D39D3aD3bD3cD3dD3eD3fD40D41D45D46D47D48D4eD4fD50D51D55D56D57D5aD5bD5eD5fD60D61D65D66D67D68D69D6aD6bD6eD6fD70D71D75D76D77D78D79D7aD7bD7cD7eD7fD80D81D84D85D86D87D88D89D8aD8bD8cD8eD8fD90D91D95D96D97D98D99D9aD9bD9eD9fDa0Da1Da5Da6Da7Da8Da9DaaDabDaeDafDb0Db1Db6Db7Db8Db9DbaDbeDbfDc0Dc1Dc8DceDcfDd0Dd1Dd2DdeDdfDe0De1De2De3DedDeeDefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDffC000D74Dc2De4DecC000Dc7Dc9C000C111Db5DbbC111D94C111D9cDddC111Dd3C111D6cC111D64C222C333D42C333C444C555Dc6DcaC555D54D5cC555C666Da4DacC666Db2C666De5C666DebC666C777C888C999D52C999CaaaCbbbDa2CbbbDe6DeaCbbbCcccD4cCcccDcdCcccDc3CcccDd4CcccCdddD62DdcCdddDc5DcbCdddDb4DbcCdddCeeeCfffD92CfffDe7De9CfffD72CfffD82CfffDe8CfffD15D16D25D34D35D43D44D49D4aD4bD4dD53D58D59D5dD63D6dD73D7dD83D8dD93D9dDa3DadDb3DbdDc4DccDd5Dd6Dd7Dd8Dd9DdaDdb" { countHairCells(); } macro "Count Hair Cells (f2) Action Tool Options" { Dialog.create("Cochlea Hair Cell Counting"); Dialog.addNumber("min. cell area", _MIN_SIZE); Dialog.addNumber("max. cell area", _MAX_SIZE); Dialog.addNumber("segment length", _SEGMENT_LENGTH); Dialog.addCheckbox("use watershed", _USE_WATERSHED); Dialog.addCheckbox("correct after straighten", _CORRECT_AFTER_STRAIGHTEN); Dialog.addHelp(helpURL); Dialog.show(); _MIN_SIZE = Dialog.getNumber(); _MAX_SIZE = Dialog.getNumber(); _SEGMENT_LENGTH = Dialog.getNumber(); _USE_WATERSHED = Dialog.getCheckbox(); _CORRECT_AFTER_STRAIGHTEN = Dialog.getCheckbox(); } macro "Draw Grid (f3) Action Tool - C0a0L18f8L818f" { drawGrid(); } macro "Manual Count (f4) Action Tool - C000T4b12m" { reportCount(); } function countHairCells() { straightenAndSeparate(); sortMeasurements(); countPerSegment() ; } function drawGrid() { width = getWidth(); height = getHeight(); startX = 0; len = _SEGMENT_LENGTH; while (startX1) run("Z Project...", "projection=[Max Intensity]"); if (selectionType==-1) waitForUser("Please make a selection!"); run("Straighten..."); setAutoThreshold("Default dark"); run("Convert to Mask"); if( _USE_WATERSHED) run("Watershed"); if(_CORRECT_AFTER_STRAIGHTEN) waitForUser("Please correct!"); run("Analyze Particles...", "size="+_MIN_SIZE+"-"+_MAX_SIZE+" show=Nothing display clear add"); } function countPerSegment() { startX = 0; len = _SEGMENT_LENGTH; counter = 0; segment = 1; height = getHeight(); run("Remove Overlay"); title1 = "Count per segment"; title2 = "["+title1+"]"; f = title2; if (isOpen(title1)) print(f, "\\Clear"); else run("Table...", "name="+title2+" width=250 height=600"); print(f, "\\Headings:segment\tcount"); for (i=0; i