The errors happened in different version of matlab on the same code

1 次查看(过去 30 天)
As I posed before, http://www.mathworks.com/matlabcentral/answers/37417-how-to-get-the-value-of-a-certain-pixel-region-in-video-and-analyze-them runs well in matlab version R2009a.However, it goes wrong in version R2010. What was the problem? Thank you very much.
ps: original code is
%read the video
avi = aviread('sample.avi');
video = {avi.cdata};
pixels = double(cat(4,video{1:end}))/255;
nFrames = size(pixels,4)
%convert the video to gray scale
for f = 1:nFrames
pixel(:,:,f) = (rgb2gray(pixels(:,:,:,f)));
end
background=(pixel(:,:,1)+pixel(:,:,2)+pixel(:,:,3))/3; %get a background picture
%transfer the video to binary video and counting
for m = 2:1:nFrames
dif=(abs(pixel(:,:,m)-background));
bw = im2bw(dif, 0.2);
if (0==any(bw(:,314))) && (0~=any(bw(:,313)))
n=n+1;
disp(n)
end
end

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by