Login  Register

Re: Intersection point(s) of two roi's.

Posted by vischer on Sep 12, 2010; 2:13pm
URL: http://imagej.273.s1.nabble.com/Intersection-point-s-of-two-roi-s-tp3686903p3686909.html

> In an image I draw two roi's, a straight line and an oval. I want to get the intersection coordinates (x,y) of these two roi's. Of course I can visually put the cursor at the intersection point(s) and read the (x,y) values in the ImageJ status bar. But I was wondering if there is an automatic way, without me to point the cursor to the intersection point. I tried using "AND" function of ROI Manger, but to no avail. Any suggestions?

Before ANDing a line roi, you need to convert it to an Area Roi.
The following macro does this, checks whether the line is falling or rising,
and selects the two correct corners from the 4 corners of the resulting boundary box.

"Line to Area" only works at a min line width of 2, which introduces some inaccuracy. If this is a problem, you better find a mathematical solution.

regards, Norbert


roiManager("Reset");
setTool("Oval");
waitForUser("Make Oval");
roiManager("Add");
run("Line Width...", "line=2");
setTool("Line");
waitForUser("Make Line");
getLine(x1, y1, x2, y2, lineWidth);
run("Line to Area");
rising = ((x2 - x1) * (y2 - y1)) < 0;
roiManager("Add");
roiManager("AND");
getSelectionBounds(x, y, width, height);
makeRectangle(x, y, width, height);//optional
xx1 = x;
xx2 = x + width;
if (rising){
        yy1 = y + height;
        yy2 = y;
}
else{
        yy1 = y;
        yy2 = y + height;
}
print("xx1=", xx1, "  yy1=", yy1, "  xx2=", xx2, "  yy2=", yy2);