Determining whether a point lies within a closed region

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

Determining whether a point lies within a closed region

Douglas Benn-2
Could somebody please tell me if there is a tool or macro for determining whether or not a point with x,y coords lies inside a closed region of interest which has been created by the Process > Binary >Outline routine?

Thank you.

Douglas

Dr Douglas K Benn, BDS, M.Phil., Ph.D., Dipl. Dental Radiology (Royal College of Radiologists, England).
Professor
Dept of General Dentistry
Creighton University Dental School
2500 California Plaza
Omaha
Nebraska 68178

Tel: (402)280 5025
Fax: (402)280 5094
Reply | Threaded
Open this post in threaded view
|

Re: Determining whether a point lies within a closed region

Gabriel Landini
On Saturday 03 April 2010, you wrote:
> Could somebody please tell me if there is a tool or macro for determining
> whether or not a point with x,y coords lies inside a closed region of
> interest which has been created by the Process > Binary >Outline routine?

If you need to know in which outline, use morphological operators:

1. Fill the holes of the "outlines" image
2. Make a new image of the same dimensions where only your test pixel is ON
(and the rest is background)
3 Binary-reconstruct the pixel-only image as "seed" and the filled image as
"mask"
4. Apply the Particle Analyzer to the result image, If nResults==0, your pixel
is outside any outine, If nResults==1 it is inside the boundary which has
coordinates (XStart, YStart) (from the Results Table, so make sure that you
select "Record Starts" in the particle analyzer)

The BinaryReconstruct plugin can be downloaded from my page, it is in the
Morphology collection zip archive:
http://www.dentistry.bham.ac.uk/landinig/software/software.html

Here is a macro (it expects white objects on a black background and sets the
B&F colours accordingly). Note the line breaks.

run("Colors...", "foreground=white background=black selection=yellow");
newImage("MASK", "8-bit Black", 256, 256, 1);
makeOval(78, 63, 114, 108);
run("Draw");
run("Select None");
run("Fill Holes");

run("Duplicate...", "title=SEED");
run("Set...", "value=0");
setPixel(121,102, 255); // make test point

setBatchMode(true);
run("BinaryReconstruct ", "mask=MASK seed=SEED create white");
setThreshold(255, 255);
selectWindow("Reconstructed");
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00
show=Nothing display clear record");
if (nResults>0) print ("it is inside"); else print("it is not inside");
close();
setBatchMode(false);


If you need to know if it is in *any* outline, then it is simpler, just fill
holes, and check the colour of the test pixel in the filled image, If it is  
foreground colour, then it is inside a blob.

For a plugin there is a contains(x,y) method in the PolygonRoi.java class.
Cheers

G.
Reply | Threaded
Open this post in threaded view
|

Re: Determining whether a point lies within a closed region

Douglas Benn-2
Dear G,

Thank you very much for your time and effort.

Best wishes.

Douglas

Dr Douglas K Benn, BDS, M.Phil., Ph.D., Dipl. Dental Radiology (Royal College of Radiologists, England).
Professor
Dept of General Dentistry
Creighton University Dental School
2500 California Plaza
Omaha
Nebraska 68178

Tel: (402)280 5025
Fax: (402)280 5094



-----Original Message-----
From: ImageJ Interest Group on behalf of Gabriel Landini
Sent: Sat 4/3/2010 4:58 AM
To: [hidden email]
Subject: Re: Determining whether a point lies within a closed region
 
On Saturday 03 April 2010, you wrote:
> Could somebody please tell me if there is a tool or macro for determining
> whether or not a point with x,y coords lies inside a closed region of
> interest which has been created by the Process > Binary >Outline routine?

If you need to know in which outline, use morphological operators:

1. Fill the holes of the "outlines" image
2. Make a new image of the same dimensions where only your test pixel is ON
(and the rest is background)
3 Binary-reconstruct the pixel-only image as "seed" and the filled image as
"mask"
4. Apply the Particle Analyzer to the result image, If nResults==0, your pixel
is outside any outine, If nResults==1 it is inside the boundary which has
coordinates (XStart, YStart) (from the Results Table, so make sure that you
select "Record Starts" in the particle analyzer)

The BinaryReconstruct plugin can be downloaded from my page, it is in the
Morphology collection zip archive:
http://www.dentistry.bham.ac.uk/landinig/software/software.html

Here is a macro (it expects white objects on a black background and sets the
B&F colours accordingly). Note the line breaks.

run("Colors...", "foreground=white background=black selection=yellow");
newImage("MASK", "8-bit Black", 256, 256, 1);
makeOval(78, 63, 114, 108);
run("Draw");
run("Select None");
run("Fill Holes");

run("Duplicate...", "title=SEED");
run("Set...", "value=0");
setPixel(121,102, 255); // make test point

setBatchMode(true);
run("BinaryReconstruct ", "mask=MASK seed=SEED create white");
setThreshold(255, 255);
selectWindow("Reconstructed");
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00
show=Nothing display clear record");
if (nResults>0) print ("it is inside"); else print("it is not inside");
close();
setBatchMode(false);


If you need to know if it is in *any* outline, then it is simpler, just fill
holes, and check the colour of the test pixel in the filled image, If it is  
foreground colour, then it is inside a blob.

For a plugin there is a contains(x,y) method in the PolygonRoi.java class.
Cheers

G.