Hello,
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? Thanks in advance, Ved |
> 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); |
I agree with Norbert that a mathematical solution would be more accurate.
The following macro returns the points of intersection, after drawing the rois on two masks and ANDing them (Max image calculator). Jerome. // Rois intersection example run("AuPbSn 40 (56K)"); makeOval(172, 120, 245, 129); roiManager("Add"); makeLine(167, 308, 370, 62); roiManager("Add"); setBackgroundColor(255, 255, 255); setForegroundColor(0, 0, 0); newImage("i1","8-bit White",getWidth,getHeight,1); i1=getImageID; roiManager("Select", 0); run("Draw"); newImage("i2","8-bit White",getWidth,getHeight,1); i2=getImageID; roiManager("Select", 1); run("Draw"); imageCalculator("Max create", i1,i2); i3=getImageID; for (x=0;x<getWidth;x++) { for (y=0;y<getHeight;y++) { if (getPixel(x,y)==0) { makePoint(x,y); roiManager("Add"); } } } selectImage(i1); close; selectImage(i2); close; selectImage(i3); close; roiManager("Show All"); // end macro On Sun, Sep 12, 2010 at 4:13 PM, Norbert Vischer <[hidden email]>wrote: > > 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); > |
In reply to this post by ved sharma-2
Hi Norbert and Jerome,
Thanks for your replies. Jerome's methods works better but the problem is: 1. If the roi (both line and oval) thickness is 1, then sometimes there is no intersection point. 2. If the roi (line and/or oval) thickness is >1, then mostly I get multiple points for one true intersection point. Ved |
On Wednesday 15 September 2010 22:04:57 Ved Sharma wrote:
> Thanks for your replies. Jerome's methods works better but the problem is: > 1. If the roi (both line and oval) thickness is 1, then sometimes there is > no intersection point. > > 2. If the roi (line and/or oval) thickness is >1, then mostly I get > multiple points for one true intersection point Maybe you need to do something like this using the paramters that define the line and the circle/ellipse: http://mathworld.wolfram.com/Circle-LineIntersection.html or http://en.allexperts.com/q/Geometry-2060/Line-Ellipse-Intersection.htm ROIs are discrete, so no-points or multiple points results should be expected. Cheers G. |
In reply to this post by ved sharma-2
Yeah, I wish it was that easy. In my original email I said oval(ellipse), just to keep things simple. In reality, I am looking for the intersection points of a straight line and a ROI drawn with the freehand selection (representing cell boundary). Thanks for your reply though!
Ved |
> eah, I wish it was that easy. In my original email I said oval(ellipse), just to keep things simple. In reality, I am looking for the intersection points of a straight line and a ROI drawn with the freehand selection (representing cell boundary). Thanks for your reply though!
> > Ved Travel along all points of your line and check where it enters and leaves the roi. Wayne, it would be nice if there was a macro like selectionContains(x, y) Currently, you have to do this in JavaScript: roi = IJ.getImage().getRoi(); inside = roi.contains(100, 100); print(inside); http://imagej.588099.n2.nabble.com/eval-script-roi-contains-x-y-td4854845.html#a4855568 Norbert |
The 1.44g daily build has a selectionContains(x,y) macro function.
-wayne _______________________________________ From: Norbert Vischer [[hidden email]] Sent: Thursday, September 16, 2010 5:22 AM To: List IMAGEJ Subject: Re: Intersection point(s) of two roi's. > eah, I wish it was that easy. In my original email I said oval(ellipse), just to keep things simple. In reality, I am looking for the intersection points of a straight line and a ROI drawn with the freehand selection (representing cell boundary). Thanks for your reply though! > > Ved Travel along all points of your line and check where it enters and leaves the roi. Wayne, it would be nice if there was a macro like selectionContains(x, y) Currently, you have to do this in JavaScript: roi = IJ.getImage().getRoi(); inside = roi.contains(100, 100); print(inside); http://imagej.588099.n2.nabble.com/eval-script-roi-contains-x-y-td4854845.html#a4855568 Norbert |
Free forum by Nabble | Edit this page |