clc;
close all; % Close all figures
%%
finf = dir(' file path\*.tif'); % *.tif => choose all tif file
n = length(finf);
data = cell(n,1);
len = zeros(n,1);
for k=1:n
filename = [finf(k).name];
data{k} = imread(filename);
%F(k) = im2frame(data{k});
end
%%
%Making movie
writerObj = VideoWriter('movie file path \ file_name.avi');
writerObj.FrameRate = 20;
open(writerObj); %open movie file
for k=1:n
img = rgb2gray(data{k});
% Otsu's method
level = graythresh(img);
otsu = im2bw(img,level);
otsu = im2uint8(otsu);
new_img = [img otsu];
imshow(in_new_img);
title('Otsu method');
% binary to 8-bit integer
mov = im2uint8(in_new_img);
Mov = im2frame(mov);
writeVideo(writerObj,Mov);
end
%%
% save as AVI file
close(writerObj); %file name
----------------------------------------
Official document for VideoWriter
沒有留言:
張貼留言