Re: MEDIAN filtering and why it's not working [message #12046] |
Fri, 12 June 1998 00:00 |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
David Foster wrote:
>
> If you want only the median values from every 3 elements, then you
> can use:
>
> index = lindgen(n_elements(array))
> ind3 = where(index mod 3 eq 0)
>
> median3 = (median(array, 3))[ind3]
>
Whoops! That second line should read:
ind3 = where(index mod 3 eq 1)
^^^
Dave
> --
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
> David S. Foster Univ. of California, San Diego
> Programmer/Analyst Brain Image Analysis Laboratory
> foster@bial1.ucsd.edu Department of Psychiatry
> (619) 622-5892 8950 Via La Jolla Drive, Suite 2240
> La Jolla, CA 92037
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|
Re: MEDIAN filtering and why it's not working [message #12061 is a reply to message #12046] |
Thu, 11 June 1998 00:00  |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
"T Bowers" <tbowers@nrlssc.navy.mil> writes:
> Hi,
> How come
> print, median([0.0,1.0,1.5,2.0,5.0,6.0], 3, /EVEN)
> prints
> 0.00000 1.00000 1.50000 2.00000 5.00000 6.00000
> instead of
> 1.00000 1.00000 1.00000 5.00000 5.00000 5.00000
> Doesn't look like it's filtering anything to me, no matter what
> I set the filter width to.
> Actually, I'd really like it to print
> 1.00000 5.00000
> just the median of each filter width. I'm trying to filter spikes in
> time series data.
> I'm using IDL 5.02 and win95
One of the oddities of the median filter program is that it doesn't filter
points near the edges of the array. It doesn't filter points if there aren't
enough points on either side. In your example, with a filter width of three,
then it won't filter the points on either end, because it needs one point
before and one point after for each point it filters.
If I understand you correctly, I think you want to do something like the
following. It would require that array be evenly divisible by the filter
width.
array = [0.0,1.0,1.5,2.0,5.0,6.0]
n = n_elements(array) / 3
array = reform(array, 3, n, /overwrite)
for i=0,n-1 do array(*,i) = median(array(*,i))
array = reform(array, 3*n, /overwrite)
This would give you
1.00000 1.00000 1.00000 5.00000 5.00000 5.00000
as you request. However, the last step would probably be better implemented as
array = reform(array(0,*), /overwrite)
to remove the repeated entries. This would give you simply
1.00000 5.00000
William Thompson
|
|
|
Re: MEDIAN filtering and why it's not working [message #12073 is a reply to message #12061] |
Wed, 10 June 1998 00:00  |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
T Bowers wrote:
>
> Hi,
> How come
>
> print, median([0.0,1.0,1.5,2.0,5.0,6.0], 3, /EVEN)
>
> prints
> 0.00000 1.00000 1.50000 2.00000 5.00000 6.00000
>
> instead of
> 1.00000 1.00000 1.00000 5.00000 5.00000 5.00000
>
> Doesn't look like it's filtering anything to me, no matter what
> I set the filter width to.
>
> Actually, I'd really like it to print
> 1.00000 5.00000
> just the median of each filter width. I'm trying to filter spikes in
> time series data.
> I'm using IDL 5.02 and win95
Check the Online help for info on MEDIAN(), because you are a bit
confused as to how it works. For example, the median of [1.0,1.5,2.0]
is 1.5, not 1.0 as you suggest. With a width of 3, each element
of your median array will be the median of itself and its two
neighbors. Since your array is monotonically increasing, each
element will be it's "own" median value.
If you want only the median values from every 3 elements, then you
can use:
index = lindgen(n_elements(array))
ind3 = where(index mod 3 eq 0)
median3 = (median(array, 3))[ind3]
Hope this helps.
Dave
>
> tia,
> todd bowers
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|