赞
踩
- clc;
- clear all
- I=imread('D:/作业1.png');
- G=rgb2gray(I);
- % G=histeq(G);
- H=imhist(G);
- % bar(H);
- [a,b]=size(G);
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%提取白车
- G=G-100;
- for i=1:1:a
-
- for j=1:1:b
-
- if G(i,j)>=25
-
- G2(i,j)=1;
-
- else
-
- G2(i,j)=0;
-
- end
- end
- end
- se1=strel('square',10);
- G4=imdilate(G2,se1);
- se1=strel('square',15);
- G4=imerode(G4,se1);
- XX=bwlabel(G4,8);
- white=max(max(XX))/2%%%%%%%%%%%%%两个点为1个白车
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%提取黑车
- G=rgb2gray(I);
- G=G+100;
- [a,b]=size(G);
- for i=1:1:a
-
- for j=1:1:b
-
- if G(i,j)<=150
-
- G1(i,j)=1;
-
- else
-
- G1(i,j)=0;
-
- end
- end
- end
- se1=strel('square',20);%20
- G4=imerode(G1,se1);
- se1=strel('square',35); %35
- G5=imdilate(G4,se1);
- XX1=bwlabel(G5,8);
- black=max(max(XX1))-2%%%%%%%%%%%%%%减去两个背景
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%提取棕车
- G=rgb2gray(I);
- [a,b]=size(G);
- for i=1:1:a
-
- for j=1:1:b
-
- if G(i,j)<=100&&G(i,j)>=70
-
- G1(i,j)=1;
-
- else
-
- G1(i,j)=0;
-
- end
- end
- end
- se1=strel('square',30);
- G4=imerode(G1,se1);
- se1=strel('square',30);
- G5=imdilate(G4,se1);
- XX2=bwlabel(G5,8);
- brown=max(max(XX2))-1%%%%%%%%%%%%减去中间背景点
- XX3=XX1+XX2+XX;
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%出图
- subplot 221
- imshow(I)
- subplot 222
- % X1=double(G)-XX*255;
- % imshow(X1/255)
- imshow(XX)
- subplot 223
- imshow(XX1)
- % X2=double(G)-XX1*255;
- % imshow(X2/255)
- % imshow(XX1)
- subplot 224
- % X3=double(G)-XX2*255;
- % imshow(X3/255)
- imshow(XX2)
- sum=white+black+brown
11.5
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。