Set of tangents to a selection

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

Set of tangents to a selection

Michael Doube
Hi All

I want to simulate calliper measurement of an ROI, which is the distance
between two parallel tangents to the ROI.  The tangents cannot penetrate
the inside of an irregular ROI, as callipers in the real world must stay
on the outside of a specimen.  Has anyone implemented such a measurement?

I've had a go with macro language: the following macro generates a large
number of lines then tests to see if any of the points in the selection
equate to 0, if so then they intersect and if there is only one
intersection then the line should be a tangent - but unfortunately the
way that selections are defined means that there are holes that the line
can go through, so most of the solutions aren't tangents. You can alter
stepsize and radstep to change the density of test lines.

All comments appreciated,

Mike
-------------------------
//Tangents.txt
//draw a selection and run this macro

pi = 3.141592654;
width = getWidth();
stepsize = 8;
radstep = pi/32;
getSelectionCoordinates(periostx, periosty);
for (theta = -pi/2; theta < pi/2; theta = theta+radstep){
    for (step = sqrt(2)*getWidth()/2; step > 0; step=step-stepsize){
        intersections = 0;
        for (n = 0; n < lengthOf(periostx)-1; n++){
            zerotest = periostx[n]*tan(theta)+step/cos(theta)-periosty[n];
            if (zerotest > -1 && zerotest < 1 ) {
                intersections++;
            }
        }
        if (intersections == 1){
            for (x=0; x<width; x++){
                setPixel(x,(x*tan(theta)+step/cos(theta)), 128);
            }
        }
        updateDisplay();
    }
}

--
Michael Doube  BPhil BVSc PhD MRCVS
Research Associate
Department of Bioengineering
Imperial College London
South Kensington Campus
London  SW7 2AZ
United Kingdom
Reply | Threaded
Open this post in threaded view
|

Re: Set of tangents to a selection

Gabriel Landini
On Monday 31 March 2008 11:40:39 Michael Doube wrote:
> I want to simulate calliper measurement of an ROI, which is the distance
> between two parallel tangents to the ROI.

What you want is called "rotating calipers algorithm".
One only needs to test this for the points in the convex hull.
The reference is this:

http://cgm.cs.mcgill.ca/~orm/rotcal.frame.html

This applet (that does not run in my browser) has some source code:

http://cgm.cs.mcgill.ca/~orm/RCS.frame.html

The minimum area enclosing rectangle of a polygon is calculated with this
algorithm too.

Cheers,

Gabriel