How to find second minimum and maximum in 3D array? [message #90353] |
Wed, 25 February 2015 12:01  |
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   |
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  |
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
|
|
|