Re: Convert a set of points into an ROI
Posted by Gabriel Landini on May 13, 2009; 8:06am
URL: http://imagej.273.s1.nabble.com/Convert-a-set-of-points-into-an-ROI-tp3692520p3692527.html
On Tuesday 12 May 2009 23:46:42 Ghislain Bonamy wrote:
> Thanks for the long and detailed answer. I was planning to add this line
> tracing algorithm inside loci.plugins.util.? If this is OK with you.
> Perhaps you have a suggested Package/Class name? I have already though a
> bit to the case scenario you proposed. The way I intend to solve this is to
> check for points which are across and then diagonals. In addition, for the
> first point, I will force the trace to be clockwise (only check for pixels
> that are right, top, bottom, right-top diag, right-bottom diag) and force
> to start at the upper left corner of the shape. Finally, I would erased the
> points that were already used so that I would not trace backwards.
This is not a good idea. You need to scan points depending where your previous
point detected point was, not in any arbitrary order. See suggestion 1 below.
> A more
> problematic event would be:
>
> 010
> 111
> 000
No, you cannot blindly erase points that have been traversed already.
Think of this:
01000
10121
01000
You have to traverse point 2 twice. If you delete the first time, your
algorithm fails to reach the start ever again. Something like this happens in
the yellow particle near 730,561.
> However, I am pretty sure that this would never occur. Since it would be
> represented by:
> 010
> 101
> 000
I doubt that it will never occur.
> For the code, I plan to use List<Point> to store the initial coordinate and
> move them one by one into a Vector<Point> (corresponding to the Polygone
> calculated). Note: List.contains(currentPoint) works correctly, even if
> currentPoint is not the same object as the one entered. Let me know if you
> think the point structure is not ideal, or anything else is not ideal. Once
> this is written perhaps someone can see if it is optimized?
A few suggestions:
1. Do not reinvent the wheel. What you are trying to recreate is Freeman's
chain encoding algorithm which is already implemented in the particle analyzer
and in the particles4, particles8 and lines8 plugins.
2. Do not make assumptions of what might or not might occur in your images. If
you implement Freeman's algorithm correctly, it should deal with all cases,
and it is likely that what one thinks *might* not happen, will eventually
happen in some other image or when you change the segmentation conditions,
etc.
3. From what you say, your coordinate points are supposed to be 8-connected. I
would avoid repeating code if that already exists. The following would work:
Create an empty image and cell by cell:
plot the points,
extract the ROI
store it,
delete the points.
(you will need the last step because some of your objects touch neighbouring
objects, which makes it impossible to tell them appart in terms of foreground-
background (i.e. there is no space between objects).
4. The proper solution however is to get the coordinates already sorted by the
program that generates the boundaries.
I hope it helps
G