fmov = aviread('coastguard.avi'); %read the AVI file



for k=1:300

tdata = fmov(1,k).cdata; %indexed
tmap = fmov(1,k).colormap;


tt3 = ind2gray(tdata, tmap);
%image(tt3);
tt = tt3(:,:,1);
tt = double(tt);
%figure
%imshow(tt)
imwrite(tt, ['coastguard_' num2str(k) '.jpeg'])

end