Posted by
Jeremy Adler on
Jun 02, 2014; 8:13pm
URL: http://imagej.273.s1.nabble.com/Generating-random-points-and-tallying-proportion-of-points-that-fall-within-object-tp5007988p5007993.html
There is nothing magic about 1000 random, or even non random points.
Measuring every point (the whole image) is self evidently better than sampling a subset of the points, you don't even need to write a macro to do it.
The whole image is as unbiased as you can get, any remaining bias orignatedin how you images were acquired.
________________________________________
From: ImageJ Interest Group [
[hidden email]] on behalf of atawewe [
[hidden email]]
Sent: 02 June 2014 19:14
To:
[hidden email]
Subject: Re: Generating random points and tallying proportion of points that fall within object
Your points are valid, and what you describe sounds quite practical. However,
I need to generate random points to get an unbiased estimate of the
proportion of the image occupied by the objects of interest. I already got a
solution to this bit, as another kind contributor wrote a macro for me that
will generate 1000 random points. What I need to figure out now is how to
include a line of code in the macro that gets the pixel value for each of
those points and determine if they fall within the object of interest i.e.
black or have a value of 255. As it is, my guess is that the macro is
checking if the x and y coordinates equal 255 and so the output is always 0.
Any thoughts on this?
See macro below:
// 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
--
View this message in context:
http://imagej.1557.x6.nabble.com/Generating-random-points-and-tallying-proportion-of-points-that-fall-within-object-tp5007988p5007991.htmlSent 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