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

Home » Public Forums » archive » Fast way to collapse data cube with median
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
Fast way to collapse data cube with median [message #85133] Tue, 09 July 2013 09:08 Go to next message
stefan.meingast is currently offline  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 #85135 is a reply to message #85133] Tue, 09 July 2013 09:22 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Stefan writes:

> 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.

medianValuesOfArray = Median(cube, DIMENSION=3)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Fast way to collapse data cube with median [message #85136 is a reply to message #85133] Tue, 09 July 2013 09:28 Go to previous messageGo to next message
Michael Galloy is currently offline  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 #85138 is a reply to message #85133] Tue, 09 July 2013 10:42 Go to previous messageGo to next message
stefan.meingast is currently offline  stefan.meingast
Messages: 30
Registered: June 2012
Member
Great, I forgot about this keyword. :)

Unfortunately its only 3% faster compared to my method...hmm

cheers and thanks a lot!!!
Re: Fast way to collapse data cube with median [message #85139 is a reply to message #85138] Tue, 09 July 2013 10:44 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Stefan writes:

> Unfortunately its only 3% faster compared to my method...hmm

Maybe you will have to reorganize your data array. TRANSPOSE can do this
for you.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Fast way to collapse data cube with median [message #85141 is a reply to message #85133] Tue, 09 July 2013 12:14 Go to previous message
stefan.meingast is currently offline  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!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Peak detection
Next Topic: CURVEFIT function

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

Current Time: Wed Oct 08 13:33:31 PDT 2025

Total time taken to generate the page: 0.00554 seconds