Snippets
Dave Mason Image Feature Measurement from http://forum.imagej.net/t/image-features-measurement-in-batch-mode-not-working/11284
Created by
Dave Mason
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | //@ File (label = "Input directory", style = "directory") input //@ File (label = "Output directory", style = "directory") output //@ String (label = "File suffix", value = ".tif") suffix //-- Call the initial function to get a list of files processFolder(input); print("Done"); //-- FUNCTIONS --- function processFolder(input) { list = getFileList(input); list = Array.sort(list); for (i = 0; i < list.length; i++) { if(endsWith(list[i], suffix)) //-- Call the file processing function processFile(input, output, list[i]); } } function processFile(input, output, file) { print("Processing: " + input + File.separator + file); //-- Open the file open(input+File.separator+file); title=getTitle(); //-- Your code here ------------------- //setAutoThreshold("Default"); //setThreshold(245, 255); // Shape Analysis Macro for ImageJ // Copyright of Liu, E.J., Cashman, K.V., & Rust, A.C., (2015). Optimising Shape Analysis to quantify volcanic ash morphology. GeoResJ // INPUTS: this macro requires a binary image. // OUTPUTS: Particle area, Particle perimeter, Convex hull (CH) area, Convex hull (CH) perimeter, Solidity, Convexity, // Concavity Index, Form Factor, Major axis (of best fit ellipse), Minor axis (of best fit ellipse), Axial ratio (minor/major axis), // Bounding box width (along x axis), Bounding box height (along y axis), Feret diameter, Minimum Feret diameter. All mathematical // definitions given in Table 2 of Liu et al., (2015). // Default variables: particle size range = 750-Infinity pixels per particle; 'exclude' edge-touching particles; // 'include' holes in the particle area. { run("Set Measurements...", "area centroid perimeter bounding fit shape feret's redirect=None decimal=3"); run("Analyze Particles...", "size=750-Infinity pixel circularity=0.00-1.00 show=Outlines exclude clear include record stack"); n = nResults; area1 = newArray(n); length1 = newArray(n); area2 = newArray(n); length2 = newArray(n); xstart = newArray(n); ystart = newArray(n); ff1 = newArray(n); AR1 = newArray(n); round1 = newArray(n); BBX1 = newArray(n); BBY1 = newArray(n); major1 = newArray(n); minor1 = newArray(n); feret1 = newArray(n); minferet1 = newArray(n); solidity1 = newArray(n); for (i=0; i<n; i++) { area1[i] = getResult("Area", i); length1[i] = getResult("Perim.", i); xstart[i] = getResult("XStart", i); ystart[i] = getResult("YStart", i); ff1[i] = getResult("Circ.", i); AR1[i] = getResult("Aspect", i); round1[i] = getResult("Round", i); BBX1[i] = getResult("Width", i); BBY1[i] = getResult("Height", i); minor1[i] = getResult("Minor", i); major1[i] = getResult("Major", i); feret1[i] = getResult("Feret", i); minferet1[i] = getResult("MinFeret", i); } run("Clear Results"); for (i=0; i<n; i++) { doWand(xstart[i], ystart[i]); run("Convex Hull"); run("Measure"); area2[i] = getResult("Area", i); length2[i] = getResult("Perim.", i); } run("Clear Results"); run("Select None"); for (i=0; i<n; i++) { setResult("Area", i, area1[i]); setResult("Perim.", i, length1[i]); setResult("CH Area", i, area2[i]); setResult("CH Perim.", i, length2[i]); setResult("Solidity", i, area1[i]/area2[i]); setResult("Convexity", i, length2[i]/length1[i]); setResult("Concavity Index", i, sqrt((pow(1-(area1[i]/area2[i]),2)+(pow(1-(length2[i]/length1[i]),2))))); setResult("FormFactor", i, ff1[i]); setResult("Major axis", i, major1[i]); setResult("Minor axis", i, minor1[i]); setResult("Axial ratio", i, minor1[i]/major1[i]); setResult("BX width", i, BBX1[i]); setResult("BY height", i, BBY1[i]); setResult("Feret d", i, feret1[i]); setResult("MinFeret d", i, minferet1[i]); } updateResults(); } //-- Save out the results table here: selectWindow("Results"); saveAs("Results", output+File.separator+replace(file,suffix,"_results.csv")); //run("Read and Write Excel"); //-- Save out your drawing here selectWindow("Drawing of "+title); saveAs("TIFF",output+File.separator+replace(file,suffix,"_drawing.tif")); //-- Close everything before the next image is opened close("*"); } |
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.