Login  Register

Re: Generating random points and tallying proportion of points that fall within object

Posted by Olivier Burri on Jun 02, 2014; 2:44pm
URL: http://imagej.273.s1.nabble.com/Generating-random-points-and-tallying-proportion-of-points-that-fall-within-object-tp5007986p5007987.html

Hi,

The simplest thing I can think of is as follows:

You have your image which you can threshold to get a mask (a BW image that has values of either 0 or 255).

Generate random points using this macro which also counts how many are inside your object.

// START OF MACRO
// This macro assumes you have a binary image.

// Number of points to generate
n_points = 1000;


name = getTitle(); // Name of the image
getDimensions(x,y,z,c,t); // Size of the image

// Initialize arrays that will contain point coordinates
xcoords = newArray(n_points);
ycoords = newArray(n_points);

// Seed the random number generator
random('seed', getTime());

// Create n_points points in XY
for (i=0; i<n_points; i++) {
        xcoords[i] = round(random()*x);
        ycoords[i] = round(random()*y);
}

// Overlay them on the image
makeSelection("point", xcoords, ycoords);

// Count points that have a value of 255
prevRes = nResults;
run("Measure");
count = 0;

for (i=0; i<n_points;i++) {
        val = getResult("Mean",i+prevRes);
        if (val == 255) {
                count++;
        }
}

// Output to log window.
print("Image "+name+": "+count+" points out of "+n_points+" inside objects of interest");

// END OF MACRO


Olivier Burri
Engineer - Image Processing
& Software Development
EPFL - SV - PTECH - PTBIOP

> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
> atawewe
> Sent: lundi 2 juin 2014 15:55
> To: [hidden email]
> Subject: Generating random points and tallying proportion of points that fall
> within object
>
> I have over 300 images I need to process to obtain an unbiased estimate of the
> proportion of each image that is occupied by the object of interest. For each
> image, the objects of interest are black in color, mostly spherical in shape, but
> range in sizes, while the background of the image is white. The challenge for me
> is that I need to generate 1000 random points on each image, and determine the
> proportion of points that fall within the objects of interest in the image. I will
> appreciate information on how to achieve this using imageJ. After searching
> online, I really couldn't find any tips on where to start from or how to go about
> generating random points on an image and estimating whether they fall within
> the object of interest or not in imageJ.
>
> Thanks in advance.
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Generating-
> random-points-and-tallying-proportion-of-points-that-fall-within-object-
> tp5007986.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