# 3D matrix to Video

조회 수: 98(최근 30일)
Andrew Chen 2017년 2월 24일
댓글: Guangxu Li 2020년 5월 9일
Hello all, I have been having a lot of trouble trying to export a video from Matlab from a 3D matrix. The matrix dimensions indicate frame height, width and frame number. The element values are what is being used to form images with commands such as imagesc or imshow. I can create a video in Matlab by putting the imshow or imagesc command in a for loop but I want to extract something equivalent from Matlab to put in youtube or imbed in a powerpoint or soemthing. Here's an example of the situation:
IM % an mxnxz matrix
for i = 1:size(IM,3);
imshow(IM(:,:,i))
pause(.001);
end
Since the matrix has no color information after processing I have run into problems using WriteVideo or im2frame command. Thanks for any help.

댓글을 달려면 로그인하십시오.

### 채택된 답변

Stephen23 2017년 2월 24일
편집: Stephen23 2017년 2월 24일
It is easy to use getframe and videoWriter object. Here is an example from the videoWriter object help:
v = VideoWriter('peaks.avi');
open(v);
Generate initial data and set axes and figure properties.
Z = peaks;
surf(Z);
axis tight manual
set(gca,'nextplot','replacechildren');
Create a set of frames and write each frame to the file.
for k = 1:20
surf(sin(2*pi*k/20)*Z,Z)
frame = getframe;
writeVideo(v,frame);
end
close(v);
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
Andrew Chen 2017년 2월 24일
Thanks! It worked!

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

Guangxu Li 2020년 3월 9일
편집: Guangxu Li 2020년 5월 9일
Video to 3D image (single channel)
filename="./*.avi";
mImage=obj.Width;
nImage=obj.Height;
frames = obj.NumberOfFrames;
Image3D=zeros(nImage,mImage,frames,'uint8');
for x = 1 : frames
Image3D(:,:,x)=vid(:,:,1,x);
end
niftiwrite(Image3D,filename);
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Guangxu Li 2020년 5월 9일
Dear Bahmanabasdi,
I am very sorry. Please ignore the rotation and flipud lines. That is for my case.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Audio and Video in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by