How to count points within a specified area?

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

How to count points within a specified area?

voidspaces
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.

Can anyone help?

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: How to count points within a specified area?

Rocco D'Antuono
This post was updated on .
Hi, suppose you have the points saved in different ROI; in this case you can just select the Area ROI and use "selectionContains(x, y)" function looping on each point: count the times you get "true" value and you get the result.

P.S. In order to loop on each point, first you would need to store (x,y) coordinates in two array

Regards,
Rocco
Senior Microscopist
Crick Advanced Light Microscopy facility (CALM)
The Francis Crick Institute
1 Midland Road, NW1 1AT, London (UK)
https://roccodant.github.io/
Reply | Threaded
Open this post in threaded view
|

Re: How to count points within a specified area?

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by voidspaces
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:[hidden email]]




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

points.jpg (26K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to count points within a specified area?

voidspaces
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