comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Local max filter
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Local max filter [message #26430 is a reply to message #26339] Tue, 28 August 2001 02:47 Go to previous message
Martin Downing is currently offline  Martin Downing
Messages: 136
Registered: September 1998
Senior Member
Hi All,

I almost have a solution for N dimensional arrays, but since it is a SHIFT
based solution I need help on solving the wrap problem (well its a problem
to me!) -
i.e.. I need to prevent wrap and instead replicate the last elements of the
array in that dimension: e.g.: what we have is:
> print, shift([-2,1,3,8],1)
8 -2 1 3

we would like
> print, shift([-2,1,3,8],1, /REPLICATE_BORDER)
-2 -2 1 3

So in trying to solve this problem I am laying down another challenge for
the boys ;)
Anyway - heres my code for those interested - its still ok for large arrays
and could always be padded round the edges.

function local_maxima, array, width, INDEX=INDEX
;+
; Purpose: Calculates local maxima of ARRAY of any dimension
; Restrictions: incorrect results around the array border of WIDTH elements
; maybe be produced due to maxima wrapping from use of shift
; allows multiple maxima within WIDTH if identical
; - should be fairly fast even for large WIDTHs
; MRD 26/08/2001
;-
marr=array ; temp array in which maxima "dilate"
s = size( marr )
ndims = s[0]
sarr = intarr(ndims) ; array for controlling shift
sarr[0] = 1 ; set to shift one dimension at a time

for w = 1, width do begin
for d = 1, ndims do begin
marr = shift(marr, sarr) > shift(marr, -sarr) > marr
; NOTE need shift to replicate border pixels rather than wrapping
sarr = shift(sarr, 1)
endfor
endfor

if keyword_set(INDEX) then begin
return, where(marr eq array)
endif else begin
return, (marr eq array)*marr
endelse

end
; END OF LOCAL_MAXIMA

--
----------------------------------------
Martin Downing,
Orthopaedic RSA Research Centre,
Woodend Hospital, Aberdeen, AB15 6LS.
m.downing@abdn.ac.uk

"Craig Markwardt" <craigmnet@cow.physics.wisc.edu> wrote in message
news:onn14ryalz.fsf@cow.physics.wisc.edu...
>
> JD Smith <jdsmith@astro.cornell.edu> writes:
>>> JD and I had a contest doing this kind of thing -- finding maxima -- a
>>> year or so ago. Of course I popped his socks off, but he will tell
>>> you a different story :-)
>>
>> Hmmmph... from my posting before of April 2000:
>>
>> "Nice entry Craig. But unfortunatly it doesn't *alway* do exactly what
>> was
>> requested. It works fine for n=5, but for n>5 (7,9,...), the index is
>> off..."
>
> Yeah, I was just baiting you a little. :-)
>
>
>
>> P.S. Craig, now that I have your attention, I have an unrelated
>> question, the answer to which might be of general interest. How do you
>> feel about your excellent fitting/minimization routines being
>> distributed with a large scale freely available system for scientific
>> reduction and analysis?
>
> I feel fine about that. Of course, someone *else* will provide the
> support, not me. :-) Any more details?
>
> Craig
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: is this a managed usegroup or not ?
Next Topic: Dataminer and mySQL?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 06:54:39 PDT 2025

Total time taken to generate the page: 1.92034 seconds