Converting TIFF cell array sequence to video

7 次查看(过去 30 天)
I am trying to take a multipage tiff file and convert it to video, I'm not proficient in Matlab at all. I'm using code that I found on a tutorial for converting multipage tiff images into seperate viewable images. The code is as follows:
fname = 'vid.tiff';
info = imfinfo(fname);
num_images = numel(info);
for k = 1:num_images
A(:,:,k) = imread(fname, k, 'Info', info);
end
mplay(A);
I originally had the imread saving to a cell array, but that didn't work with mplay, so I changed it to a matrix. It seems to work as it runs a video of the right number of frames after I run the script, but the video that plays is only black images. I know the images have information in them because I can view each of them seperately. I'm honestly not even sure what this code does, I just know that it seems to work up until the video output.

回答(1 个)

Mann Baidi
Mann Baidi 2024-4-30
编辑:Mann Baidi 2024-4-30
I am assuming you would like to convert a multilayer tiff file to a video and play using the mplay function.
I would sugget you to use the 'VideoWriter' object to create a video object and then can add the frames using the 'writeVideo' function.
You can take help of the following code as a reference.
v = VideoWriter('newfile.avi','Uncompressed AVI'); % Creating a video format of .avi format
tiff_file= 'this.tif';
tiffInfo = imfinfo(tiff_file);
numFrames=numel(tiffInfo); % Number of frames in the tiff file
open(v);
for k=1:numFrames
x=imread(tiff_file,k); % Reading the tiff file frame-by-frame
v.writeVideo(x); % Add the frame in the video
end
close(v);
implay('newfile.avi')
You can know more about the 'VideoWriter' object using the documentation link mentioned below:
I am hoping that I helped you in resloing your issue!

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by