Snippets

Dave Mason Example code to process all ROIs in ROI manager (https://forum.image.sc/t/help-to-update-imagej-code/27566)

Updated by Dave Mason

File ProcessAllROI.ijm Modified

  • Ignore whitespace
  • Hide word diff
 d=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
 setResult("Displacement",i, d);
 updateResults;
-
 	
-}
+}
+run("Select None");
Updated by Dave Mason

File ProcessAllROI.ijm Modified

  • Ignore whitespace
  • Hide word diff
 roiManager("reset");
 
 run("Blobs (25K)");
-makePoint(73, 42, "small yellow hybrid");
+makeLine(74, 59, 161, 89);
 roiManager("Add");
-makePoint(138, 52, "small yellow hybrid");
+makeLine(72, 157, 179, 124);
 roiManager("Add");
-makePoint(100, 74, "small yellow hybrid");
-roiManager("Add");
-makePoint(183, 102, "small yellow hybrid");
+makeLine(141, 215, 208, 213);
 roiManager("Add");
 
 
-//-- get the number of ROIs
+//-- get the number
 nROI = roiManager("count");
-
-//-- Loop through each one
 for (i = 0; i < nROI; i++) {
-
-roiManager("select", i);
+	roiManager("select", i);
 	
 //-- Your code goes here as if you've selected the ROI
 
-//run("Measure"); //-- Not necessary if you use the count variable i to select the results table line
+//run("Measure");
 Roi.getCoordinates(xpoints, ypoints);
 x0=xpoints[0];
 setResult("Xi",i, x0);
 d=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
 setResult("Displacement",i, d);
 updateResults;
-	
-}
 
+	
+}
Updated by Dave Mason

File ProcessAllROI.ijm Modified

  • Ignore whitespace
  • Hide word diff
 roiManager("Add");
 
 
-//-- get the number
-
+//-- get the number of ROIs
 nROI = roiManager("count");
+
+//-- Loop through each one
 for (i = 0; i < nROI; i++) {
-	roiManager("select", i);
+
+roiManager("select", i);
 	
 //-- Your code goes here as if you've selected the ROI
 
-run("Measure");
+//run("Measure"); //-- Not necessary if you use the count variable i to select the results table line
 Roi.getCoordinates(xpoints, ypoints);
 x0=xpoints[0];
-setResult("Xi",nResults-1, x0);
+setResult("Xi",i, x0);
 y0=ypoints[0];
-setResult("Yi",nResults-1, y0);
+setResult("Yi",i, y0);
 x1=xpoints[xpoints.length-1];
-setResult("Xf",nResults-1, x1);
+setResult("Xf",i, x1);
 y1=ypoints[ypoints.length-1];
-setResult("Yf",nResults-1, y1);
+setResult("Yf",i, y1);
 d=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
-setResult("Displacement",nResults-1, d);
+setResult("Displacement",i, d);
 updateResults;
-
 	
 }
 
Created by Dave Mason

File ProcessAllROI.ijm Added

  • Ignore whitespace
  • Hide word diff
+//-- Set up example
+run("Close All");
+roiManager("reset");
+
+run("Blobs (25K)");
+makePoint(73, 42, "small yellow hybrid");
+roiManager("Add");
+makePoint(138, 52, "small yellow hybrid");
+roiManager("Add");
+makePoint(100, 74, "small yellow hybrid");
+roiManager("Add");
+makePoint(183, 102, "small yellow hybrid");
+roiManager("Add");
+
+
+//-- get the number
+
+nROI = roiManager("count");
+for (i = 0; i < nROI; i++) {
+	roiManager("select", i);
+	
+//-- Your code goes here as if you've selected the ROI
+
+run("Measure");
+Roi.getCoordinates(xpoints, ypoints);
+x0=xpoints[0];
+setResult("Xi",nResults-1, x0);
+y0=ypoints[0];
+setResult("Yi",nResults-1, y0);
+x1=xpoints[xpoints.length-1];
+setResult("Xf",nResults-1, x1);
+y1=ypoints[ypoints.length-1];
+setResult("Yf",nResults-1, y1);
+d=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
+setResult("Displacement",nResults-1, d);
+updateResults;
+
+	
+}
+
HTTPS SSH

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