Snippets

Dave Mason Measurement of Ant Heads from AntWeb using a Fiji script

Created by Dave Mason

File AntHeads.ijm Added

  • Ignore whitespace
  • Hide word diff
+close("*");
+open("http://www.antweb.org/images/casent0249453/casent0249453_h_1_high.jpg");
+//open("http://www.antweb.org/images/casent0902634/casent0902634_h_1_high.jpg");
+
+title=getTitle();
+getDimensions(width, height, channels, slices, frames);
+
+//-- duplicate the bottom right of the image to try and find the scale bar
+makeRectangle(width-floor(width*0.4), height-150, floor(width*0.4), 150);
+run("Duplicate...", "title=scale");
+run("8-bit");
+run("Median...", "radius=1");
+//setThreshold(0, 30);
+setAutoThreshold("Default light");
+
+setOption("BlackBackground", true);
+run("Convert to Mask");
+run("Analyze Particles...", "size=100-Infinity show=Masks clear add in_situ");
+
+//-- for each object check concavity or solidity
+numObj=roiManager("count");
+//-- record the squareness and the width
+squareness=newArray(numObj);
+sqW=newArray(numObj);
+for (i = 0; i < numObj; i++) {
+	roiManager("select", i);
+	//--calculate "squareness"
+	List.setMeasurements;
+	sqW[i]=List.getValue("Width");
+	//-- don't really need this other than to calculate the bounding box so replace every loop
+	sqH=List.getValue("Height");
+	squareness[i]=List.getValue("Area")/(sqW[i]*sqH);
+}
+//Array.print(squareness);
+//-- Rank the array from highest squareness to lowest
+squarenessRank=Array.reverse(Array.rankPositions(squareness));
+
+//-- may want to check that the squareness is above, eg. 0.96
+
+//-- now pull the width to use for calibration
+calibVal=sqW[squarenessRank[0]];
+//Array.print(squarenessRank);
+close("scale");
+selectWindow(title);
+run("Select None");
+
+//-- Set the scale on the origial 
+run( "Set Scale...", "distance=" + calibVal + " known=1 unit=mm" );
+
+//-- add the scale bar as an overlay
+roiManager("select", squarenessRank[0]);
+getSelectionBounds(sbX, sbY, sbW, sbH);
+makeRectangle(sbX+width-floor(width*0.4), sbY+height-150, sbW, sbH);
+Overlay.addSelection("magenta", 3);
+run("Select None");
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.