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

Home » Public Forums » archive » How to find second minimum and maximum in 3D array?
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
How to find second minimum and maximum in 3D array? [message #90353] Wed, 25 February 2015 12:01 Go to next message
Harald Frey is currently offline  Harald Frey
Messages: 41
Registered: March 1997
Member
I have a time series of ~200 images with dimensions [X,Y]=[400,250]. My data is a UINTARR[200,400,250]. It is very easy to get the minimum and maximum for each pixel X,Y in my time series using

res=min(array,dimension=1,max=max_val)
IDL> help,res,max_val
RES FLOAT = Array[400, 250]
MAX_VAL FLOAT = Array[400, 250]

However, several pixels have 0 value or 65535 value and I want the second minimum and second maximum which are not 0 or 65535. I can do this in a for-loop, but is there a more clever and faster way?

min_array=uintarr(400,250)
max_array=uintarr(400,250)
for x=0,400-1 do begin
for y=0,300-1 do begin
good=where (array[*,x,y] gt 0 and array[*,x,y] lt 65535l)
res=min(array[good,x,y],dimension=1,max=max_val)
min_array[x,y]=res
max_array[x,y]=max_val
endfor
endfor

Thanks,
Harald Frey (UC Berkeley)
Re: How to find second minimum and maximum in 3D array? [message #90355 is a reply to message #90353] Wed, 25 February 2015 13:25 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Wednesday, February 25, 2015 at 3:01:53 PM UTC-5, hf...@ssl.berkeley.edu wrote:
> I have a time series of ~200 images with dimensions [X,Y]=[400,250]. My data is a UINTARR[200,400,250]. It is very easy to get the minimum and maximum for each pixel X,Y in my time series using
>
> res=min(array,dimension=1,max=max_val)
> IDL> help,res,max_val
> RES FLOAT = Array[400, 250]
> MAX_VAL FLOAT = Array[400, 250]
>
> However, several pixels have 0 value or 65535 value and I want the second minimum and second maximum which are not 0 or 65535. I can do this in a for-loop, but is there a more clever and faster way?

You could use WHERE() once to find the pixels that are 0 or 65535, and then set those to NAN. Then you can use min() or max() directly with the /NAN keyword to ignore NAN values.

Craig
Re: How to find second minimum and maximum in 3D array? [message #90357 is a reply to message #90355] Wed, 25 February 2015 13:31 Go to previous message
Harald Frey is currently offline  Harald Frey
Messages: 41
Registered: March 1997
Member
On Wednesday, February 25, 2015 at 1:25:44 PM UTC-8, Craig Markwardt wrote:
> On Wednesday, February 25, 2015 at 3:01:53 PM UTC-5, hf...@ssl.berkeley.edu wrote:
>> I have a time series of ~200 images with dimensions [X,Y]=[400,250]. My data is a UINTARR[200,400,250]. It is very easy to get the minimum and maximum for each pixel X,Y in my time series using
>>
>> res=min(array,dimension=1,max=max_val)
>> IDL> help,res,max_val
>> RES FLOAT = Array[400, 250]
>> MAX_VAL FLOAT = Array[400, 250]
>>
>> However, several pixels have 0 value or 65535 value and I want the second minimum and second maximum which are not 0 or 65535. I can do this in a for-loop, but is there a more clever and faster way?
>
> You could use WHERE() once to find the pixels that are 0 or 65535, and then set those to NAN. Then you can use min() or max() directly with the /NAN keyword to ignore NAN values.
>
> Craig

Perfect! That should really speed thing up.
Thanks a lot!
Harald
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: normal, relative and ellipse
Next Topic: Using Slither with Anaconda

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

Current Time: Wed Oct 08 09:11:44 PDT 2025

Total time taken to generate the page: 0.00402 seconds