Demo entry 6357970

1

   

Submitted by 1 on Apr 24, 2017 at 10:51
Language: Matlab. Code size: 1.8 kB.

load RGB.txt
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)>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
%X轴特征块中心点
[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)>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轴特征块中心点
[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);
%连接顶点
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.

Delete this entry (admin only).