Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Does anyone can explain this code, i am doing a project regrading to color ball track

Status
Not open for further replies.

umagon

Newbie level 3
Joined
Sep 23, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
[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
 

cb=140;
cr=180;

for i=1:256
for j=1:256
for y=1:256
im(i,j,3)=uint8(cr);
im(i,j,2)=uint8(cb);
im(i,j,1)=uint8(y);
end
end
end

imshow(im);


Run this program...The colour output you get is the one which is to be traced as I get from this program.
 
  • Like
Reactions: umagon

    umagon

    Points: 2
    Helpful Answer Positive Rating
cb=140;
cr=180;

for i=1:256
for j=1:256
for y=1:256
im(i,j,3)=uint8(cr);
im(i,j,2)=uint8(cb);
im(i,j,1)=uint8(y);
end
end
end

imshow(im);


Run this program...The colour output you get is the one which is to be traced as I get from this program.

i see, so the meaning of this does not show the range of the color? bcoz if no threshold the program only recognize this color as "red"
 

i see, so the meaning of this does not show the range of the color? bcoz if no threshold the program only recognize this color as "red"


Thats what I suppose so. I guess this might be a program for a line follower or something similar to that as becoz I se a output which is going to a DC motor(may be a differential motor such that the detection may follow a red colour line. Although I am not sure.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top