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

Home » Public Forums » archive » Moving window mode
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Moving window mode [message #50599] Sun, 08 October 2006 20:24
Luke is currently offline  Luke
Messages: 4
Registered: October 2006
Junior Member
I use smooth to calculate a moving window mean and have seen posts
relating to other moving window moments, but can't figure out how to do
a moving window mode (w/out nested loops).

Any ideas...?

Below is the code with nested loops I currently use...

function mode,arr ;code from JD Smith - (http://tinyurl.com/zpbxp)
compile_opt idl2
on_error, 2
;note... if array is multimodal,
;this function returns the LOWEST value
;of the equal highest frequency values
void=max(histogram(arr,omin=mn),mxpos)
mode=mn+mxpos
return, mode
end
function focalmode, arr, win
compile_opt idl2
on_error, 2

dims = size(arr,/dimensions)
cols=dims[0]
rows=dims[1]

if win mod 2.0 eq 0 then win-=1 ;win needs to be an odd number
win2=(win-1)/2 ;num pixels from centre pixel to edge of moving
window

fm_array=arr

for Y=0,ROWS-1 do begin
;watch out for the edges...
ywin_u = y < win2 ;num pixels from centre pixel to upper
edge of moving window
ywin_d = rows-1-y < win2 ;num pixels from centre pixel to lower
edge of moving window
for X=0,COLS-1 do begin
;watch out for the edges...
xwin_l = x < win2 ;num pixels from centre pixel to
left edge of moving window
xwin_r = cols-1-x < win2 ;num pixels from centre pixel to
right edge of moving window
;Calc the mode
fm_array[X,Y] =
mode(fm_array[X-xwin_l:X+xwin_r,Y-ywin_u:Y+ywin_d])
endfor
endfor

return, fm_array

end

PS: verrry newbie in IDL, be nice ;)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: call_procedure with a dynamically created arguments list?
Next Topic: MPFIT for 21st Century

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

Current Time: Wed Oct 08 09:15:13 PDT 2025

Total time taken to generate the page: 0.02182 seconds