MATLAB Answers

Errror using imwrite, can't use "append" in 'WriteMode'

조회 수: 16(최근 30일)
Hey there! I'm trying to use to convert a video ( .avi file) to a .tif STACK but unfortunately the code just converts it to a set of .tif images despite using 'WriteMode' and "append". Is there any other way to achieve in MATLAB ( if I'm not wrong ImageJ has this functionality)
Here's the code, it's similar to that of Joe's written a year ago.
%% To convert avi files to tif images
obj = VideoReader('video.avi');
vid = read(obj);
frames = obj.NumberOfFrames;
% This just converts them to a set of images
% for x = 1 : frames
% imwrite(vid(:,:,:,x),strcat('frame-',num2str(x),'.tif'));
% end
%This is meant to amend that and to make a .tif stack
for x = 1 : frames
imwrite(vid(:,:,:,x),strcat('frame-',num2str(x),'.tif'), 'Compression', 'none','WriteMode', "append");
end

  댓글 수: 0

로그인 to comment.

채택된 답변

Alex Mcaulley
Alex Mcaulley 5 Sep 2019
편집: Alex Mcaulley 5 Sep 2019
You are changing the file name for each frame, resulting in different tif images. To build a tif stack you just need to use ONE unique file name:
%% To convert avi files to tif images
obj = VideoReader('video.avi');
vid = read(obj);
frames = obj.NumberOfFrames;
% This just converts them to a set of images
% for x = 1 : frames
% imwrite(vid(:,:,:,x),strcat('frame-',num2str(x),'.tif'));
% end
%This is meant to amend that and to make a .tif stack
for x = 1 : frames
imwrite(vid(:,:,:,x),'myimage.tif', 'Compression', 'none','WriteMode', 'append');
end

  댓글 수: 1

Sai Sirish Gokavarapu
Thanks Alex, I guess I overlooked it while modifying my code from previous version. :) It works now

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by