How can I convert multiple individual .tif files to a single .tif stack

23 次查看(过去 30 天)
I am currently writing some code to convert each frame of a .avi file to a .tif file, but I would also like to store the resulting frames as a single file, i.e. a tif stack.
The imwrite feature 'WriteMode', 'append' is not working (and also not giving an error).
Below is the segment of code:
obj = VideoReader(currAVI); vid = read(obj); frames = obj.NumberOfFrames; mkdir(nameString); writeFolder = strcat(currFolder,'\', nameString); cd(writeFolder);
for x = 1 : frames
imwrite(vid(:,:,:,x),strcat('frame-',num2str(x),'.tif'), 'Compression', 'none', 'WriteMode', 'append');
end
  2 个评论
Joe Sheppard
Joe Sheppard 2018-4-4
I ended up writing the first frame to tiff outside the loop and then selecting 'overwrite' and 'append' within the loop and that got it to work.
I really don't know why the usual WriteMode' 'append' name pair argument didn't work, but hey a fix is a fix.
Thanks for your suggestion in any case

请先登录,再进行评论。

回答(1 个)

Mann Baidi
Mann Baidi 2024-4-4
Hi Joe,
Asumming you would like to store the frames of your .avi file in a single single stack of .tif file, but your facing issues in executing the same.
This is because you are using different filename (strcat('frame-',num2str(x),'.tif')) for each of the file in your 'imwrite' command.
imwrite(vid(:,:,:,x),strcat('frame-',num2str(x),'.tif'), 'Compression', 'none', 'WriteMode', 'append');
I would suggest you to use only one name for all the frames instead of multiple names.
You can try replacing the above line of code with the following line:
imwrite(vid(:,:,:,x),'sample.tif', 'Compression', 'none','WriteMode', "append");
I hope this will help in reslolving your quries!

类别

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