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

22 views (last 30 days)
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 Comments
Joe Sheppard
Joe Sheppard on 4 Apr 2018
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

Sign in to comment.

Answers (1)

Mann Baidi
Mann Baidi on 4 Apr 2024
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!

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!