Set of tangents to a selection
Posted by Michael Doube on Mar 31, 2008; 10:40am
URL: http://imagej.273.s1.nabble.com/Set-of-tangents-to-a-selection-tp3696741.html
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