comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: find_boundary routine
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: find_boundary routine [message #38636] Thu, 18 March 2004 18:47 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Brian Frizzelle writes:

> Let me apologize if this post is a bit lengthy. And in case it's
> important, I'm using IDL 6.0 on a Windows machine.
>
> I need help calculating the perimeters of regions. I have an input
> array of roughly 900 by 1200 cells which contains 15 different
> categories (coded 1 through 15). For each category, I need to find the
> total perimeter length among all of its regions.
>
> I found David Fanning's FIND_BOUNDARY routine and ran it on this
> array, but it seemed to stop at the first region that it found. So I
> wrote a script that subsetted each array first by category, then by
> region within the category (regions were created with LABEL_REGION).
> Running FIND_BOUNDARY again, I got an output for each category, but
> the numbers seemed off.
>
> So I resorted to creating a simple 5x5 array with two categories, one
> region each, to test the perimeter output of FIND_BOUNDARY.
> - Category 1 has 16 cells and a perimeter of 18.
> - Category 2 has 9 cells and a perimeter of 18.
> * FIND_BOUNDARY output a perimeter of 2 for each category.
> * FIND_BOUNDARY also only give me an output array with 2 X/Y
> coordinates.
>
> Has anyone else found this to be a problem? Maybe I'm passing in the
> wrong parameters. Here are the details of what I've done so far. Any
> help would be greatly appreciated.

Here is an example of a 5 by 5 array, with the middle 9 pixels
making up the region:

IDL> array=[[0,0,0,0,0],[0,1,1,1,0],[0,1,1,1,0],[0,1,1,1,0],[0,0, 0,0,0]]
IDL>indices = Where(array GT 0)
IDL>pts = Find_Boundary(indices, XSize=5, YSize=5, Perimeter=p)
IDL>Print, p
8.0

I had to make a small change to the Find_Boundary to accommodate this
few a number of indices. I had to change line 316 from this:

boundaryPts = IntArr(2, Long(xsize) * ysize / 4L)

To this:

boundaryPts = IntArr(2, Long(xsize) * ysize / 2L)

You might think the correct "perimeter" would be 9 in this
case, but you have to remember that the algorithm is calculating
from the center of each pixel. A quick sketch of these 9 pixels
and their centers will convince you that the correct answer is 8.

Other combinations of pixels in my tests gave similar correct
results. I think the algorithm is working properly.

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http:/www.dfanning.com/
Phone: 970-221-0438, IDL Book Orders: 1-888-461-0155
Re: find_boundary routine [message #38642 is a reply to message #38636] Thu, 18 March 2004 14:47 Go to previous messageGo to next message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Brian Frizzelle wrote:

> Let me apologize if this post is a bit lengthy. And in case it's
> important, I'm using IDL 6.0 on a Windows machine.
>
> I need help calculating the perimeters of regions. I have an input
> array of roughly 900 by 1200 cells which contains 15 different
> categories (coded 1 through 15). For each category, I need to find the
> total perimeter length among all of its regions.
>
> I found David Fanning's FIND_BOUNDARY routine and ran it on this
> array, but it seemed to stop at the first region that it found. So I
> wrote a script that subsetted each array first by category, then by
> region within the category (regions were created with LABEL_REGION).
> Running FIND_BOUNDARY again, I got an output for each category, but
> the numbers seemed off.
>
> So I resorted to creating a simple 5x5 array with two categories, one
> region each, to test the perimeter output of FIND_BOUNDARY.
> - Category 1 has 16 cells and a perimeter of 18.
> - Category 2 has 9 cells and a perimeter of 18.
> * FIND_BOUNDARY output a perimeter of 2 for each category.
> * FIND_BOUNDARY also only give me an output array with 2 X/Y
> coordinates.
>
> Has anyone else found this to be a problem? Maybe I'm passing in the
> wrong parameters. Here are the details of what I've done so far. Any
> help would be greatly appreciated.
>
> Brian Frizzelle
>
> -------------------------
>
> arrayTest: regCat1: regCat2:
> 1 1 1 2 2 1 1 1 0 0 0 0 0 1 1
> 1 1 1 2 2 1 1 1 0 0 0 0 0 1 1
> 1 1 1 1 2 1 1 1 1 0 0 0 0 0 1
> 1 1 1 1 2 1 1 1 1 0 0 0 0 0 1
> 1 1 2 2 2 1 1 0 0 0 0 0 1 1 1
>
> IDL> bndry = find_boundary(regCat1, XSize=5, YSize=5, Perimeter=perim)
> IDL> print, perim
> 2.0000000
> IDL> print, bndry
> 0 0
> 0 1


Hello,

I think David's FIND_BOUNDARY is looking for the 1-dimensional
subscripts of the 'blob' within the image. Try...

index = where(arrayTest EQ 1, cnt)
If cnt GT 0 Then $
bndry = find_boundary(index, XSize=5, YSize=5, Perimeter=perim) else
bndry = -1


Be careful using LABEL_REGION, it assign features that lie along the
image edge to the background.

Ben
Ben
Re: find_boundary routine [message #38669 is a reply to message #38636] Wed, 24 March 2004 10:29 Go to previous message
brian_frizzelle is currently offline  brian_frizzelle
Messages: 2
Registered: March 2004
Junior Member
David and Ben,

Thanks for the assistance. I now understand how David's routine works,
and it attacks this perimeter problem in a different manner than what
I needed. So I wrote a different routine which will calculate the
boundary of a region in an array, as long as all cells in the region
are coded with a 1.
The reason that the FIND_BOUNDARY routine didn't work for me is that I
needed to calculate the perimeters from the pixel corners rather than
the centers. So a one-pixel region should have a perimeter of 4, and a
2-by-2 region should have a perimeter of 8. In your routine, the
one-pixel region's perimeter would be 0, and the 2x2 pixel region's
perimeter would be 1.

If anyone is interested, I can post my code.

Brian
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Calling Matlab engine from IDL,
Next Topic: 2d extrema

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:47:37 PDT 2025

Total time taken to generate the page: 0.00650 seconds