Snippets

Dave Mason Make a duplicate offset line [http://forum.imagej.net/t/how-to-draw-a-curved-line-in-imagej-and-move-it-for-certain-pixels-can-i-also-make-a-selection-of-the-area-in-between-the-two-lines/11793]

Updated by Dave Mason

File shiftLine.ijm Modified

  • Ignore whitespace
  • Hide word diff
 //-- Draw the new line and show both
 makeSelection("freeline", xpos, ypos_new);
 roiManager("add");
-roiManager("Show All");
+roiManager("Show All");
+
+//-- Extra code to turn this into an area selection
+
+//-- Combine the two lines into a single set of X and Y coordinates
+xpos_area=Array.concat(xpos,Array.reverse(xpos));
+ypos_area=Array.concat(ypos,Array.reverse(ypos_new));
+
+//-- Draw the area shape and add to ROI manager
+makeSelection("freehand", xpos_area, ypos_area);
+roiManager("add");
Created by Dave Mason

File shiftLine.ijm Added

  • Ignore whitespace
  • Hide word diff
+//-- Make a demo image
+roiManager("reset");
+newImage("MoveLine", "8-bit black", 512, 512, 1);
+
+//-- select the tool and wait for the user to draw a line
+setTool("freeline");
+waitForUser("Draw a line");
+roiManager("add");
+
+//-- convert the freehand into discreet points and pull the coordinates
+run("Fit Spline");
+getSelectionCoordinates(xpos,ypos);
+
+//-- Shift the line down by 50 pixels
+ypos_new=newArray(ypos.length);
+for (points=0;points<ypos.length;points++){
+	ypos_new[points]=ypos[points]+50;
+}
+
+//-- Draw the new line and show both
+makeSelection("freeline", xpos, ypos_new);
+roiManager("add");
+roiManager("Show All");
HTTPS SSH

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