Re: Need help with vector processing. [message #10872] |
Thu, 12 February 1998 00:00 |
Dan Bergmann
Messages: 2 Registered: February 1998
|
Junior Member |
|
|
S Penzes wrote:
>
> Hi one and all,
> I am looking for a smart solution to a problem that keeps occuring
> and that I can't
> seem to find a smart solution for.
> Bear in mind that the example I am using here is much simplified from
> the image
> processing I am trying to do. The goal is to find a solution that
> minimizes compute time (ie no loops).
> Given a vector (lets say vector=[0,0,6,7,8,8,7,0,0,7,8,0,0]) and the
> fact that I have a window that is 3 wide, how do I process vector so
> that any data that is greater than 5 and stays that way for more than 3
> indexes remains and everything else is set to 0.
>
> vector -> process -> [0,0,6,7,8,8,7,0,0,0,0,0,0]
How about
vector=[0,0,6,7,8,8,7,0,0,7,8,0,0]
limit = 5
len = (size(vector))(1)
pad = [limit,limit,vector,limit,limit] gt limit
vector = vector * $
(pad(2:len+1) and $
((pad(1:len) and pad(3:len+2)) $
or(pad(1:len) and pad(0:len-1)) $
or(pad(3:len+2) and pad(4:len+3))))
This is finding the locations where the data and its two nearest
neighbors is greater than the limit, or where the data and its
two neighbors to the left are greater than the limit, or where
the data and its two neighbors to the right are greater than the
limit. Is this what you need??
--
************************************************************ ***
** Dan Bergmann dbergmann@llnl.gov **
** Atmospheric Science Division fax (510) 423-4908 **
** Lawrence Livermore National Lab human (510) 423-6765 **
************************************************************ ***
|
|
|
Re: Need help with vector processing. [message #10884 is a reply to message #10872] |
Wed, 11 February 1998 00:00  |
Brian Jackel
Messages: 34 Registered: January 1998
|
Member |
|
|
S Penzes wrote:
>
> Hi one and all,
> I am looking for a smart solution to a problem that keeps
> occuring and that I can't seem to find a smart solution for.
> The goal is to find a solution that minimizes compute time
> (ie no loops). Given a vector=[0,0,6,7,8,8,7,0,0,7,8,0,0]
> and the fact that I have a window that is 3 wide, how do I
> process vector so that any data that is greater than 5 and
> stays that way for more than 3 indexes remains and everything
> else is set to 0.
>
> vector -> process -> [0,0,6,7,8,8,7,0,0,0,0,0,0]
One way is to use the ERODE and DILATE operators, which
can find the mimimum or maximum values in a sliding window.
For example:
IDL> print,test
0 0 6 7 8 8 7 0 0 7 8 0 0
IDL> print,ERODE(test,[1,1,1],/GRAY)
0 0 0 6 7 7 0 0 0 0 0 0 0
IDL> print,DILATE(test,[1,1,1],/GRAY)
0 6 7 8 8 8 8 7 7 8 8 8 0
when combined they can be used to "erode" islands smaller
than the window width, then re-expand the edges of anything
that survives:
IDL> print,DILATE(ERODE(test,[1,1,1],/GRAY),[1,1,1],/GRAY)
0 0 6 7 7 7 7 0 0 0 0 0 0
which is pretty close to what you wanted. Then just do
IDL> islands= DILATE(ERODE(test,[1,1,1],/GRAY),[1,1,1],/GRAY)
IDL> print,test*(islands GT 0)
0 0 6 7 8 8 7 0 0 0 0 0 0
and you're home free. It's funny, erode and dilate have
been in IDL for quite a while now, but it's only in the
last couple of months that I've realized how useful they
can be. Hope this helps.
Brian Jackel
ps. in your statement of the problem you mention that values
of 5 or less should vanish, but I've assumed you've already
removed them with something like test= test*(test GT 5)
|
|
|