Re: Filling a contour [message #60673] |
Wed, 11 June 2008 19:00 |
Robbie
Messages: 165 Registered: February 2006
|
Senior Member |
|
|
As discussed in previous threads, Polyfillv has unusual behavior.
"PolyFillV is not using the provided polygons coordinates but a fix()
of them.... which induce an extra line on the left and at the bottom."
Some people recommend applying round() to your polygon coordinates so
that it returns better results. I tend to think that using
IDLanROI::ComputeMask is a good idea.
Robbie
|
|
|
Re: Filling a contour [message #60674 is a reply to message #60673] |
Wed, 11 June 2008 18:02  |
Loren Anderson
Messages: 22 Registered: August 2007
|
Junior Member |
|
|
You could also create a ROI object and use the compute_mask function.
contour, image, Path_XY = path_xy ....
roi = Object_New('IDLANROI', path_xy)
mask = roi->Compute_Mask(dimensions = size(image, /Dim))
indices = where(mask EQ 255B)
There is a run_length keyword to compute_mask that you can use if you
don't want to create the entire mask.
-Loren
|
|
|
Re: Filling a contour [message #60675 is a reply to message #60674] |
Wed, 11 June 2008 16:32  |
Jye
Messages: 17 Registered: May 2008
|
Junior Member |
|
|
On Jun 7, 8:11 am, "mzagu...@gmail.com" <mzagu...@gmail.com> wrote:
> I have created a single contour and converted it into a 'contour
> image'. That is to say that I have created an N x M image array and
> populated it with 0's and placed a 1 where a contour point resides. I
> would like to be able to fill the interior of the contour with 1's.
> Any ideas? Thanks
Check out POLYFILLV. It will return the subscripts of the array within
the contour which you can then set to 1.
array[subscripts] = 1
Cheers
Jye
|
|
|
Re: Filling a contour [message #60716 is a reply to message #60675] |
Sun, 08 June 2008 09:59  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
> xcrossings = total(contour_image, 1, /cumulative)
> ycrossings = total(contour_image, 2, /cumulative)
> interior = where(xcrossings mod 2 and ycrossings mod 2, ninterior)
> if ninterior gt 0 then contour_image[interior]=1
Actually, that's going to fall down badly where the contour is tangent
to the x or y axis. So you probably need to resort to some sort of
iterative scheme of finding one interior point and then searching for
points around it.
-Jeremy.
|
|
|
Re: Filling a contour [message #60721 is a reply to message #60716] |
Sat, 07 June 2008 06:19  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
> I have created a single contour and converted it into a 'contour
> image'. That is to say that I have created an N x M image array and
> populated it with 0's and placed a 1 where a contour point resides. I
> would like to be able to fill the interior of the contour with 1's.
> Any ideas? Thanks
If the contour is closed in the image, then an interior point is
defined as having an odd number of contour crossings to the edge in
each direction. So I would create a new NxM array of "number of
contour crossings between x=0 and this point" and the same for y
(which, since everything is either 0 or 1, is simply the cumulative
sum). Then test for positions where both of these are odd and set
those to 1.
xcrossings = total(contour_image, 1, /cumulative)
ycrossings = total(contour_image, 2, /cumulative)
interior = where(xcrossings mod 2 and ycrossings mod 2, ninterior)
if ninterior gt 0 then contour_image[interior]=1
-Jeremy.
|
|
|