Login  Register

Re: How to count points within a specified area?

Posted by voidspaces on Jan 20, 2014; 5:34am
URL: http://imagej.273.s1.nabble.com/How-to-count-points-within-a-specified-area-tp5006175p5006188.html

Thank you!
On 19 Jan 2014, at 17:32, Rasband, Wayne (NIH/NIMH) [E] [via ImageJ] <[hidden email]> wrote:

On Jan 18, 2014, at 9:18 AM, voidspaces wrote:

> Hi everyone
>
> I have a picture on which I selected different points with the point tool. I
> also have different areas selected on the same pictures and I would like to
> count the points within a specified area. I thought it would have been
> possible to "AND" the group of points (points are saved in a single ROI) and
> the specified area but as a results I would get the area itself.

Here is a macro that counts points within different areas. It assumes the image has an overlay and the points are the first element of the overlay and the areas are the remaining elements.

  Overlay.activateSelection(0);
  if (selectionType!=10)
     exit("1st element of overlay must be point");
  getSelectionCoordinates(x, y);
  counts = newArray(Overlay.size-1);
  for (i=1; i<Overlay.size; i++) {
     Overlay.activateSelection(i);
     for (j=0; j<x.length; j++) {
        if (selectionContains(x[j],y[j]))
           counts[i-1] += 1;
     }
     print("Area "+i+" contains "+counts[i-1]+" points");
  }

Here is the output from running the macro on the attached image:

  Area 1 contains 4 points
  Area 2 contains 2 points
  Area 3 contains 2 points
  Area 4 contains 0 points

Here is the output of the Image>Overlay>List Elements command (requires v1.48a or later):

  0     null    Point   114     94      226     196     yellow  none    0       0       0       0       0
  1     null    Oval    68      61      190     209     yellow  none    0       0       0       0       0
  2     null    Oval    217     124     168     145     yellow  none    0       0       0       0       0
  3     null    Oval    135     22      279     126     yellow  none    0       0       0       0       0
  4     null    Oval    81      337     250     56      yellow  none    0       0       0       0       0

[cid:<a href="x-msg://2/user/SendEmail.jtp?type=node&amp;node=5006180&amp;i=0" target="_top" rel="nofollow" link="external">[hidden email]]




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

points.jpg (26K) Download Attachment



If you reply to this email, your message will be added to the discussion below:
http://imagej.1557.x6.nabble.com/How-to-count-points-within-a-specified-area-tp5006175p5006180.html
To unsubscribe from How to count points within a specified area?, click here.
NAML