Macro to go to a specific pixel

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

Macro to go to a specific pixel

Kurt Fisher
Does anyone have a macro that will:

1) Get user input for a specific pixel coordinate in the image.
2) Go to that pixel.
3) Zoom to an area 50 pixels square around that point.

I have a large number coordinates that I would like to go through in an image and make measurements.

Regards, Kurt

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro to go to a specific pixel

Herbie-2
Good day Kurt,

you may draw a selection centered on the desired coordinates by calling

        makeRectangle( x-25, y-25, 50, 50 );
               
and then call

        run("To Selection");

Of course you must first present a dialog for the user data (coordinates
x, y), i.e. something like

        Dialog.create("Title")
                Dialog.addNumber("x-coord", getWidth/2, 0, 3, "pixel");
                Dialog.addNumber("y-coord", getHeight/2, 0, 3, "pixel");
        Dialog.show()
        x = Dialog.getNumber();
        y = Dialog.getNumber();

The drawback is that ImageJ adds some space around the selection. i.e.
it doesn't show an area of 50x50 pixels.

You may also have a look at the routine

        run("Set... ", "zoom=400 x=128 y=128");

HTH

Herbie
______________________________________
On 28.12.12 06:37, Kurt Fisher wrote:

> Does anyone have a macro that will:
>
> 1) Get user input for a specific pixel coordinate in the image.
> 2) Go to that pixel.
> 3) Zoom to an area 50 pixels square around that point.
>
> I have a large number coordinates that I would like to go through in an image and make measurements.
>
> Regards, Kurt
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro to go to a specific pixel

Kurt Fisher
In reply to this post by Kurt Fisher
Herb,  Thank you.  Your solution was right on point.

After posting, I was thinking maybe a better approach would be to have a routine that would read a set of x,y coordinates in a text file into the ROI Manager. Then all the user would have to do would be to click on a list of measurement points in the ROI.  I believe example macros exist in the ImageJ website library.  I will followup on that as well as your excellent code.  

Thanks again, Kurt

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro to go to a specific pixel

Herbie-2
Well Kurt,

you know how to motivate... ;-)

Here is a IJ-macro that uses a text-file containing the coordinates
(tab-delimited and one pair per line). The first pair should be x y and
serves as the column header.

Open the text-file by "File>Import>Results" in ImageJ as a result table.

Start the following macro (watch for eMail line breaks!):
-------------------------------------
setOption( "ShowRowNumbers", false );
updateResults;
stop = false;
do {
   waitForUser( "Copy a pair of coordinates from the results table and
click OK." );
   //String.copyResults();
   coord = split( String.paste, "" );
   if ( coord.length > 2 ) {
     stop = true;
   } else {
     makeRectangle( parseInt( coord[0] )-25, parseInt( coord[1] )-25,
50, 50 );
     run( "To Selection" );
   }
} while ( stop == false );
run( "Select None" );
-------------------------------------

While the dialog is shown select the desired pair of coordinates and
copy them. Then click OK in the dialog.

In order to stop the macro either use the Escape-key, or select nothing,
copy (empty) and click OK.

The need to not only select the pair of coordinates but to copy it is
annoying. The call "String.copyResults()" doesn't copy the selection but
the whole table, so it can't be used.

Maybe there are better approaches...

Best

Herbie

_____________________________________
On 29.12.12 01:32, Kurt Fisher wrote:
> Herb,  Thank you.  Your solution was right on point.
>
> After posting, I was thinking maybe a better approach would be to have a routine that would read a set of x,y coordinates in a text file into the ROI Manager. Then all the user would have to do would be to click on a list of measurement points in the ROI.  I believe example macros exist in the ImageJ website library.  I will followup on that as well as your excellent code.
>
> Thanks again, Kurt
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro to go to a specific pixel

Kurt Fisher
In reply to this post by Kurt Fisher
Herbie,  Thanks, I'll work with your enhanced code.  For the group record, here is the "Go To Coordinate" macro that I settled on using your code snippets.  It works without problems under ImageJ on a MacOS.  Under Windows 7 and ImageJ, it occasionally has a runtime error were the view screen flickers.  That resolves by either running the cursor over the view window or by aborting the macro and rerunning it. Happy New Year, Kurt

-----------------
macro "Go to Coord [g]"{
Dialog.create("Go to Coord")
Dialog.addNumber("x-coord", getWidth/2, 0, 5, "pixel");
Dialog.addNumber("y-coord", getHeight/2, 0, 5, "pixel");
Dialog.show()
x = Dialog.getNumber();
y = Dialog.getNumber();
makeRectangle( x-25, y-25, 50, 50 );
run("To Selection");
}
------------------

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