In order to use the VideoWriter to create an uncompressed AVI in grayscale, you need to create a VideoWriter object with the profile set to 'Uncompressed AVI'. Then create a movie structure that has grayscale frames by using the RGB2GRAY function and use the WRITEVIDEO function to write the frames in the movie to the AVI file. Then close the VideoWriter object using the CLOSE function.
Please refer to the following sample code:
xyloObj = VideoReader('xylophone.mpg');
nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;
map = [(0:255)' (0:255)' (0:255)']/255;
mov(1:nFrames) = struct('cdata', zeros(vidHeight, vidWidth, 'uint8'),'colormap', map);
for k = 1 : nFrames
mov(k).cdata = rgb2gray(read(xyloObj, k));
end
vidObj = VideoWriter('videowrite.avi','Uncompressed AVI');
open(vidObj);
writeVideo(vidObj, mov);
close(vidObj);
Best Answer