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

Home » Public Forums » archive » Local Maxima of 2D array
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 Maxima of 2D array [message #69542 is a reply to message #69489] Fri, 22 January 2010 01:56 Go to previous messageGo to previous message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
On 21 Jan., 18:39, Robin Wilson <r.t.wil...@rmplc.co.uk> wrote:
>> Dear Robin,
>> did you tried to reform that array to 3D and to find the MAXima and
>> their indices together with the keyword DIMENSION=3? Don't forget that
>> REFORM 'forms' rowwise.
>
>> Cheers
>
>> CR
>
> Hi Chris,
>
> Thank you very much for your suggestion. I have looked at the
> documentation for the REFORM function, but I'm not sure how to reform
> the array to a suitable 3D form so that MAX will work with the
> dimension=3 keyword. Could you provide some more details?
>
> Best regards,
>
> Robin Wilson
> University of Southampton

Dear Robin,

basically the code without a loop could be:

function cr_get_windowed_extrema,b,sx_k,sy_k

sk = long(sx_k)*long(sy_k)
sz = size(b,/dimensions)
sm = long(sz[0])*long(sz[1])
ind= (reform((transpose(lindgen(sz[0],sz[1])))[*],sx_k,sm/sx_k))
[0:sy_k-1,*]
mins= min(b[(reform((transpose((transpose(rebin(ind,sx_k,sm/sy_k,s y_k)
+$
rebin(lindgen(1,1,sy_k),sx_k,sm/sx_k,sy_k),[0,2,1])),
[1,0,2])),sk,sm/sx_k))],$
minind,max=maxs,subscript_max=maxind,dimension=1)
ind2=(lindgen(sx_k,sm/sk))[*,0:*:sy_k]
return, {mins:mins[ind2],minind:minind[ind2],maxs:maxs
[ind2],maxind:maxind[ind2]}
end

As potential output I got:

IDL> b=randomn(seed,9,9)
IDL> c=cr_get_windowed_extrema(b,3,3)
IDL> print,b
-0.232820 -1.81190 -1.79086 -0.0838641 -1.42229
-0.569596 -0.000931759 0.197937 0.203128
-0.742161 -1.04460 0.286660 1.59126 -1.18528
1.11088 -1.17374 -1.51570 0.156324
0.265435 -1.02502 -0.232129 0.259060 -0.825678
-0.386492 0.275219 -0.886818 -0.210116
1.20696 0.0987463 -1.22906 -0.155326 1.27177
-1.25504 0.650159 -0.864291 -0.915809
0.207192 -0.544278 -1.79930 0.0309544 -0.609460
-0.348675 -0.199986 0.518268 -1.03154
1.35320 1.08140 -0.00415816 -0.822823 -0.570877
-1.01163 -1.01084 1.87093 -1.31978
-0.486999 0.565098 0.140825 0.0224620 0.851600
0.922738 -0.779988 0.251917 0.834798
-1.06734 1.14913 -0.539062 -0.584468 -0.426683
0.869110 0.384573 1.50669 0.350647
0.478418 0.458704 1.72066 1.48684 -0.250672
0.920115 -0.324874 -1.49407 -0.0624892
IDL> print,c.mins
-1.81190 -1.79930 -1.06734
-1.42229 -1.25504 -0.584468
-1.51570 -1.31978 -1.49407
IDL> print,c.maxs
0.286660 1.35320 1.72066
1.59126 1.27177 1.48684
0.275219 1.87093 1.50669
IDL> print,c.minind
1 14 21
82 92 102
166 179 187
IDL> print,c.maxind
5 15 26
84 91 105
168 178 184

Hope, it works for you :) Maybe there are some unnecessary
computations, so you might optimize the code...

Cheers

CR
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: XYOUTS: Variable is undefined: Conversion destination variable.
Next Topic: current directory changes unexpectedly

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

Current Time: Fri Oct 10 11:49:45 PDT 2025

Total time taken to generate the page: 1.60297 seconds