Reputation: 341
I have 20 grayscale images of type uint8
stored in a 1x20 cell array named flow8
. I want to generate a movie from them. My current approach is:
% Generate images.
for i = 1:20
flow8{i} = round(rand(100, 100)*255+1);
end
% Get into 4-D shape.
n = size(flow8,2);
matSize = size(flow8,1);
imageStack = reshape(cell2mat(flow8),matSize,[],n);
imageStack = permute(imageStack, [1 2 4 3]);
% Create movie.
mov = immovie(imageStack, gray)
implay(mov)
Here, I have added an image generation loop to make the code compilable.
With this code, the generated movie consists of only one horizontal line.
What do I need to do to get a proper movie? Or is there a better way to make a movie from my images?
I am using MATLAB R2015b academic on Windows 7.
Upvotes: 2
Views: 390
Reputation: 65430
If you look closely at your code, flow8
is 1 x 20
. When you do your reshaping, you compute matSize
with:
matSize = size(flow8, 1)
Well, that value is 1
, because as we said the shape of the cell array is 1 x 20
.
Instead, you likely wanted the size of each image. In which case, you'll want to index into the cell array to get the value and then take the size of that.
matSize = size(flow8{1});
Potentially another (much shorter) way to do this though, it so use cat
to concatenate along the 4th dimension. Then you avoid all of the reshape
and permute
manipulations.
imageStack = cat(4, flow8{:});
Upvotes: 1