Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hi everyone;
I am working in a plugin where the user can select different ROIs using a ROI manager,these ROIs could be different types(OvalRoi,Rectangle,Ellipse,etc). I need to get the coordinates of all the points inside the ROI; is trivial to get the perimeter coordinates but I cannot find a simple way for the points inside. My solution is using the method contain and iterate over the perimeter coordinates. I think must be an easier way... Am I missing something? Thanks in advance. PD: contain method work properly even with freehand ROIs.
Research engineer
HGGM. Madrid. |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
On Jun 5, 2013, at 9:56 PM, Peter Mc wrote:
> Hi everyone; > > I am working in a plugin where the user can select different ROIs using a > ROI manager,these ROIs could be different > types(OvalRoi,Rectangle,Ellipse,etc). I need to get the coordinates of all > the points inside the ROI; is trivial to get the perimeter coordinates but I > cannot find a simple way for the points inside. > My solution is using the method /contain/ and iterate over the perimeter > coordinates. > > I think must be an easier way... Am I missing something? Use a mask. There is an example at http://imagej.nih.gov/ij/plugins/calculate-mean.html It is not easier than using contains() but it is much faster. -wayne -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Thanks Wayne;
I am afraid cannot get why is much faster... I do not need to get the the pixel value(just X,Y coordinates),so getting the bounds is enough for the coordinates (Rectangle coordinates). Using some ROIs as ovals or ellipses some points inside the rectangle could not be inside the ROI but the method contains() fixes this issue quite good; sure I could avoid the method contains() establishing some restrictions over X and Y in the loop,but I think is not necessary get more complicated the code in my case. Actually I was looking for a direct way, don't know something close to : Point getROIPoints(Roi roi) { } Thank you for you answer and please let me know if you have a better idea than mine,haha.
Research engineer
HGGM. Madrid. |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hi Peter,
if you create a new Point object for each point in the ROI and put them into an array or vector, this will be slow - the Garbage Collector gets a lot of work to get rid of all the unnecessary Point objects (can be millions) after use. You can have int[][] roiPoints = getRoiPoints(Roi roi), which gives you two arrays, roiPoints[0] with all the x coordinates and roiPoints[1] with all the y coordinates. For creating these arrays, as Wayne said, it would be best to step through the mask, avoiding what may be millions of calls to the contains() method, with all the overhead of a method call. Something like the following (I did not try, so there may be lots of mistakes in it): int n=0; //number of points in the selection byte[] mask; Rectangle rect = roi.getBounds(); if (roi.getType()==Roi.RECTANGLE) { mask = null; n = rect.width*rect.height; } else { mask = (byte[])(roi.getMask().getPixels()); for (int i=0; i<mask.length; i++) if (mask[i] != 0) n++; //count points in mask } int[][] points = new int[2][n]; int i=0; for (int y=rect.y; y<rect.y+rect.height; y++) for (int x=rect.x; x<rect.x+rect.width; x++) if (mask==null || mask[i]!=0) { points[0][i] = x; points[1][i] = y; i++; } It might be worthwhile having something like this as method of Roi (and maybe even as a macro function getRoiPoints(xArray, yArray). If one does not care about the potentially huge memory consumption by the array, it could provide a simple way to write code that steps through all points of the roi. Michael ________________________________________________________________ On Jun 7, 2013, at 16:06, Peter Mc wrote: > Thanks Wayne; > I am afraid cannot get why is much faster... > I do not need to get the the pixel value(just X,Y coordinates),so getting > the bounds is enough for the coordinates (Rectangle coordinates). Using some > ROIs as ovals or ellipses some points inside the rectangle could not be > inside the ROI but the method /contains()/ fixes this issue quite good; sure > I could avoid the method contains() establishing some restrictions over X > and Y in the loop,but I think is not necessary get more complicated the code > in my case. > > Actually I was looking for a direct way, don't know something close to : > > Point getROIPoints(Roi roi) { } > > > Thank you for you answer and please let me know if you have a better idea > than mine,haha. > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Getting-coordinates-inside-a-ROI-tp5003250p5003280.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html ... [show rest of quote] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Thanks Michael;
I did not know how the mask works,now I can understand what you both said. Now I can allocate the right space for the points avoiding null points inside the array,about using a Point[] or int[][]... I am not sure how the Garbage Collector performs in Java,is there a big difference getting rid of a Point[] or int[][] when as in this case are both "full" (without null or 0 elements)?finally both are objects with a similar memory allocate by the new operator,aren't they? and what about the former case (with null elements)? Anyway these couple of questions are just for curiosity but I would like to know,haha. Thank you again for your answer ,your advice has been really useful.
Research engineer
HGGM. Madrid. |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hi Peter,
if you have a Point[100000] array, it's 100000+1 objects, the array and 100000 Point objects. If you have an int[2][100000], that's three objects: An int[][], which contains two 1-dimensional arrays. Each of these two arrays contains 100000 numbers, but the numbers are so-called primitives, no objects. By the way, there is also a significant difference of memory allocation: Two integer numbers need 8 bytes, but a Point object more than twice as much. Michael ________________________________________________________________ On Jun 10, 2013, at 20:25, Peter Mc wrote: > Thanks Michael; > > I did not know how the mask works,now I can understand what you both said. > Now I can allocate the right space for the points avoiding null points > inside the array,about using a Point[] or int[][]... I am not sure how the > Garbage Collector performs in Java,is there a big difference getting rid of > a Point[] or int[][] when as in this case are both "full" (without null or 0 > elements)?finally both are objects with a similar memory allocate by the new > operator,aren't they? and what about the former case (with null elements)? > Anyway these couple of questions are just for curiosity but I would like to > know,haha. > > Thank you again for your answer ,your advice has been really useful. > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Disable Popup Ads | Edit this page |