Login  Register

Re: Rotate grid?

Posted by Jerome Mutterer-3 on May 09, 2014; 4:00pm
URL: http://imagej.273.s1.nabble.com/Rotate-grid-tp5007581p5007665.html

Dear Chris,
You're right, these are good ideas. Here's an updated version, where the
grid is centerd on the image.
The angle can be set in the tool's option dialog, and manually adjusted if
you drag the mouse more than 20 pixels.
Sincerely,
Jerome.

// a tool that overlays a grid on the image with adjustable angle and step.
var step =50;
var angle =45;
macro "Grid Tool - C00cT1f1aG" {
max = maxOf(getWidth,getHeight);
getCursorLoc(x0, y0, z, flags);
while (flags&16!=0) {
getCursorLoc(x, y, z, flags);
distance = sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0));
if (distance>20) { a = atan2(x-x0, y-y0);}
else { a = PI*angle/180;}
showStatus("step:"+step+" px; angle:"+d2s(180*a/PI,2)+" degrees");
xc=getWidth/2;
yc=getHeight/2;
Overlay.remove;
for (i=-1*floor(max/step);i<max/step;i++) {
Overlay.moveTo(xc- max*cos(a)+i*step*sin(a), yc+max*sin(a)+i*step*cos(a));
Overlay.lineTo(xc+ max*cos(a)+i*step*sin(a), yc-max*sin(a)+i*step*cos(a));
Overlay.moveTo(xc- max*sin(a)+i*step*cos(a), yc- max*cos(a)-i*step*sin(a));
Overlay.lineTo(xc+ max*sin(a)+i*step*cos(a), yc+ max*cos(a)-i*step*sin(a));
}
Overlay.show;
wait(50);
}
}

macro "Grid Tool Options" {
Dialog.create("Grid");
Dialog.addNumber("Step (in pixels):", step);
Dialog.addNumber("Angle (in degrees):", angle);
Dialog.show();
step = Dialog.getNumber();
angle = Dialog.getNumber();
}




On 9 May 2014 15:47, christopher of the family hunt coulon <
[hidden email]> wrote:
>
> Thanks Jerome!
>
> Interesting approach.  I like the rotation feature -- I could have used
that in a project last year!  :-)  However, I think for a practical tool
for most purposes, it would be best for the user to enter the angle they
would like for the grid, then the grid would cover the entire image.  In
this instance -- I realize this is only a proof of concept -- the grid's
origin is the clicked point, and it is rotated about the point of origin;
not too useful as a tool for the whole image, but it would work for a
smaller ROI.  Cool idea!  :-)
>
> Chris Coulon
> gaiag.net
>
> On May 9, 2014, at 1:30 AM, Jerome Mutterer <
[hidden email]> wrote:

>
> > Dear Chris,
> >
> > the following macro tool allows you to paint an overlay grid.
> > The angle is adjusted as you're dragging the mouse.
> > The grid step is the tool's option.
> >
> > Jerome
> >
> >
> > // a tool that overlays a grid on the image with adjustable angle and
step.

> > var step =50;
> > macro "Grid Tool - C00cT1f1aG" {
> > max = maxOf(getWidth,getHeight);
> > getCursorLoc(x0, y0, z, flags);
> > while (flags&16!=0) {
> > getCursorLoc(x, y, z, flags);
> > a = atan2(x-x0, y-y0);
> > showStatus("step:"+step+" px; angle:"+d2s(180*a/PI,2)+" degrees");
> > Overlay.remove;
> > for (i=0;i<max/step;i++) {
> > Overlay.moveTo(x0+i*step*sin(a), y0+i*step*cos(a));
> > Overlay.lineTo(x0+ max*cos(a)+i*step*sin(a),
y0-max*sin(a)+i*step*cos(a));
> > Overlay.moveTo(x0+i*step*cos(a), y0-i*step*sin(a));
> > Overlay.lineTo(x0+ max*sin(a)+i*step*cos(a), y0+
max*cos(a)-i*step*sin(a));

> > }
> > Overlay.show;
> > wait(10);
> > }
> > }
> > macro "Grid Tool Options" {
> > step = getNumber("Step (in pixels):", step);
> > }
> >
> >
> >
> >
> >
> >
> > On 6 May 2014 10:05, Straatman, Kees (Dr.) <[hidden email]> wrote:
> >>
> >> Dear Chris,
> >>
> >> Try Image > Selection > Rotate
> >>
> >> Best wishes
> >>
> >> Kees
> >>
> >>
> >> Dr Ir K.R. Straatman
> >> Senior Experimental Officer
> >> Centre for Core Biotechnology Services
> >> University of Leicester
> >>
> >
http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aif
> >>
> >> -----Original Message-----
> >> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
> > christopher of the family hunt coulon
> >> Sent: 05 May 2014 23:09
> >> To: [hidden email]
> >> Subject: Rotate grid?
> >>
> >> Is there a way to rotate a nondestructive grid by an arbitrary angle?
 I
> > couldn't find any way to do this via a web search and would like to
avoid

> > working this out if it has already been done.
> >>
> >> Thanks in advance,
> >>
> >> Chris Coulon
> >> --
> >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >>
> >> --
> >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
> >
> >
> >
> > --
> > Jerome Mutterer
> > CNRS - Institut de biologie moléculaire des plantes
> > 12, rue du Général Zimmer
> > 67084 Strasbourg Cedex
> > T 0367155339
> > www.ibmp.cnrs.fr
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html




--
Jerome Mutterer
CNRS - Institut de biologie moléculaire des plantes
12, rue du Général Zimmer
67084 Strasbourg Cedex
T 0367155339
www.ibmp.cnrs.fr

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html