Hi,
I am trying to post-process matrix of frames I get from a camera. Each frame is outputted as a.mat file with a "Frame" variable that is a 512x640 double. I want to import all of these files for each frame, I have 2497 frames so 2497 files, and create a 3D matrix that is 512x640x2497 with all the frames. I currently import the frames but it creates a 1x2497 strucutre with each field being a 512x640 double. Is it possible to convert this structure to a 3D matrix or import the data straight into a 3D matrix?
Thank you
This is my code so far:
for k = 0:2497
filename = sprintf('Rec--000013_%d.mat', k);
%Checking File Exists
if isfile(filename)
all_frames(k+1) = load(filename,'Frame');
else
fprintf('File %s does not exist.\n', filename);
end
fprintf('Now Reading File : Rec--000013_%d.mat\n', k)
end

 Respuesta aceptada

Matt J
Matt J el 24 de Nov. de 2021
Matrix=cat(3, all_frames.Frame);
However, you will need generous RAM. Your all_frames structure already consumes about 5 GB in double flating point, and this will consume another 5 GB.

3 comentarios

Hi Matt,
Thank you so much for this. It works perfectly. My goal is to get these frames playing as a video. I intended on converting each index into an image and getting the images to play at 10 fps but I am not managing. Do you have any sugegstion on how to approach this?
This is my current solution:
frames_matrix = cat(3, all_frames.Frame);
%Converts Matrix into Images
for i = 1:2497
images(k) = image(frames_matrix(k));
end
%Create the Video Writer With 10 FPS
writerObj = VideoWriter('13.avi');
writerObj.FrameRate = 10;
%Open the Video Writer
open(writerObj);
%Write the Frames to the Video
for u=1:2498
%Convert the Image to a Video Frame
frame = im2frame(images(u));
writeVideo(writerObj, frame);
end
%Close the Writer Object
close(writerObj);
implay('13.avi');
Matt J
Matt J el 26 de Nov. de 2021
Since you Accept-clicked the answer, I assume you figured it out?
Afonso Espírito Santo
Afonso Espírito Santo el 27 de Nov. de 2021
Hi Matt,
The original issue was solved.However, I have not figured out how to answer the question I asked in the comment. Should I open a new questions for that specifically?
Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Read, Write, and Modify Image en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by