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)
|