# How to construct a video object for display by ImageView.imshow()

**URL:** <https://discourse.julialang.org/t/how-to-construct-a-video-object-for-display-by-imageview-imshow/27323>\
**Category:** Visualization\
**Created:** [August 8, 2019, 6:14pm UTC](https://discourse.julialang.org/t/how-to-construct-a-video-object-for-display-by-imageview-imshow/27323 "2019-08-08T18:14:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgf314](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@tgf314](https://discourse.julialang.org/u/tgf314)\
**Post date:** [August 8, 2019, 6:14pm UTC](https://discourse.julialang.org/t/how-to-construct-a-video-object-for-display-by-imageview-imshow/27323/1 "2019-08-08T18:14:54Z")

</div>

imshow() is described as being able to display a video. The example in the documentation is testimage(“mri”). The type of this object is:

`AxisArray{Gray{Normed{UInt8,8}},3,Array{Gray{Normed{UInt8,8}},3},Tuple{AxisArrays.Axis{:P,StepRange{Int64,Int64}},AxisArrays.Axis{:R,StepRange{Int64,Int64}},AxisArrays.Axis{:S,StepRange{Int64,Int64}}}}

As a julia beginner it’s rather difficult for me to parse this type information and infer the correct process for constructing my own video of the correct type.

The (short) video I have is loaded from a file using VideoIO like this:

```julia
f = VideoIO.openvideo( VIDEO )
video = []
framecount = 0
while !eof( f )
    global framecount
    global video
    frame = read( f )
    push!( video, frame )
    framecount += 1
end

```

I want to work with it as a single in memory object which (among many other things) I would like to be able to display as a video and maybe step through the frames.

Of course the simple array I’m using is not the AxisArray expected by imshow so how can I get my data into the correct structure ?

---

<div class="post-metadata">

**Author:** ![tgf314](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@tgf314](https://discourse.julialang.org/u/tgf314)\
**Post date:** [August 9, 2019, 12:00am UTC](https://discourse.julialang.org/t/how-to-construct-a-video-object-for-display-by-imageview-imshow/27323/2 "2019-08-09T00:00:26Z")

</div>

Answering my own question in case anyone else encounters the same problem.

The following code does the job:

```julia
function loadvideo( filename )
    f = VideoIO.openvideo( filename )
    framecount = 0
    frames = []
    while !eof( f )
        frame = read( f )
        push!( frames, frame )
        framecount += 1
    end
 
    video = Array{ eltype( frames[1] ) }( undef, 
                                          size( frames[1] )[1], 
                                          size( frames[1] )[2], 
                                          length( frames ) )    
    for i = 1:length( frames )
        video[:, :, i] = frames[i]
    end
    return video
end

```

This is inefficient because it loads the frames into a simple array first but when I tried constructing the multidimensional array on the fly with cat the performance was terrible and actually required me to kill the julia process.
