/** * MRI Skin Tools * * The Skin Tools allow to analyse masks of skin * tissue that touch the right and left border of the image. * The length of the lower border line is measured. For * each extremum on the lower border line of the mask the * length of a vertical line across the mask is measured. * * The interdigitation index can be measured using a given number of segments. * The thickness is estimated by using random lines across the skin, that are perpendicular * to the skin border. * * written 2011-2012 by Volker Baecker (INSERM) at Montpellier RIO Imaging (www.mri.cnrs.fr) */ var helpURL = "http://dev.mri.cnrs.fr/wiki/imagej-macros/Skin_Tools" var minRadius = 15; var numberOfSegments = 1; var numberOfLines = 10; var randomSet = false; var COLOR1_R = 255; var COLOR1_G = 255; var COLOR1_B = 0; var COLOR2_R = 0; var COLOR2_G = 255; var COLOR2_B = 0; var LINE_WIDTH1 = 4; var LINE_WIDTH2 = 1; macro "Unused Tool - C037" { } macro "MRI Skin Tools Help Action Tool -C000D00D01D02D03D04D0aD0bD0cD0dD0eD0fD10D11D12D13D14D1aD1bD1cD1dD1eD1fD20D21D22D23D24D2aD2bD2cD2dD2eD2fD30D31D32D33D34D3bD3cD3dD3eD3fD40D41D42D43D4cD4dD4eD4fD50D51D52D5dD5eD5fD60D6eD6fD70D7eD7fD80D8dD8eD8fD90D91D9bD9cD9dD9eD9fDa0Da1Da2DaaDabDacDadDaeDafDb0Db1Db2DbaDbbDbcDbdDbeDbfDc0Dc1Dc2Dc3DcaDcbDccDcdDceDcfDd0Dd1Dd2Dd3DdbDdcDddDdeDdfDe0De1De2De3DebDecDedDeeDefDf0DfcDfdDfeDffCfffD05D06D07D08D09D25D26D27D28D29D35D36D37D38D39D3aD44D45D46D47D48D49D4aD4bD53D54D55D56D57D58D59D5aD5bD5cD61D62D63D64D65D66D67D68D69D6aD6bD6cD6dD81D82D83D84D85D86D87D88D89D8aD8bD8cD92D93D94D95D96D97D98D99D9aDa3Da4Da5Da6Da7Da8Da9Dc4Dc5Dc6Dc7Dc8Dc9Dd4Dd5Dd6Dd7Dd8Dd9DdaDe4De5De6De7De8De9DeaDf1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbC0ffD15D16D17D18D19D71D72D73D74D75D76D77D78D79D7aD7bD7cD7dDb3Db4Db5Db6Db7Db8Db9"{ run('URL...', 'url='+helpURL); } macro "Options Action Tool- C000T4b12o" { Dialog.create("MRI Skin Tools Options"); Dialog.addNumber("minimum radius", minRadius); Dialog.show(); minRadius = Dialog.getNumber(); } macro "Measure Skin Properties Action Tool- C000T4b12m" { run("Set Measurements...", " bounding display redirect=None decimal=3"); measureOneImage(); roiManager("Show All"); roiManager("Measure"); } macro "Measure Skin Properties Batch Action Tool- C000T4b12b" { showStatus("measure skin properties..."); run("Clear Results"); setForegroundColor(255, 255, 0); run("Set Measurements...", " bounding display redirect=None decimal=3"); call("fr.cnrs.mri.macro.io.IOSettings.resetFileLists"); call("fr.cnrs.mri.macro.io.IOSettings.show"); waitForUser("Please select the input files using the IO_Settings dialog and press ok"); list = call("fr.cnrs.mri.macro.io.IOSettings.getFileList"); if (list=="none") {IJ.log("No files selected! Macro stopped."); return;} files = split(list, ","); for (i=0; i < files.length; i++) { file = files[i]; open(file); folder = File.getParent(file); roiManager("reset"); measureOneImage(); run("Select None"); roiManager("Measure"); run("RGB Color"); roiManager("draw"); if (!File.exists(folder + "/" + "control/")) File.makeDirectory(folder+ "/" + "control/"); saveAs("jpeg", folder + "/" + "control/" + File.nameWithoutExtension + ".jpg"); close(); showProgress(i/(files.length-1)); } filename = folder+"/Results.csv"; writeResultsTableToFile(filename); roiManager("reset"); } macro "Measure Interdigitation Index Action Tool- C000T4b12i" { prepareImage(); roiManager("Reset"); selectLowerObject(); getSelectionCoordinates(x, y); Array.getStatistics(x, xMin, xMax); Array.getStatistics(y, yMin, yMax); length = (xMax-xMin) / numberOfSegments; lengths = newArray(numberOfSegments); distances = newArray(numberOfSegments); initialLength = length; if (numberOfSegments>1) { for (i=0; i0) { setKeyDown("ctrl"); setKeyDown("alt"); makeRectangle(0, 0, currentStartX, yMax); setKeyDown("none"); } } while (selectionType()>3); run("MRI Roi Converter"); roiManager("Add"); } } else { run("MRI Roi Converter"); roiManager("Add"); } resetThreshold(); roiManager("Select", 0); roiManager("Delete"); run("Clear Results"); roiManager("Measure"); for (i=0; i=0 && x0 < width) { findUpperEdgeIndex(x[index], y[index], x0, 0); numberOfLinesFound++; roiManager("Add"); } numberOfLinesTried++; } run("Clear Results"); roiManager("Measure"); run("Summarize"); } macro "Measure Skin Thickness Action Tool Options" { Dialog.create("Skin Thickness Options"); Dialog.addNumber("number of lines", numberOfLines); Dialog.show(); numberOfLines = Dialog.getNumber(); } macro "Measure Advanced Skin Properties Batch Action Tool- C000T4b12bit" { roiManager("Reset"); colorR = newArray(2); colorG = newArray(2); colorB = newArray(2); colorR[0] = COLOR1_R; colorG[0] = COLOR1_G; colorB[0] = COLOR1_B; colorR[1] = COLOR2_R; colorG[1] = COLOR2_G; colorB[1] = COLOR1_B; showStatus("measure advanced skin properties..."); run("Clear Results"); setForegroundColor(255, 255, 0); run("Set Measurements...", " bounding display redirect=None decimal=3"); call("fr.cnrs.mri.macro.io.IOSettings.resetFileLists"); call("fr.cnrs.mri.macro.io.IOSettings.show"); waitForUser("Please select the input files using the IO_Settings dialog and press ok"); list = call("fr.cnrs.mri.macro.io.IOSettings.getFileList"); if (list=="none") {IJ.log("No files selected! Macro stopped."); return;} files = split(list, ","); if (files.length>0) { file = files[0]; folder = File.getParent(file); filename = folder+"/Advanced-Skin-Results.csv"; if (File.exists(filename)) File.delete(filename); f = File.open(filename); print(f, "File\t" + "segments\t" + "length\t" + "distance\t" + "interdigitation index\t" + "lines\t" + "width\n"); } for (fileIndex=0; fileIndex< files.length; fileIndex++) { setBatchMode(true); file = files[fileIndex]; open(file); prepareImage(); folder = File.getParent(file); roiManager("Reset"); selectLowerObject(); getSelectionCoordinates(x, y); Array.getStatistics(x, xMin, xMax); Array.getStatistics(y, yMin, yMax); length = (xMax-xMin) / numberOfSegments; lengths = newArray(numberOfSegments); distances = newArray(numberOfSegments); initialLength = length; if (numberOfSegments>1) { for (i=0; i0) { setKeyDown("ctrl"); setKeyDown("alt"); makeRectangle(0, 0, currentStartX, yMax); setKeyDown("none"); } } while (selectionType()>3); run("MRI Roi Converter"); roiManager("Add"); } } else { run("MRI Roi Converter"); roiManager("Add"); } resetThreshold(); roiManager("Select", 0); roiManager("Delete"); run("Clear Results"); roiManager("Measure"); for (i=0; i=0 && x0 < width) { widths[numberOfLinesFound] = findUpperEdgeIndex(x[index], y[index], x0, 0); numberOfLinesFound++; roiManager("Add"); } numberOfLinesTried++; } meanLength = 0; meanDistance = 0; meanIIndex = 0; for (i=0; i0) File.close(f); print("\\Update1:finished processing"); setBatchMode("exit and display"); } macro "Measure Advanced Skin Properties Batch Action Tool Options" { Dialog.create("Measure Advanced Skin Properties Batch Options"); Dialog.addNumber("color one red", COLOR1_R); Dialog.addNumber("color one green", COLOR1_G); Dialog.addNumber("color one blue", COLOR1_B); Dialog.addNumber("color two red", COLOR2_R); Dialog.addNumber("color two green", COLOR2_G); Dialog.addNumber("color two blue", COLOR2_B); Dialog.addNumber("line width one", LINE_WIDTH1); Dialog.addNumber("line width two", LINE_WIDTH2); Dialog.show(); COLOR1_R = Dialog.getNumber(); COLOR1_G = Dialog.getNumber(); COLOR1_B = Dialog.getNumber(); COLOR2_R = Dialog.getNumber(); COLOR2_G = Dialog.getNumber(); COLOR2_B = Dialog.getNumber(); LINE_WIDTH1 = Dialog.getNumber(); LINE_WIDTH2 = Dialog.getNumber(); } function measureOneImage() { selectSkinBorder(); run("MRI Extrema", minRadius); call("roi.RoiConverter.addVerticalLinesToRoiManager"); } function writeResultsTableToFile(filename) { if (File.exists(filename)) File.delete(filename); f = File.open(filename); print(f, "File\t" + "x\t" + "y\t" + "angle\t" + "length\n"); for (i=0; i0) run("Restore Selection"); run("MRI Roi Converter"); } function getIndexAt(x, y, value) { start = 0; for (i=0; ivalue)) { start = i; } } if (x[x.length-1]==value) start = x.length-1; xValue = x[start]; yValue = y[start]; index = i; for (i=start+1; i=0; i--) { v = getPixel(rx+0.5,ry+0.5); if (v>0) { i=-1; } else { rx = rx - xInc; ry = ry - yInc; } } xE = rx+0.5; yE = ry+0.5; makeLine(x1, y1,xE, yE); toScaled(x1, y1); toScaled(xE, yE); length = sqrt(((xE-x1) * (xE-x1)) + ((yE-y1)*(yE-y1))); return length; } function selectLowerObject() { run("Select None"); setThreshold(0,224); run("Analyze Particles...", "size=500-Infinity circularity=0.00-1.00 show=Nothing add"); lastIndex = roiManager("count")-1; roiManager("Select", lastIndex-1); roiManager("Delete"); roiManager("Select", lastIndex-1); roiManager("Delete"); if (roiManager("count")>0) run("Restore Selection"); roiManager("Add"); } function prepareImage() { run("8-bit"); run("Grays"); resetThreshold(); setAutoThreshold("Default dark"); run("Convert to Mask"); run("Fill Holes"); }