Measuring distance between points for tree ring widths

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

Measuring distance between points for tree ring widths

lindbeem
I have multiple tree core .tiff files that I want to analyze and calculate the distance from the pith to each respected ring.  I have used the multiple point tool and have marked the edge of each ring starting from the most recent year's growth all the way to marking the middle of the pith.  I'm planning to label them by calendar year and use the distances to do further calculations.  I am new to using ImageJ and macros, but essentially, I would like to be able to have a script calculate the distance between the tree ring to the pith for each measurement using the x and y coordinates.  Images were scanned using 3200 DPI resolution which is already set.  (I.E. If the tree is 82 years old, there will be 83 points.  Point #83 will be at the center of the core (pith), and every other point will mark the end of a tree ring.  So I want to measure the distance from point 1 to 83, 2 to 83, 3 to 83, 4 to 83, etc.)

Is there a tool that allows you to enter in the coordinates and specify how you would like them measured?   Also, I have marked the points on the tree core, but I am unable to see them in the ROI manager.  Is there an extra step that I need to do in order to get those points to show up?

Any help will be appreciated.  Thank you in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Measuring distance between points for tree ring widths

Straub, Volko A. (Dr.)
Dear lindbeem,

Once you have created a selection, you need to add it to the ROI
manager. You can do this by pressing 't' on your keyboard (if it doesn't
show on your image, tick the 'Show All' box in the ROI manager).
However, using the multipoint selection tool adds all the points as a
single selection. I think it is probably better to use the point
selection tool and add each point you want to measure as an individual
ROI to the ROI manager. Once that is done, the macro code below will
measure the distance between the first and all other points in the ROI
manager. The results are printed to the log window. So, as long as the
core (pith) is the first point in the ROI manager, the macro should
provide a list of the straight line distance between that point and all
other points.

Hope this helps,
Volko

roiManager("select",0);
Roi.getCoordinates(x0,y0);
for(i=1;i<roiManager("count");i++) {
     roiManager("select",i);
     Roi.getCoordinates(x,y);
     d=sqrt(pow(x[0]-x0[0],2)+pow(y[0]-y0[0],2));
     print(i,d);
}


On 15/10/2015 04:30, lindbeem wrote:

> I have multiple tree core .tiff files that I want to analyze and calculate
> the distance from the pith to each respected ring.  I have used the multiple
> point tool and have marked the edge of each ring starting from the most
> recent year's growth all the way to marking the middle of the pith.  I'm
> planning to label them by calendar year and use the distances to do further
> calculations.  I am new to using ImageJ and macros, but essentially, I would
> like to be able to have a script calculate the distance between the tree
> ring to the pith for each measurement using the x and y coordinates.  Images
> were scanned using 3200 DPI resolution which is already set.  (I.E. If the
> tree is 82 years old, there will be 83 points.  Point #83 will be at the
> center of the core (pith), and every other point will mark the end of a tree
> ring.  So I want to measure the distance from point 1 to 83, 2 to 83, 3 to
> 83, 4 to 83, etc.)
>
> Is there a tool that allows you to enter in the coordinates and specify how
> you would like them measured?   Also, I have marked the points on the tree
> core, but I am unable to see them in the ROI manager.  Is there an extra
> step that I need to do in order to get those points to show up?
>
> Any help will be appreciated.  Thank you in advance.
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Measuring-distance-between-points-for-tree-ring-widths-tp5014639.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> 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: Measuring distance between points for tree ring widths

Christopher Coulon-2
In reply to this post by lindbeem
Here’s a demo of one way to do this:



which is just this macro:

newImage("Demo", "RGB white", 500, 500, 1);
n = 0;
makePoint(241, 232);
manage();
makePoint(257, 233);
manage();
makePoint(271, 235);
manage();
makePoint(292, 240);
manage();
makePoint(320, 243);
manage();
makePoint(361, 246);
manage();
makePoint(397, 248);
manage();
makePoint(418, 247);
manage();
makePoint(436, 245);
manage();
makePoint(452, 244);
manage();

function manage() {
        roiManager("Add");
        roiManager("select", n);
        roiManager("Rename", n);
        n++
}

for(i = 0; i < roiManager("count"); i++) {
        n = i+1;

        run("Measure");

        x = getResult("X", i);
        y = getResult("Y", i);
       
        if(i == 0) {
                print("center point: x = " + x + ", y = " + y);
        }
        else {
                d = sqrt(x*x + y*y);
                print("Point " + n + " distance to center is " + d);
        }
}


> On Oct 14, 2015, at 8:30 PM, lindbeem <[hidden email]> wrote:
>
> I have multiple tree core .tiff files that I want to analyze and calculate
> the distance from the pith to each respected ring.  I have used the multiple
> point tool and have marked the edge of each ring starting from the most
> recent year's growth all the way to marking the middle of the pith.  I'm
> planning to label them by calendar year and use the distances to do further
> calculations.  I am new to using ImageJ and macros, but essentially, I would
> like to be able to have a script calculate the distance between the tree
> ring to the pith for each measurement using the x and y coordinates.  Images
> were scanned using 3200 DPI resolution which is already set.  (I.E. If the
> tree is 82 years old, there will be 83 points.  Point #83 will be at the
> center of the core (pith), and every other point will mark the end of a tree
> ring.  So I want to measure the distance from point 1 to 83, 2 to 83, 3 to
> 83, 4 to 83, etc.)
>
> Is there a tool that allows you to enter in the coordinates and specify how
> you would like them measured?   Also, I have marked the points on the tree
> core, but I am unable to see them in the ROI manager.  Is there an extra
> step that I need to do in order to get those points to show up?
>
> Any help will be appreciated.  Thank you in advance.
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Measuring-distance-between-points-for-tree-ring-widths-tp5014639.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html


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

treeRings.txt (850 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Measuring distance between points for tree ring widths

lindbeem
Hi Christopher,

Thank you so much for showing me an example of this!  So I ran the macro with your demo data, and also with my data, and the only problem is that it is somehow computing an average (or I think it's an average), and populates that number for each value when it prints, and also when the calculations show up in the results.

Also, I had another quick question.  In the example dataset that you gave, you called the manage function after every point.  I was wondering how I would do that if I am manually selecting my points.

Lastly, how would I be able to print the output in order to be compatible with a .csv format.  I want to be able to export the distance for each core, and then combine them into another .csv that I am using to look at other variables.

-Erik
Reply | Threaded
Open this post in threaded view
|

Re: Measuring distance between points for tree ring widths

lindbeem
In reply to this post by Straub, Volko A. (Dr.)
Hi Volko,

I ran your macro, and everything looked great at first, but I am getting strange units as a measurement.  At first I thought it was giving an output in pixels, so I tried converting the number into inches based on the dpi, but the number I obtained was much larger than it should be.  Based on the macro that you wrote, what would be the units of the output given?  
Reply | Threaded
Open this post in threaded view
|

Re: Measuring distance between points for tree ring widths

Straub, Volko A. (Dr.)
Hi,

The output of the measurements were in pixels as the coordinates reported by the ROI.getCoordinates (x,y) are in pixels. Below is a slightly modified version of the macro that reports the distance in pixels plus the calibrated distance and units (depending on values set in 'Analysis -> Set Scale').

Hope this helps,
Volko

roiManager("select",0);
Roi.getCoordinates(x0,y0);
for(i=1;i<roiManager("count");i++) {
     roiManager("select",i);
     Roi.getCoordinates(x,y);
     d=sqrt(pow(x[0]-x0[0],2)+pow(y[0]-y0[0],2));
     getPixelSize(unit,pixelWidth,pixelHeight);
     scaled=d*pixelWidth;
     print(i,d,scaled,unit);
}



-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of lindbeem
Sent: 16 October 2015 15:16
To: [hidden email]
Subject: Re: Measuring distance between points for tree ring widths

Hi Volko,

I ran your macro, and everything looked great at first, but I am getting strange units as a measurement.  At first I thought it was giving an output in pixels, so I tried converting the number into inches based on the dpi, but the number I obtained was much larger than it should be.  Based on the macro that you wrote, what would be the units of the output given?  



--
View this message in context: http://imagej.1557.x6.nabble.com/Measuring-distance-between-points-for-tree-ring-widths-tp5014639p5014664.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
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: Measuring distance between points for tree ring widths

Glen MacDonald-2
In reply to this post by lindbeem
Dear Erik,
Manually enter points into the ROIManager by selecting the Single Point tool and press ’t’ after you click on each each point in the image.
2 options for opening your files.  Save the default results as filename.xls (set the default extension with Edit>Options>Input/Output). Open in Excel by File>Import and choose ‘Space’ as the delimiter (or similar operation in statistics software).  
If you really want to create csv formatted files, insert a comma between values in the print statement by replacing the last line of Volko’s macro with this version:
    print(i,”,”,d,”,”,scaled,”,”,unit);

regards,
Glen MacDonald
        Core for Communication Research
Virginia Merrill Bloedel Hearing Research Center
        Cellular Morphology Core
Center on Human Development and Disability
Box 357923
University of Washington
Seattle, WA 98195-7923  USA
(206) 616-4156
[hidden email]







On Oct 16, 2015, at 7:09 AM, lindbeem <[hidden email]> wrote:

> Hi Christopher,
>
> Thank you so much for showing me an example of this!  So I ran the macro
> with your demo data, and also with my data, and the only problem is that it
> is somehow computing an average (or I think it's an average), and populates
> that number for each value when it prints, and also when the calculations
> show up in the results.
>
> Also, I had another quick question.  In the example dataset that you gave,
> you called the manage function after every point.  I was wondering how I
> would do that if I am manually selecting my points.
>
> Lastly, how would I be able to print the output in order to be compatible
> with a .csv format.  I want to be able to export the distance for each core,
> and then combine them into another .csv that I am using to look at other
> variables.
>
> -Erik
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Measuring-distance-between-points-for-tree-ring-widths-tp5014639p5014663.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> 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: Measuring distance between points for tree ring widths

Christopher Coulon-2
In reply to this post by lindbeem
Hi Erik,

It looks like others have helped you with this, but if you still have questions or want a macro that will be a working tool rather than the simple demo I sent you, I will be delighted to help you (no money, please!  ;-)

Chris

> On Oct 16, 2015, at 7:09 AM, lindbeem <[hidden email]> wrote:
>
> Hi Christopher,
>
> Thank you so much for showing me an example of this!  So I ran the macro
> with your demo data, and also with my data, and the only problem is that it
> is somehow computing an average (or I think it's an average), and populates
> that number for each value when it prints, and also when the calculations
> show up in the results.
>
> Also, I had another quick question.  In the example dataset that you gave,
> you called the manage function after every point.  I was wondering how I
> would do that if I am manually selecting my points.
>
> Lastly, how would I be able to print the output in order to be compatible
> with a .csv format.  I want to be able to export the distance for each core,
> and then combine them into another .csv that I am using to look at other
> variables.
>
> -Erik
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Measuring-distance-between-points-for-tree-ring-widths-tp5014639p5014663.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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