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]

Created by Dave Mason last modified
//-- 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");

//-- 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");

Comments (0)