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?



I would like to draw a curved line in ImageJ, and then duplicate the line and move it downward for certain pixels. My final goal is to make a selection of the area in between the two curved lines.

Right now I can use the freehand lines tool to draw the curved line, and if I press T and then move it manually for certain pixels and press T again, I will have two lines with certain pixels in between. However, it is a bit time-consuming and can be hard to adjust the pixels manually. Is there a way that I can type in the pixel number to move the line? Also, how can I connect the two line to make a selection for the area in between them?

I would really appreciate if someone can offer some solutions / thoughts. Thanks :slight_smile:


If you mean a few pixels by ‘certain pixels’, you could draw a wider line halfway in between the original line and the ‘moved certain pixels down’ line having a width of the delta move. See this question.

Alternatively, you could create an extra image that acts as a mask. Draw the selected line in the mask, move the selection where you want it, go there with a step of 1 in x or in y and repeat until you reach the desired width/location.

Once the area is complete, threshold, take the outline (doWand on the first coordinate) and use the selection as ROI on the original image.


Hi @454Casull,

The way I would approach the first bit (as with most things) is with a bit of macro code.

The idea is this:

  1. Draw a freehand line
  2. run Edit > Selection > Fit Spline (which effectively turns a freehand line into a discreet set of points)
  3. Pull the coordinates of the points with getSelectionCoordinates()
  4. Move the points by however many pixels in whichever axis you want
  5. Redraw the line with makeSelection("freeline",xcoords,ycoords)

Here’s a standalone snippet that should get you going:

It polls for a freeline selection, adds this to the ROI manager then shifts it down by 50 pixels. You can of course pull the ROI straight from the manager and/or use the same template to shift on the x-axis or whatever.


If you want to make an area selection out of this you can just combine the coordinates of the two lines (reversing the second line so you don’t get a zig-zag) and redraw the freehand shape (which automatically closes the loop so you don’t need to include the first point as the last point).


The code to create the area selection is included in the bottom of the code linked above. Hope that helps!


Thank you so much @dnmason ! That is exactly what I want to do :star_struck:!


Thanks for your help @eljonco ! Your method works :smiley: