Demo entry 6357405

1

Submitted by 1 on Apr 22, 2017 at 04:43
Language: Matlab. Code size: 1.7 kB.

```Y=imread('0.jpg');
imshow(Y);
R=Y(:,:,1);
G=Y(:,:,2);
B=Y(:,:,3);
[m,n]=size(R);
for i=1:m
for j=1:n
if (R(i,j)>40&&R(i,j)<70)&&(G(i,j)>40&&G(i,j)<70)&&(B(i,j)>40&&B(i,j)<70)
black(i,j)=1;
else
black(i,j)=0;
end
end
end

%红色色块中心点
[y_r,x_r]=find(black==1);
B_r=[x_r,y_r];
[y1_r,I_r] = max(B_r(:,2));
x1_r=B_r(I_r,1);
[y2_r,S_r] = min(B_r(:,2));
x2_r=B_r(S_r,1);
[x3_r,M_r] = min(B_r(:,1));
y3_r=B_r(M_r,2);
[x4_r,N_r] = max(B_r(:,1));
y4_r=B_r(N_r,2);
x0_r=((x1_r+x2_r+x3_r+x4_r)/4);
y0_r=((y1_r+y2_r+y3_r+y4_r)/4);

for i=1:m
for j=1:n
if (R(i,j)>205&&R(i,j)<220)&&(G(i,j)>170&&G(i,j)<180)&&(B(i,j)>90&&B(i,j)<110)
yellow(i,j)=1;
else
yellow(i,j)=0;
end
end
end

%绿色色块中心点
[y_g,x_g]=find(yellow==1);
B_g=[x_g,y_g];
[y1_g,I_g] = max(B_g(:,2));
x1_g=B_g(I_g,1);
[y2_g,S_g] = min(B_g(:,2));
x2_g=B_g(S_g,1);
[x3_g,M_g] = min(B_g(:,1));
y3_g=B_g(M_g,2);
[x4_g,N_g] = max(B_g(:,1));
y4_g=B_g(N_g,2);
x0_g=((x1_g+x2_g+x3_g+x4_g)/4);
y0_g=((y1_g+y2_g+y3_g+y4_g)/4);

for i=1:m
for j=1:n
if (R(i,j)>50&&R(i,j)<80)&&(G(i,j)>105&&G(i,j)<130)&&(B(i,j)>156&&B(i,j)<180)
blue(i,j)=1;
else
blue(i,j)=0;
end
end
end

[y_b,x_b]=find(blue==1);
B_b=[x_b,y_b];
[y1_b,I_b] = max(B_b(:,2));
x1_b=B_b(I_b,1);
[y2_b,S_b] = min(B_b(:,2));
x2_b=B_b(S_b,1);
[x3_b,M_b] = min(B_b(:,1));
y3_b=B_b(M_b,2);
[x4_b,N_b] = max(B_b(:,1));
y4_b=B_b(N_b,2);
x0_b=((x1_b+x2_b+x3_b+x4_b)/4);
y0_b=((y1_b+y2_b+y3_b+y4_b)/4);

%连接顶点
hold on;
line([x0_r,x0_g],[y0_r,y0_g]);
hold on;
line([x0_r,x0_b],[y0_r,y0_b]);
```

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.