/** * Measure skeleton length * Measure the length of a skeleton using the algorithm from * "Robust Quantification of In Vitro Angiogenesis Through Image Analysis" * published in IEEE Transactions on Medical Imaging Vol24, No.4, April 2005 * as described in the ImageJ mailing list by Michael Miller. The aspect ratio of * a pixel is considered to be one. Lengths are calculated from the middle of one * pixel to the middle of another pixel. * * (c) 2010, INSERM * written by Volker Baecker at Montpellier RIO Imaging (www.mri.cnrs.fr) */ var helpURL = "http://dev.mri.cnrs.fr/projects/imagej-macros/wiki/Measure_Skeleton_Length"; macro "Measure Skeleton Length [f1]" { print (measureSkeletonLength()); } macro "Measure Skeleton Length (f1) Action Tool- CfffCeeeCdddCcccCbbbCaaaC999C888C777C666C555C444C333C222C111C000D27D36D3dD3eD45D4bD4cD54D5aD61D62D63D64D6aD75D76D77D78D79D7aD7bD7cD86D8dD97D9dDa7DadDb8Dc8Dd9" { print (measureSkeletonLength()); } macro "Measure Skeleton Length (f1) Action Tool Options" { Dialog.create("Measure Skeleton Length"); Dialog.addMessage("Measure the length of a skeleton using the algorithm from\n \"Robust Quantification of In Vitro Angiogenesis Through Image Analysis\"\npublished in IEEE Transactions on Medical Imaging Vol24, No.4, April 2005\nas described in the ImageJ mailing list by Michael Miller. The aspect ratio of\na pixel is considered to be one. Lengths are calculated from the middle of one\npixel to the middle of another pixel.\n(c) 2010, INSERM\nwritten by Volker Baecker at Montpellier RIO Imaging (www.mri.cnrs.fr)"); Dialog.addHelp(helpURL); Dialog.show(); } function measureSkeletonLength() { var sqrtOfTwo = sqrt(2); var x,y, result; result = 0; var value,ul,um,ur,l,r,ll,lm,lr; var straightCounter, diagonalCounter; straightCounter = 0; diagonalCounter = 0; for (x=0; x0) { ul = getPixel(x-1, y-1); um = getPixel(x, y-1); ur = getPixel(x+1, y-1); l = getPixel(x-1, y); r = getPixel(x+1, y); ll = getPixel(x-1, y+1); lm = getPixel(x, y+1); lr = getPixel(x+1, y+1); if (um>0) straightCounter++; if (l>0) straightCounter++; if (r>0) straightCounter++; if (lm>0) straightCounter++; if (ul>0 && l==0 && um==0) diagonalCounter++; if (ur>0 && r==0 && um==0) diagonalCounter++; if (ll>0 && l==0 && lm==0) diagonalCounter++; if (lr>0 && r==0 && lm==0) diagonalCounter++; } } } straightCounter = straightCounter / 2.0; diagonalCounter = diagonalCounter / 2.0; result = straightCounter + (diagonalCounter * sqrtOfTwo); getPixelSize(unit, pw, ph, pd); result = result * pw; return result; }