Effacer les filtres
Effacer les filtres

how to get the value of a certain pixel-region in video and analyze them?

1 vue (au cours des 30 derniers jours)
I have a video of pills moving from left to right slowly. I want to draw a visual line in the original video and when the pills get through that line, the program automatically increase the pills-number by one, namely, n=n+1.
here is my code:
%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 l = 2:1:nFrames
dif(:,:,l)=(abs(pixel(:,:,l)-background));
bw(:,:,l) = im2bw(dif(:,:,l), 0.2);
**if (0==any(bw(:,314,l))) && (0~=any(bw(:,313,l)))
n=n+1;
disp(n)
end**
end
however I don't know why the condition "if (0==any(bw(:,314,l))) && (0~=any(bw(:,313,l)))" never get satisfied and the displayed "n" hence equals 0. I am badly in need of help. Thanks all of you.

Réponse acceptée

Image Analyst
Image Analyst le 4 Mai 2012
Reread the help on any for how it handles 2D matrices. Then try something like this:
dif = abs(double(pixel(:,:,l))-background);
bw = im2bw(dif, 0.2);
if any(any(bw(:,314))) && ~any(any(bw(:,313)))
No need to have dif and bw be a 3D matrix depending on l (which is a bad choice for a variable name since "ell" looks like 1 ("one"). I'm still not sure about the "pixel" variable but I don't have time to look into it now.
  1 commentaire
Stephen
Stephen le 4 Mai 2012
Thank you for your kind reply. In this program, I define "pixel" as the conversion result of the RGB video to gray video.Namely, the matrix of the gray video.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by