Clear Filters
Clear Filters

how can I convert Tiff images with different timepoint to Mp4?

8 views (last 30 days)
v = VideoWriter('test_c_file.mp4', 'MPEG-4');
open(v);
for k = 0:100 % assumes 10 images to write to file
%tmp = randi(255, 100, 200, 'uint8');
t = Tiff([folder 'test_27_Hour_00_Minute_00_Second_00_Frame_00; test_27_Hour_00_Minute_00_Second_01_Frame_00; test_27_Hour_00_Minute_00_Second_02_Frame_00; test_27_Hour_00_Minute_00_Second_03_Frame_00; test_27_Hour_00_Minute_00_Second_04_Frame_00; test_27_Hour_00_Minute_00_Second_05_Frame_00' num2str(k) '.tif'], 'r');
tmp = read(t);
writeVideo(v, tmp);
end
close(v);

Answers (1)

Geoff Hayes
Geoff Hayes on 5 May 2022
@Abdallah Almahmoud - are you trying to read multiple TIFF files with
t = Tiff([folder 'test_27_Hour_00_Minute_00_Second_00_Frame_00; test_27_Hour_00_Minute_00_Second_01_Frame_00; test_27_Hour_00_Minute_00_Second_02_Frame_00; test_27_Hour_00_Minute_00_Second_03_Frame_00; test_27_Hour_00_Minute_00_Second_04_Frame_00; test_27_Hour_00_Minute_00_Second_05_Frame_00' num2str(k) '.tif'], 'r');
? If I try something like this, then there is the following error
Error using Tiff (line 653)
Could not open file '\<some folder>\test_27_Hour_00_Minute_00_Second_00_Frame_00;
test_27_Hour_00_Minute_00_Second_01_Frame_00; test_27_Hour_00_Minute_00_Second_02_Frame_00;
test_27_Hour_00_Minute_00_Second_03_Frame_00; test_27_Hour_00_Minute_00_Second_04_Frame_00;
test_27_Hour_00_Minute_00_Second_05_Frame_001.tif'.
I think that you need to iterate over each file instead. Perhaps something like
v = VideoWriter('test_c_file.mp4', 'MPEG-4');
open(v);
images = {'test_27_Hour_00_Minute_00_Second_00_Frame_00'; 'test_27_Hour_00_Minute_00_Second_01_Frame_00'; ...
'test_27_Hour_00_Minute_00_Second_02_Frame_00'; 'test_27_Hour_00_Minute_00_Second_03_Frame_00'; ...
'test_27_Hour_00_Minute_00_Second_04_Frame_00'; 'test_27_Hour_00_Minute_00_Second_05_Frame_00'};
for k = 0:100 % assumes 10 images to write to file
for j = 1:length(images)
t = Tiff(fullfile(folder,[images{j} num2str(k) '.tif']), 'r');
tmp = read(t);
writeVideo(v, tmp);
end
end
close(v);

Categories

Find more on Convert Image Type 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!