Import XY from text file to point selections

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

Import XY from text file to point selections

Kevin Marsh
I have point data that was collected from an external process that has
X and Y coordinates and a unique identifier. I was wondering if there
was an easy way to create point selections (or some other type of
marker) of the data on top of an image.

(I'm new to ImageJ, its been a fascinating learning process so far.)

Thanks,
Kevin
Reply | Threaded
Open this post in threaded view
|

Re: Import XY from text file to point selections

BenTupper
On Jun 1, 2009, at 3:13 PM, Kevin Marsh wrote:

> I have point data that was collected from an external process that has
> X and Y coordinates and a unique identifier. I was wondering if there
> was an easy way to create point selections (or some other type of
> marker) of the data on top of an image.


Hi,

The macro below will read a columnar text file, parse it, and plot the  
contents on an image.  The example text file is pasted below the macro.

// begin macro
file = File.openDialog("Select the text file to read");
allText = File.openAsString(file);
text = split(allText, "\n");
hdr = split(text[0]);

//these are the column indices
iX = 0;
iY = 1;
iLabel = 2;

setForegroundColor(255,255,255);

run("Blobs (25K)");

for (i = 1; i < (text.length); i++){
   line = split(text[i]);
   drawString(line[iLabel], parseInt(line[iX]), parseInt(line[iY]));
}
// end macro

// begin example file
X Y Label
10  20  "Bob"
50  70  "Jeff"
100 100 "Betty"

//end example file

Ben Tupper
Reply | Threaded
Open this post in threaded view
|

Re: Import XY from text file to point selections

Brad Busse
Ben Tupper wrote:

> On Jun 1, 2009, at 3:13 PM, Kevin Marsh wrote:
>
>> I have point data that was collected from an external process that has
>> X and Y coordinates and a unique identifier. I was wondering if there
>> was an easy way to create point selections (or some other type of
>> marker) of the data on top of an image.
>
>
> Hi,
>
> The macro below will read a columnar text file, parse it, and plot the
> contents on an image.  The example text file is pasted below the macro.
>
> // begin macro
> file = File.openDialog("Select the text file to read");
> allText = File.openAsString(file);
> text = split(allText, "\n");
> hdr = split(text[0]);
>
> //these are the column indices
> iX = 0;
> iY = 1;
> iLabel = 2;
>
> setForegroundColor(255,255,255);
>
> run("Blobs (25K)");
>
> for (i = 1; i < (text.length); i++){
>   line = split(text[i]);
>   drawString(line[iLabel], parseInt(line[iX]), parseInt(line[iY]));
> }
> // end macro
>
> // begin example file
> X Y Label
> 10  20  "Bob"
> 50  70  "Jeff"
> 100 100 "Betty"
>
> //end example file
>
> Ben Tupper
You can also use point ROIs, which help if you want to look at one point
at a a time.  Just replace the code in Ben's for loop with

    makePoint(parseInt(line[iX]), parseInt(line[iY]));
    roiManager("Add");

Brad