[Project] Based on matlab binarization parking lot vehicle count [including Matlab source code 628]

1. Introduction

Based on matlab binarization parking lot vehicle counting

Second, the source code

clc;
clear all
I=imread('C:\Users\lenovo\Desktop\新建文件夹\2.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)

Three, running results

Insert picture description here

Four, remarks

Complete code or write on behalf of adding QQ 1564658423

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/115220896