필터 지우기
필터 지우기

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

조회 수: 21 (최근 30일)
Joe Sheppard
Joe Sheppard 2018년 4월 3일
답변: Mann Baidi 2024년 4월 4일
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에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by