MATLAB: How to change movie to gray (frame by frame)

frameImage Processing ToolboxMATLABrgb2grayvideoreader

I know there are probably easier methods but it must be frame by frame
this is what I have:
movi = VideoReader('xylophone.mpg');
nFrames = movi.NumberOfFrames;
vidHeight = movi.Height;
vidWidth = movi.Width;
mov(1:nFrames) = … struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),… 'colormap', []);
for k = 1 : nFrames
poj_ramka=mov(k).cdata;
funkcja=zad(poj_ramka);
kraw=uint8(funkcja)*255;
kraw=cat(3,kraw,kraw,kraw);
mov(k)=struct('cdata',kraw,'colormap',[]);
end
okno=figure;
set(okno,'position',[150 150 vidWidth vidHeight]);
movie(okno,mov,1,25);
and zad.m file:
function[obraz]=zad(poj_ramka)
obraz=rgb2gray(poj_ramka);
end
what i get is a black window :/

Best Answer

Why not just use rgb2gray() and im2frame():
kraw = rgb2gray(poj_ramka);
mov(k)= im2frame(kraw);
Related Question