Search code examples
imagevideorgbgrayscaleidl

IDL - Reshape 2D-Array to 3D-Array


In IDL I have an datacube containing (grayscale) images at different times: datacube[w, h, frames]. Now I want to convert that datacube into an animation using IDLFFVideoWrite, but the problem is, the Put-Method only eats frames of the sort frame[3, w, h].

How can I convert a single frame of my datacube into a fitting frame, that IDLffVideoWrite::Put will eat?


Solution

  • You have greyscale images, so we need to make all three bands (R, G, and B) just copies of the one band. REBIN and REFORM are the tools for "juggling dimensions" like that:

    frame = rebin(reform(datacube[*, *, i], 1, w, h), 3, w, h)
    

    As long as datacube is of byte data, frame will be suitable for IDLffVideoWrite::put.

    UPDATE: editing answer because I have limited formatting options in a comment.

    So you actually have a datacube of this form then:

    datacube[w, h, 3 * n_frames]
    

    So you should do this to datacube to make it easier to deal with:

    datacube = transpose(reform(datacube, w, h, 3, n_frames), [2, 0, 1, 3])
    

    Then, to get the ith frame, you can just do:

    frame = reform(datacube[*, *, *, i])