%% image2YUV
% Reads RGB images from a directory and coverts them in YUV ($:2:0) format

numImges = 100;
inputFileName = 'C:\ftp3DVSequences\cam10\Cam10_Frame_000';
imageType = '.png';

outputVideoName = 'C:\ftp3DVSequences\cam10\BookArrival_c_10_1024x768.yuv';

fidMC = fopen(outputVideoName, 'w');
if fidMC < 0
    error('File is not created.');
end

strlen = numel(inputFileName);

for i=0:numImges-1
    len = numel(num2str(i));
    fn = strcat(inputFileName(1:(strlen-len)), num2str(i), imageType);
    img = imread(fn);
    [ Y, U, V ] = rgb2yuv(img(:,:,1), img(:,:,2), img(:,:,3), 'YUV420_8');  
    
    fwrite(fidMC, Y', 'uint8');
    fwrite(fidMC, U', 'uint8');
    fwrite(fidMC, V', 'uint8'); 
    display(sprintf('Frame %d/%d', i, numImges));
end

fclose('all');
