Login  Register

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

Posted by Michael Entrup on Jun 03, 2014; 8:05am
URL: http://imagej.273.s1.nabble.com/Generating-random-points-and-tallying-proportion-of-points-that-fall-within-object-tp5007986p5007998.html

Hi,

the macro presented by Olivier Burri works fine. I used

run("Blobs (25K)");
setAutoThreshold("Default dark");
setOption("BlackBackground", false);
run("Convert to Mask");

to create an appropriate image that only contains 0 and 255.

But I think the random points generator needs to be optimised. There is
a small chance to create a point twice. The change decreases with the
size of the image, but it should not be neglected.

It is more important to replace

xcoords[i] = round(random()*x);
ycoords[i] = round(random()*y);

by

xcoords[i] = round(random()*(x-1));
ycoords[i] = round(random()*(y-1));

For example the width of "Blobs" is 256, but the most right pixel has
the x-coordinate 255. With "random()" that generates numbers between 0
and 1 you need "round(random()*(x-1))" to generate x-coordinates between
0 and 255.

Best regards
Michael


Am 02.06.2014 18:23, schrieb atawewe:

> Thanks for helping to resolve this challenge!
> Your solution does work, because it generates 1000 random points. But I
> think there's a problem because the output always says: "0 points out of
> 1000 inside objects of interest". I have tried it out on 3 different images
> and get the same output.
> I have no experience writing macros, but reading through the one you
> generously wrote to solve my problem, I think the problem is that the code
> is searching for points for which the x and y coordinates equal 255. My
> guess is that there needs to be a line of code that extracts the pixel value
> or the color of that point to determine if it equals 255.
>
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Generating-random-points-and-tallying-proportion-of-points-that-fall-within-object-tp5007986p5007989.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