# Demo entry 6358384

11

Submitted by 1 on Apr 25, 2017 at 08:29
Language: Matlab. Code size: 2.8 kB.

```load RGB.txt
imshow(Y);
R=Y(:,:,1);
G=Y(:,:,2);
B=Y(:,:,3);
[m,n]=size(R);
%X轴特征块中心点
for i=1:m
for j=1:n
if (R(i,j)>=RGB(1,1)&&R(i,j)<=RGB(1,2)&&(G(i,j)>=RGB(2,1)&&G(i,j)<=RGB(2,2))&&(B(i,j)>=RGB(3,1)&&B(i,j)<=RGB(3,2)))
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);
%Y轴特征块中心点
for i=1:m
for j=1:n
if (R(i,j)>=RGB(4,1)&&R(i,j)<=RGB(4,2))&&(G(i,j)>=RGB(5,1)&&G(i,j)<=RGB(5,2))&&(B(i,j)>=RGB(6,1)&&B(i,j)<=RGB(6,2))
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)>=RGB(7,1)&&R(i,j)<=RGB(7,2))&&(G(i,j)>=RGB(8,1)&&G(i,j)<=RGB(8,2))&&(B(i,j)>=RGB(9,1)&&B(i,j)<=RGB(9,2))
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);
%备用点特征块
for i=1:m
for j=1:n
if (R(i,j)>=RGB(4,1)&&R(i,j)<=RGB(4,2))&&(G(i,j)>=RGB(5,1)&&G(i,j)<=RGB(5,2))&&(B(i,j)>=RGB(6,1)&&B(i,j)<=RGB(6,2))
yellow(i,j)=1;
else
yellow(i,j)=0;
end
end
end
[y_s,x_s]=find(yellow==1);
B_s=[x_s,y_s];
[y1_s,I_s] = max(B_s(:,2));
x1_s=B_s(I_s,1);
[y2_s,S_s] = min(B_s(:,2));
x2_s=B_s(S_s,1);
[x3_s,M_s] = min(B_s(:,1));
y3_s=B_s(M_s,2);
[x4_s,N_s] = max(B_s(:,1));
y4_s=B_s(N_s,2);
x0_s=((x1_s+x2_s+x3_s+x4_s)/4);
y0_s=((y1_s+y2_s+y3_s+y4_s)/4);
%Y轴中心点坐标（x_g,y_g)
%X轴中心点坐标（x_r,y_r)
%原点中心点坐标（x_b,y_b)
%备用点中心坐标（x_s,y_s)
%Y轴特征块不可见
if all(yellow(:)==0)
x0_g=x0_b-x0_r+x0_s;
y0_g=y0_b-y0_r+y0_s;
else
end
%X轴特征块不可见
if all(black(:)==0)
x0_r=x0_b-x0_g+x0_s;
y0_r=y0_b-y0_g+y0_s;
else
end
%原点特征块不可见
if all(blue(:)==0)
x0_b=x0_r-x0_s+x0_g;
y0_b=y0_r-y0_s+y0_g;
else
end
%连接顶点
hold on;
line([x0_b,x0_g],[y0_b,y0_g]);
hold on;
line([x0_b,x0_r],[y0_b,y0_r]);
```

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.