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 |
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 |
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 > > > -----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 |
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 |
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 > > 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), > > 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 > >> > > > >> > >> -----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 |
Yes! Beautiful! Thanks Jerome! :-)
On May 9, 2014, at 9:00 AM, Jerome Mutterer <[hidden email]> wrote: > 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Jerome Mutterer-3
Jerome,
I incorporated your algorithm into a macro for a researcher in Germany, and it works beautifully! Thank you. I need one more element, which is the ability to have the grid randomly set rather than always starting in the same place. I know there is the random function, but I am having difficulty applying it to this situation. I want the starting point of the grid to be random, but I do not want the ditance between lines to vary, and the starting point must vary with the image’s calibration, so that the range of starting points is within one step value, i.e., step = distance between lines. Do you have any insights? Here is my code so far: // ********** begin macro ********** drawLines(30, 100); function drawLines(angle, step) { max = maxOf(getWidth,getHeight); a = PI*angle/180; 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.show; } // ********** end macro ********** Thank you so much, Chris Coulon gaiag.net On May 9, 2014, at 9:00 AM, Jerome Mutterer <[hidden email]> wrote: > 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Chris,
You could offset the grid center (xc,yc) which is currently set at the image center. If the random offset range is to be at most 'step', then you could modify the code as follows. Image calibration plays no role here ('step' is in pixels), but you could choose a value of 'step' that corresponds to a given length in calibrated units (see the toUnscaled(length) macro function). Sincerely, Jerome. // ********** begin macro ********** run ("Blobs (25K)"); step = 20; xc=getWidth/2 + 2*step*(random-0.5); yc=getHeight/2 + 2*step*(random-0.5); Overlay.remove; drawLines(30, step); drawLines(30+90, step); function drawLines(angle, step) { max = maxOf(getWidth,getHeight); a = PI*angle/180; 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.show; } // ********** end macro ********** On 5 June 2014 18:10, christopher of the family hunt coulon < [hidden email]> wrote: > Jerome, > > I incorporated your algorithm into a macro for a researcher in Germany, > and it works beautifully! Thank you. I need one more element, which is > the ability to have the grid randomly set rather than always starting in > the same place. I know there is the random function, but I am having > difficulty applying it to this situation. I want the starting point of the > grid to be random, but I do not want the ditance between lines to vary, and > the starting point must vary with the image's calibration, so that the > range of starting points is within one step value, i.e., step = distance > between lines. Do you have any insights? > > Here is my code so far: > > // ********** begin macro ********** > > drawLines(30, 100); > > function drawLines(angle, step) { > max = maxOf(getWidth,getHeight); > a = PI*angle/180; > > 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.show; > } > > // ********** end macro ********** > > Thank you so much, > > Chris Coulon > gaiag.net > > On May 9, 2014, at 9:00 AM, Jerome Mutterer < > [hidden email]> wrote: > > > 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 > > -- > 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 |
Thank you Jerome,
I was just about to get back to you with my solution, which I just came up with :-) drawLines(30, 50); function drawLines(angle, step) { max = maxOf(getWidth,getHeight); a = PI*angle/180; xc=getWidth/2; yc=getHeight/2; Overlay.remove; ran = random * step; for (i=-1*floor(max/step);i<max/step;i++) { x = ran+xc-max*cos(a)+i*step*sin(a); y = ran+yc+max*sin(a)+i*step*cos(a); Overlay.moveTo(x, y); x = ran+xc+max*cos(a)+i*step*sin(a); y = ran+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.show; } On Jun 5, 2014, at 10:09 AM, Jerome Mutterer <[hidden email]> wrote: > Dear Chris, > You could offset the grid center (xc,yc) which is currently set at the > image center. > If the random offset range is to be at most 'step', then you could modify > the code as follows. > Image calibration plays no role here ('step' is in pixels), but you could > choose a value of 'step' that corresponds > to a given length in calibrated units (see the toUnscaled(length) macro > function). > Sincerely, > Jerome. > > > // ********** begin macro ********** > run ("Blobs (25K)"); > step = 20; > xc=getWidth/2 + 2*step*(random-0.5); > yc=getHeight/2 + 2*step*(random-0.5); > Overlay.remove; > > drawLines(30, step); > drawLines(30+90, step); > > function drawLines(angle, step) { > max = maxOf(getWidth,getHeight); > a = PI*angle/180; > 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.show; > } > // ********** end macro ********** > > > On 5 June 2014 18:10, christopher of the family hunt coulon < > [hidden email]> wrote: > >> Jerome, >> >> I incorporated your algorithm into a macro for a researcher in Germany, >> and it works beautifully! Thank you. I need one more element, which is >> the ability to have the grid randomly set rather than always starting in >> the same place. I know there is the random function, but I am having >> difficulty applying it to this situation. I want the starting point of the >> grid to be random, but I do not want the ditance between lines to vary, and >> the starting point must vary with the image's calibration, so that the >> range of starting points is within one step value, i.e., step = distance >> between lines. Do you have any insights? >> >> Here is my code so far: >> >> // ********** begin macro ********** >> >> drawLines(30, 100); >> >> function drawLines(angle, step) { >> max = maxOf(getWidth,getHeight); >> a = PI*angle/180; >> >> 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.show; >> } >> >> // ********** end macro ********** >> >> Thank you so much, >> >> Chris Coulon >> gaiag.net >> >> On May 9, 2014, at 9:00 AM, Jerome Mutterer < >> [hidden email]> wrote: >> >>> 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 >> >> -- >> 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 |
Free forum by Nabble | Edit this page |