Re: uniform expansion [message #41321] |
Sat, 09 October 2004 09:13 |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
"mark" <mruschin@hotmail.com> wrote in message
news:a9116224.0410072307.6c4cb6d0@posting.google.com...
> Hello,
> Say I have a random 2D shape (a blob) with an irregular border (all
> pixel values equal to one). What I want to do is uniformly expand it
> in all directions such that it's increased by a constant integer
> number of pixels all around the perimeter. Subtraction of the
> original shape from the new one should yield a thin border with a
> constant width corresponding to the # of pixels the object was
> enlarged by.
> Does anyone have any suggestions... preferrably of an IDL nature?
>
> Regards,
> Mark
[comp.lang.idl removed from list, as I think you mean the IDL language from
RSI]
Hi Mark,
In IDL, you will want the Dilate function. Here's an example:
; Make sample data
IDL> a = Dist(15) GT 8
IDL> print,a
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 1 1 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
; Make a simple square structuring element for enlarging blob
; by desired width
IDL> width = 2
IDL> structElement = Replicate(1B, width*2+1, width*2+1)
IDL> print, structElement
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
; Perform dilation
IDL> b = Dilate(a, structElement)
IDL> print,b
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
IDL> print, b-a
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 0 0 1 1 1 0 0 0
0 0 1 1 1 1 1 0 0 1 1 1 1 1 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0
0 0 1 1 0 0 0 0 0 0 0 0 1 1 0
0 0 1 1 0 0 0 0 0 0 0 0 1 1 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0
0 0 1 1 1 1 1 0 0 1 1 1 1 1 0
0 0 0 0 1 1 1 0 0 1 1 1 0 0 0
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
If this dilation is too 'blocky' you may want a structuring element that is
'rounder' (say, with the four corner elements as 0 instead of 1). For more
info, have a look at Online Help for Dilate.
Hope this helps!
Cheers,
--
-Dick
Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
|
|
|
Re: uniform expansion [message #41330 is a reply to message #41321] |
Fri, 08 October 2004 03:10  |
Herbert Ramoser
Messages: 1 Registered: October 2004
|
Junior Member |
|
|
mark wrote:
> Hello,
> Say I have a random 2D shape (a blob) with an irregular border (all
> pixel values equal to one). What I want to do is uniformly expand it
> in all directions such that it's increased by a constant integer
> number of pixels all around the perimeter. Subtraction of the
> original shape from the new one should yield a thin border with a
> constant width corresponding to the # of pixels the object was
> enlarged by.
> Does anyone have any suggestions... preferrably of an IDL nature?
If I am not mistaken you are asking for morphological dilation:
help bwmorh
-Herbert
|
|
|