umagon
Newbie level 3
[MATLAB] Does anyone can explain this code, color ball tracking
Does anyone can explain this code, i am doing a project regrading to color ball tracking with MATLAB image processing toolbox
im=getingdata(vid,1);
imshow(im);
default=0;
%Image converted to ycbcr format from rgb since this format separates
%intensity from color
im_new=rgb2ycbcr(im);
sz=size(im_new);
m=sz(1,1);
n=sz(1,2);
%Creating a binary matrix binred. Value of an element is 1 only if color is
%red for that position
binred=zeros(m,n);
%num is number of pixels
num=0;
%Center of red object initialized to (I,J)=(0,0)
I=0;J=0;
output='n'; %default output n:No steering, DC motor OFF
for i=1:m
for j=1:n
%IF statement decides if pixel is only red (& not other color)
if(im_new(i,j,3)>180 && im_new(i,j,2)<140 )
%RGB sequence
binred(i,j)=1; num=num+1;
I=I+i;
J=J+j;
end
end
end
i dont quite understand this line if(im_new(i,j,3)>180 && im_new(i,j,2)<140 )
anyone??? thanks in advance
Does anyone can explain this code, i am doing a project regrading to color ball tracking with MATLAB image processing toolbox
im=getingdata(vid,1);
imshow(im);
default=0;
%Image converted to ycbcr format from rgb since this format separates
%intensity from color
im_new=rgb2ycbcr(im);
sz=size(im_new);
m=sz(1,1);
n=sz(1,2);
%Creating a binary matrix binred. Value of an element is 1 only if color is
%red for that position
binred=zeros(m,n);
%num is number of pixels
num=0;
%Center of red object initialized to (I,J)=(0,0)
I=0;J=0;
output='n'; %default output n:No steering, DC motor OFF
for i=1:m
for j=1:n
%IF statement decides if pixel is only red (& not other color)
if(im_new(i,j,3)>180 && im_new(i,j,2)<140 )
%RGB sequence
binred(i,j)=1; num=num+1;
I=I+i;
J=J+j;
end
end
end
i dont quite understand this line if(im_new(i,j,3)>180 && im_new(i,j,2)<140 )
anyone??? thanks in advance