moving an roi along a line selection

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

moving an roi along a line selection

fabrice senger-2
Dear all,

I know this is trivial, but...could someone give me some directions ?

Thank you,

Fabrice.
Reply | Threaded
Open this post in threaded view
|

Re: moving an roi along a line selection

Rasband, Wayne (NIH/NIMH) [E]
On Nov 10, 2011, at 3:43 AM, fabrice senger wrote:

> Dear all,
>
> I know this is trivial, but...could someone give me some directions ?

It is easy to move an ROI along a line selection if you first use run("Fit Spline","straighten") to convert the line to one that has one pixel coordinate spacing. I have included both macro and JavaScript examples, and a JPEG of the output.

-wayne


 // macro example
  size = 30;
  inc = size/2;
  run("Neuron (1.6M, 5 channels)");
  makeLine(228,246,272,253,304,262,
     332,279,360,304,389,337,
     422,369,464,396,502,410);
  run("Fit Spline", "straighten");
  wait(2000);
  getSelectionCoordinates(x, y);
  for (i=0; i<x.length; i+=inc) {
     makeOval(x[i]-inc, y[i]-inc, size, size);
     run("Add Selection...");
  }

  //JavaScript example
  size = 30;
  inc = size/2;
  imp = IJ.openImage("http://imagej.nih.gov/ij/images/Rat_Hippocampal_Neuron.zip");
  xpoints = [228,272,304,332,360,389,422,464,502];
  ypoints = [246,253,262,279,304,337,369,396,410];
  line = new PolygonRoi["(int[],int[],int,int)"](xpoints,ypoints,9,Roi.POLYLINE);
  imp.setRoi(line);
  IJ.run(imp, "Fit Spline", "straighten");
  p = line.getPolygon();
  overlay = new Overlay();
  for (i=0; i<p.npoints; i+=inc) {
     roi = new OvalRoi(p.xpoints[i]-inc, p.ypoints[i]-inc, size, size);
     imp.setRoi(roi);
     overlay.add(roi);
  }
  imp.setOverlay(overlay);
  imp.show();

[cid:[hidden email]]

RoiAlongLine.jpg (37K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: moving an roi along a line selection

fabrice senger-2
Hello,

This is just great !

Thank you very much,

Fabrice.

2011/11/14 Rasband, Wayne (NIH/NIMH) [E] <[hidden email]>

> On Nov 10, 2011, at 3:43 AM, fabrice senger wrote:
>
> > Dear all,
> >
> > I know this is trivial, but...could someone give me some directions ?
>
> It is easy to move an ROI along a line selection if you first use run("Fit
> Spline","straighten") to convert the line to one that has one pixel
> coordinate spacing. I have included both macro and JavaScript examples, and
> a JPEG of the output.
>
> -wayne
>
>
>  // macro example
>  size = 30;
>  inc = size/2;
>  run("Neuron (1.6M, 5 channels)");
>  makeLine(228,246,272,253,304,262,
>     332,279,360,304,389,337,
>     422,369,464,396,502,410);
>  run("Fit Spline", "straighten");
>  wait(2000);
>  getSelectionCoordinates(x, y);
>  for (i=0; i<x.length; i+=inc) {
>     makeOval(x[i]-inc, y[i]-inc, size, size);
>     run("Add Selection...");
>  }
>
>  //JavaScript example
>  size = 30;
>  inc = size/2;
>  imp = IJ.openImage("
> http://imagej.nih.gov/ij/images/Rat_Hippocampal_Neuron.zip");
>  xpoints = [228,272,304,332,360,389,422,464,502];
>  ypoints = [246,253,262,279,304,337,369,396,410];
>  line = new
> PolygonRoi["(int[],int[],int,int)"](xpoints,ypoints,9,Roi.POLYLINE);
>  imp.setRoi(line);
>  IJ.run(imp, "Fit Spline", "straighten");
>  p = line.getPolygon();
>  overlay = new Overlay();
>  for (i=0; i<p.npoints; i+=inc) {
>     roi = new OvalRoi(p.xpoints[i]-inc, p.ypoints[i]-inc, size, size);
>     imp.setRoi(roi);
>     overlay.add(roi);
>  }
>  imp.setOverlay(overlay);
>  imp.show();
>
> [cid:[hidden email]]
>