0

I am trying to create a movie in Matlab using series of functions under VideoWriter function. My code is somewhat like one shown below:

vidObj=VideoWriter('movie.avi');
open(vidObj);

for i=1:N %N is number of frames

[nx,ny]=coordinates(Lx,Ly,Nx,Ny,[x(i),-y(i)]);
%Lx and Ly refer to the length and height in meters. 
%Nx and Ny are number of pixels (boxes) and fit into the respective L's. 
%If Lx=10e-6 , with Nx=5, there will be 5 pixels in x dimension,
%each of length 2e-6 m.
[xf,yf]=ndgrid(nx,ny);
zf=zeros(size(xf))+z(i);    

% generate a frame here
[E,H]=nfmie(an,bn,xf,yf,zf,rad,ns,nm,lambda,tf_flag,cc_flag);
Ecc=sqrt(real(E(:,:,1)).^2+real(E(:,:,2)).^2+real(E(:,:,3)).^2+imag(E(:,:,1)).^2+imag(E(:,:,2)).^2+imag(E(:,:,3)).^2);
clf
imagesc(nx/rad,ny/rad,Ecc)
rectangle('Position',[-rad(end),-rad(end),dia(end),dia(end)],'Curvature',[1,1]);
axis image;
axis off;
currFrame=getframe(gcf);
writeVideo(vidObj,currFrame);
end
close(vidObj);
toc
return

This generated a movie called movie.avi. However, the movie (and the tif images generated from command window) has the dimensions of "420x560x3". I don't understand how it got here. Please help!! And thank you in advance.

1 Answers1

0

Each frame of your video has 420 by 560 pixels, each pixel has an RGB value, which is stored as 3 numbers. For example:

CurrFrame(120, 300) = [0 0 0]

Would make the 120th by 300th pixel white. And:

CurrFrame(120, 300) = [1 0 0]

Would make the same pixel bright red.

The dimensions you're getting are the dimensions of a single frame, or an image.

Justin Fletcher
  • 2,319
  • 2
  • 17
  • 32
  • Thank you for the reply. It was really helpful. However, I hope you don't mind answering another question here. I need to convert this 420x560x3 tif file into a 2D tif (or jpeg)file, for further image processing, how would I do so? Thank you again I am assuming that it would give me a 420x560. Could you help me out with that? – Nitsorn Wongsajjathiti Jun 03 '14 at 22:31
  • If you mean you want to save it as a file: `imwrite(CurrFrame, 'filename.tif', 'tif')` Else, I'm not exactly sure what you want to do. The image isn't actually "3D," so there isn't any conversion needed. – Justin Fletcher Jun 03 '14 at 22:46
  • Also, you could take some time and formulate the exact question you want to ask, and ask it as a separate question. I'll answer it. – Justin Fletcher Jun 03 '14 at 22:47
  • Thanks @Fletch . Here is my question: http://stackoverflow.com/questions/24029187/dimension-of-a-tif-file-as-420x560x3-matlab-to-idl – Nitsorn Wongsajjathiti Jun 04 '14 at 04:45