Re: Erosion/Dilation Operators [message #8203 is a reply to message #8201] |
Wed, 19 February 1997 00:00   |
djackson
Messages: 31 Registered: June 1993
|
Member |
|
|
In article <davidf-ya023080001702972225400001@news.frii.com>,
davidf@dfanning.com (David Fanning) wrote:
> Does anyone have any practical experience using the erosion
> and dilation operators in IDL? I can't make much sense of the
> documentation. In particular, I can't figure out what a good
> structuring element would be.
Hi David,
I've found erosion and dilation to be useful in filtering out 'islands' in
binary (thresholded) images that are smaller than what I'm interested in.
In general,
I've found a circular structuring element to be most useful, so as not to
introduce a horizontal or vertical bias (boxy-ness!) to the filtering.
It took me a while to get the binary_circle function (for integer 'n'
only, please!) to make nice-looking circles for me. See if this has any
use for you:
---
function binary_circle, n
dist1d = (findgen(n) - (n-1)/2.) ^ 2
dist2d = sqrt(dist1d # replicate(1, n) + replicate(1, n) # dist1d)
return, dist2d lt (n/2.)
end
function filter_it, image, n
return, dilate(erode(image, binary_circle(n)), binary_circle(n))
end
---
You can test this with:
IDL> a=(randomu(seed,200,200) gt 0.25) ; speckle field of mostly 1's
IDL> tvscl,a
IDL> tvscl,filter_it(a,4)
This should give you a lot of circles and joined paths at least as big as
a circle of diameter 4.
If you want to filter out 0's and keep 1's, I believe you have to just
invert the input array, do the filter_it, and invert the result.
Now, if you want to work with grayscale images and grayscale erode and
dilate, you could replace binary_circle with gray_circle, and use the
following, but I'm not sure if this is more helpful.
---
function gray_circle, n
dist1d = (findgen(n) - (n-1)/2.) ^ 2
dist2d = sqrt(dist1d # replicate(1, n) + replicate(1, n) # dist1d)
return, ((((n/2.) - dist2d) / (n/2.)) > 0) * 2
end
---
Good luck, David! [I cringe at my own lack of comments... please be gentle!]
PS: I don't meaning to be a twerp, but isn't it "ice floes" when referring
to floating masses of ice?
Cheers from the land of much ice!
-Dick
Dick Jackson djackson@ibd.nrc.ca Institute for Biodiagnostics
Opinions are mine alone. National Research Council Canada, Winnipeg
"And I told him my dream was to live for all time
In some perfect refrain, like the man who wrote 'Danny Boy'."
- Joe Jackson, from the album _Night_Music_, 1994.
|
|
|