Fast way to collapse data cube with median [message #85133] |
Tue, 09 July 2013 09:08  |
stefan.meingast
Messages: 30 Registered: June 2012
|
Member |
|
|
Hey
I am doing a lot of image processing and very often I have a data cube like with the x/y axes corresponding to image coordinates and the z component corresponding to the individual images.
I simply want to calculate the median at each pixel stack and so far I always loop through all pixels and determine the median for each stack. This, of course, can be quite slow for large images since it involves two loops and I was wondering if someone here might have a fancy idea of how to collapse such a cube faster.
thank a lot
:)
|
|
|
|
Re: Fast way to collapse data cube with median [message #85136 is a reply to message #85133] |
Tue, 09 July 2013 09:28   |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 7/9/13 10:08 AM, Stefan wrote:
> Hey
>
> I am doing a lot of image processing and very often I have a data
> cube like with the x/y axes corresponding to image coordinates and
> the z component corresponding to the individual images.
>
> I simply want to calculate the median at each pixel stack and so far
> I always loop through all pixels and determine the median for each
> stack. This, of course, can be quite slow for large images since it
> involves two loops and I was wondering if someone here might have a
> fancy idea of how to collapse such a cube faster.
>
> thank a lot :)
>
Yes, use the DIMENSION keyword to median (dimensions start at 1):
IDL> arr = findgen(2, 3, 4)
IDL> m = median(arr, dimension=2)
IDL> help, m
M FLOAT = Array[2, 4]
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|
|
|
Re: Fast way to collapse data cube with median [message #85141 is a reply to message #85133] |
Tue, 09 July 2013 12:14  |
stefan.meingast
Messages: 30 Registered: June 2012
|
Member |
|
|
Thanks for the tip. You are right, this is faster. One can rearrange the cube and use the dimension=2 keyword (instead of 3). However, when I use TRANSPOSE to rearrange the array, the total time it takes to transpose and collapse the cube is longer than what I had before, so I created the transposed array at the point where I create the cube and skip the call of TRANSPOSE. Now its twice as fast. :)
thanks a lot!
|
|
|