I have a license plate identification project by image processing. This is my code. I can not resolve errors.who can help me please
1 回表示 (過去 30 日間)
古いコメントを表示
clc; clear all; close all; tic; a=imread('46.jpg');%lire l'image [m b]= size(a)% dimension figure(1), imshow(a) a=rgb2gray(a);%conversion en niveau de gris %------------------------------%%traitement bruité----------------------------------- %0.49 %a=imnoise(a,'salt & pepper',0.49);bruit salt & pepper %figure (21), imshow(a) %a=imnoise(a,'gaussian',0.35);bruit Gaussienne %figure (22), imshow(a) %a=imnoise(a,'poisson'); bruit poisson %figure (23), imshow(a) %LE =20; %THETA =100; %filtre = fspecial('motion',LE,THETA); %figure (24), imshow(a) %a= imfilter(a, filtre, 'conv','circular'); %a= imadjust(a,[0.1;0.9],[0.1;0.4]); %-------------------------------------------------------------------------- sub=@(f,k)f(1:k:end,1:k:end); a=sub(a,2); a=medfilt2(a,[3 3]);% Filtrage médian pour supprimer le bruit b=imfill(a,'holes'); %remplissage de toutes les régions de l'image c=b-a;% faire la différence entre l'image remplie et celle avant le remplissage %pour extraire les blocs candidats S= [0 1 0;1 1 1;0 1 0] ; c=imerode(c,S) ;% Érosion de l'image résultat de la différence d=imfill(c,'holes');% refaire le remplissage e=d-c;%Réduire le nombre de condidat e=imerode(e,S);%Erosion de la nouvelle image e=medfilt2(e,[5 5]);% filtrage median pour réduire le bruit e=im2bw(e,0.1); %Convertir l'image en image binaire par seuillage. e=bwareaopen(e,150);%Sélection pour toutes les zones qui sont du domaine de plus de 150 pixels e1=e; [e,numero]=bwlabel(e); % Etiquettage des objets region_extrait=regionprops(e,'BoundingBox'); %Extraction des objets qui vérifie la propriété précedente(plus 150 pixel) for i=1:numero %on va faire le parcours de 1 vers nbre des objets c=0;l=0; coupe=imcrop(e,region_extrait(i).BoundingBox); %%crée un outil de recadrage des objets [l1,c1] = size(coupe); N(1,i)=l1; N(2,i)=c1; N(3,i)=l1*c1; end [h,k]=size(N); tai=0; for i=1:numero tai=tai+N(3,i); moy=tai/k; end e=bwareaopen(e,floor(moy/5)); [e,numero]=bwlabel(e); region_extrait=regionprops(e,'BoundingBox'); for i=1:numero coupe=imcrop(e,region_extrait(i).BoundingBox); [l1,c1] = size(coupe); n(1,i)=l1; n(2,i)=c1; n(3,i)=l1*c1; end [l2,c2] = size(n); U2=n(1,1); for i=1:c2 if U2<=n(1,i) U2=n(1,i); end end [l3,c3]=size(e); for t=1:numero for i=1:l3 for j=1:c3 if e(i,j)==t li=i; co=j; end end end n1(1,t)=li; n1(2,t)=co; end [C,D]=size(n); for i=1:D N=0; for j=1:D if n(1,i)>n(1,j) X=n(1,i)-n(1,j); else X=n(1,j)-n(1,i); end if X<15 N=N+1; P(i,j)=n(1,j); end end P(i,D+1)=N; end [E,F]=size(P); U=P(1,D+1); for i=1:E if U<=P(i,D+1) U=P(i,D+1); end end for i=1:E if P(i,D+1)==U j=i; for t=1:F-1 if P(j,t)>0 T(1,t)=P(j,t); T(2,t)=n(2,t); T(3,t)=n(3,t); end end end end U1=T(2,1); min=1000000000; for i=1:U if U1<=T(2,i) U1=T(2,i); end if min>=T(3,i) && T(3,i)>0 min=T(3,i); end end [C1,D1]=size(n1); for i=1:U if T(1,i)>0 R(1,i)=n1(1,i); R(2,i)=n1(2,i); end end pos=0; [A,B]=size®; ligne1=R(1,1); for i=B:-1:1 if ligne1<=R(1,i) ligne1=R(1,i); colon1=R(2,i); pos=i; end end for t=1:numero for i=l3:-1:1 for j=c3:-1:1 if e(i,j)==t li=i; co=j; end end end n2(1,t)=li; n2(2,t)=co; end [g1,f1]=size(n2); if f1>9 f1=f1-1; end for t=1:f1 ma=n2(1,1); mi=100000; for i=1:f1 if ma<=n2(1,i) ma=n2(1,i); end if mi>=n2(1,i) && n2(1,i)>0 mi=n2(1,i); r=i; end end if ma-mi>150 n2(1,r)=0; end end M1=0; [k,h]=size(T); if h>9 h=h-1; end for i=1:h if T(1,i)>0 M1=M1+1; R1(1,M1)=n2(1,i); R1(2,M1)=n2(2,i); end end x3=1000; ligne2=10000; for i=1:M1 if ligne2>=R1(1,i) && R1(1,i)>0 ligne2=R1(1,i); colon2=R1(2,i); pos2=i; end end if ligne1-ligne2<=200 U2=2; end if pos==1 U1=3; elseif pos==2 U1=10; elseif pos==3 U1=20; else U1=50; end if pos2<4 U3=150; elseif pos2>4 && pos2<6 U3=50; else U3=20; end for i=1:l3 for j=1:c3 if i<ligne2-U2 e1(i,j)=0; elseif i>ligne1+U2 e1(i,j)=0; else e1(i,j)=e1(i,j); end if j<colon1-U1*12 e1(i,j)=0; elseif j>colon2+U3*10 e1(i,j)=0; else e1(i,j)=e1(i,j); end end end e1=bwareaopen(e1,floor(min/7)); K2=e1; [e1,numero]=bwlabel(e1); [r1,r2]=size(e1); S1=zeros(r1,r2); p1=0; for t=1:r1 for j=1:r2 if e1(t,j)==1 S1(t,j)=t; end if S1(t,j)>=p1 p1=S1(t,j); w1=j; end end end S2=zeros(r1,r2); p2=0; for t=1:r1 for j=1:r2 if e1(t,j)==numero S2(t,j)=t; end if S2(t,j)>=p2 p2=S2(t,j); w2=j; end end end p3=p1-p2; w3=w2-w1; tg=p3/w3; u=atand(tg); U=u; %figure(6),imshow(e1) e1=imrotate(e1,-u); %figure(7),imshow(e1) e1=bwareaopen(e1,20); [e1,nu1]=bwlabel(e1); [nn1,nn2] = size(e1); for t=1:nu1 maxcolo=0; minlin=10000; for i=nn1:-1:1 for j=1:nn2 if e1(i,j)==t minlin=i; maxc=j; if maxcolo<=maxc maxcolo=maxc; end end end end maxlin=10000; [nn1,nn2] = size(e1); for i=1:nn1 for j=1:nn2 if e1(i,j)==t maxlin=i; end end end mincolo=10000; for i=1:nn1 for j=nn2:-1:1 if e1(i,j)==t minc=j; if mincolo>=minc mincolo=minc; end end end end tabmax(1,t)=maxlin; tabmin(1,t)=minlin; tabc1(1,t)=maxcolo; tabc1(2,t)=mincolo; end maxc2=0; tabc2=zeros(1,nu1); for i=1:nu1 tabc2(1,i)=tabc1(1,i)-tabc1(2,i); if tabc2(1,i)>=maxc2 maxc2=tabc2(1,i); llig=i; end end %llig tabc3=tabc2; for i=1:nu1 if i==llig tabc2(1,i)=0; end end ma2=0; for i=1:nu1 if tabc2(1,i)>=ma2 ma2=tabc2(1,i); end end moyenn=0; for i=1:nu1 moyenn=moyenn+tabc2(1,i); end tabc2=tabc3; moyenn=moyenn/(nu1-1); for i=1:nu1 tab(1,i)=tabmax(1,i)-tabmin(1,i); end max1=0; for i=1:nu1 if tab(1,i)>=max1 max1=tab(1,i); posmax=i; end end for i=1:nu1 H1(1,i)=max1-tab(1,i); end for i=1:nu1 ttab4(1,i)=tab(1,i)/tabc3(1,i); end %tab %ttab4 %max1 %H1 moyenn1=0; for i=1:nu1 moyenn1=moyenn1+H1(1,i); end moyenn1=moyenn1/(nu1-1); max2=0; for i=1:nu1 if H1(1,i)>=max2 max2=H1(1,i); posi=i; end end H(1,posmax)=max2; posi po=0; if max1-tab(1,1)>30 po=-2; posi=posmax; end if po==-2 H1(1,posi)=-1; elseif posi==3 && H1(1,posi)-H1(1,posi+1)<20 H1(1,posi)=-1; H1(1,posi+1)=-1; elseif posi==4 && (H1(1,posi)-H1(1,posi+1)<20) && H1(1,posi)-H1(1,posi+1)>=1 H1(1,posi)=-1; H1(1,posi+1)=-1; elseif posi==4 && (H1(1,posi)-H1(1,posi-1)<20) && H1(1,posi)-H1(1,posi+1)>=1 H1(1,posi)=-1; H1(1,posi-1)=-1; elseif posi==4 && (H1(1,posi)-H1(1,posi+1)<=1) && H1(1,posi)-H1(1,posi-1)<=1 H1(1,posi-1)=-1; elseif posi==4 && (H1(1,posi)-H1(1,posi+1)>20) && H1(1,posi)-H1(1,posi-1)>20 H1(1,posi)=-1; H1(1,posi+1)=-1; elseif posi==3 && H1(1,posi)-H1(1,posi+1)>20 && H1(1,posi)-H1(1,posi-1)>20 H1(1,posi)=-1; elseif posi==5 H1(1,posi)=-1; H1(1,posi-1)=-1; elseif posi==1 H1(1,posi)=-1; H1(1,posi+1)=-1; elseif posi==2 H1(1,posi)=-1; H1(1,posi-1)=-1; elseif posi==nu1 && H1(1,posi)-H1(1,posi-1)>10 H1(1,posi)=-1; elseif posi==nu1 && H1(1,posi)-H1(1,posi-1)<10 H1(1,posi)=-1; H1(1,posi-1)=-1; elseif posi==nu1-1 H1(1,posi)=-1; H1(1,posi+1)=-1; end H3=H1; e1=K2; %figure(1),imshow(e1) %////////////++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %++++++++++++++++lecture de chiffre+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %+++++++++++++++++++++ [e1,num]=bwlabel(e1); region_extrait=regionprops(e1,'BoundingBox'); for t=1:num if H3(1,t)>=0 coup=imcrop(e1,region_extrait(t).BoundingBox); [l,c]=size(coup); coup(1,:,:)=0; coup(l,:,:)=0; coup(:,c)=0; coup(:,1)=0; for i=1:l for j=1:c if coup(i,j)==t coup(i,j)=coup(i,j); else coup(i,j)=0; end end end coup1=imfill(coup,'holes'); if coup1==coup %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
c=coup; [li,ci] = size(c); c1=zeros(li,ci); for i=1:floor(li/4) for j=1:ci if c(i,j)>=1 c1(i,j)=j; end end end c2=zeros(li,ci); for i=3*floor(li/4):li for j=1:ci if c(i,j)>=1 c2(i,j)=j; end end end max1=0; max2=0; for i=1:li for j=1:ci if c1(i,j)>=max1 max1=c1(i,j); lin1=i; end if c2(i,j)>=max2 max2=c2(i,j); lin2=i; end end end d1(1,t)=ci-max1; d1(2,t)=ci-max2; if d1(1,t)<=d1(2,t) ang=0; else ang=d1(1,t)/(lin2-lin1); end u=atand(ang); c=imrotate(c,-u); %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ coup=c; [r1,r2] = size(coup); for j=1:r2 ze=0; for tt=1:r1 if coup(tt,j)>=1 ze=ze+1; lig=tt; li=lig-ze; if li==0 li=1; end end if ze<r1/10 && ze>0 && coup(tt,j)==0 for e=li:lig coup(e,j)=0; end elseif ze>r1/10 && coup(tt,j)==0 ze=0; end end end %-------------------------------------------------------------------------- [l,c] = size(coup); coup1=zeros(l,c); coup2=zeros(l,c); for i=1:l for j=1:c if coup(i,j)>=1 coup(i,j)=coup(i,j)/t; coup1(i,j)=j; coup2(i,j)=i; end end end [l,c] = size(coup); max1=0; max2=0; for i=1:l for j=1:c if coup1(i,j)>=max1 max1=coup1(i,j); end if coup2(i,j)>=max2 max2=coup2(i,j); end end end coup(1,:,:)=zeros; coup(l,:,:)=zeros; coup(:,1)=zeros; coup(:,c)=zeros; %figure(2),subplot(1,num,t),imshow(coup) for j=1:c if coup(floor(l/2),j)>=1 E1=j; end end for j=c:-1:3 if coup(floor(l/2),j)>=1 E2=j; end end y2=E1-E2; if y2>10 y2=10; end for y=1:1%y2-floor(y2/2) contour=edge(coup,'sobel'); for i=1:l for j=1:c if coup(i,j)==contour(i,j) coup(i,j)=0; end end end end %-------------------------------------------------------------------------- [l,c] = size(coup); %figure(3),subplot(1,num,t),imshow(coup) W=coup; im1=zeros(150,150); im2=zeros(150,150); minj=1000; for j=c:-1:1 for i=1:l if coup(i,j)>=1 mj=j; if minj>=mj minj=mj; end end end end mmincolon=1000; demi=1; minde1=1000; for j=c:-1:minj+2 for i=2*floor(l/3):-1:3 if coup(i,j)>=1 && coup(i+1,j)==0 de1=j; if de1<=minde1 minde1=de1; de=i; end end end end minde2=1000; dee=floor(l/2); for j=c:-1:minj+2 for i=l-1:-1:floor(l/2) if coup(i+1,j)>=1 && coup(i,j)==0 de2=j; if de2<=minde2 minde2=de2; dee=i; end end end end G2=dee; G1=de; G2=dee-5; G1=de+5; if G1>l G2<1 G1=1; G2=l; end if G1>G2 x1=G1; G1=G2; G2=x1; end for i=G2:-1:G1 for j=1:c if coup(i,j)>=1 ccolon=j; if ccolon<=mmincolon mmincolon=ccolon; demi=i; end end end end demi=demi+3; if demi<1 demi=1; end for p=1:l for j=1:c if p<=demi im1(p,j)=W(p,j); else im1(p,j)=0; end if p>=demi im2(p,j)=W(p,j); else im2(p,j)=0; end end end %figure(3),subplot(1,num,t),imshow(im1) %figure(4),subplot(1,num,t),imshow(im2) %figure(5),subplot(1,num,t),imshow(coup) tab1=zeros(200,200); tab2=zeros(200,200); for i=1:l for j=1:c if im1(i,j)>=1 tab1(i,j)=j; end if im2(i,j)>=1 tab2(i,j)=j; end end end b4=0; for j=1:c if W(demi,j)>0 b4=j; end end b3=0; for j=c:-1:1 if W(demi,j)>0 b3=j; end end %////////////b1 & b2 & b11 & b22 b1=0; for i=floor(l/6):-1:1 for j=1:c if b1<=tab1(i,j) b1=tab1(i,j); b11=i; end end end b2=1000; for i=demi-5:-1:1 for j=c:-1:1 if b2>=tab1(i,j) && tab1(i,j)>0 b2=tab1(i,j); b22=i; end end end %//////////////b5.... tab3=zeros(200,200); W1=zeros(l,c); for i=1:l pi=1; pj=1; for j=c:-1:1 if tab1(i,j)>0 pi=i; pj=j; end end W1(pi,pj)=im1(pi,pj); tab3(pi,pj)=tab1(pi,pj); end %figure(5),subplot(1,num,t),imshow(W1) b5=0; for i=b22:demi for j=1:c if tab3(i,j)>=b5 b5=tab3(i,j); b55=i; end end end %//////////b10.. W2=zeros(l,c); tab4=zeros(200,200); for i=1:l p1i=1; p1j=1; for j=1:c if tab1(i,j)>0 p1i=i; p1j=j; end end W2(p1i,p1j)=im1(p1i,p1j); tab4(p1i,p1j)=tab1(p1i,p1j); end %figure(6),subplot(1,num,t),imshow(W2) b10=1000; for i=b11:demi for j=1:c if tab4(i,j)<=b10 && tab4(i,j)>0 b10=tab4(i,j); linb10=i; end end end %////////////////////////////////////////////////////////////////////////// %//////////////////im2
%//////////////b7.... tab5=zeros(200,200); W5=zeros(l,c); for i=demi:l p5i=1; p5j=1; for j=c:-1:1 if tab2(i,j)>0 p5i=i; p5j=j; end end W5(p5i,p5j)=im2(p5i,p5j); tab5(p5i,p5j)=tab2(p5i,p5j); end %figure(7),subplot(1,num,t),imshow(W5) b7=1000; for i=demi:l for j=1:c if tab5(i,j)<=b7 && tab5(i,j)>0 b7=tab5(i,j); b77=i; end end end %//////////b8.. W8=zeros(l,c); tab6=zeros(200,200); for i=demi:l p8i=1; p8j=1; for j=1:c if tab2(i,j)>0 p8i=i; p8j=j; end end W8(p8i,p8j)=im2(p8i,p8j); tab6(p8i,p8j)=tab2(p8i,p8j); end %figure(8),subplot(1,num,t),imshow(W8) b8=0; for i=demi:l for j=1:c if tab6(i,j)>=b8 b8=tab6(i,j); b88=i; end end end %//////////////b6.... b6=0; for i=demi:b77 for j=1:c if tab5(i,j)>=b6 b6=tab5(i,j); b66=i; end end end %//////////////b9.... b9=1000; for i=demi:b88 for j=1:c if tab6(i,j)<=b9 && tab6(i,j)>0 b9=tab6(i,j); b99=i; end end end max12=0; min12=1000; for i=1:l for j=1:c if coup(i,j)>=1 b12=j; b13=j; if max12<=b12 max12=b12; end if min12>=b13 min12=b13; end end end end for i=l:-1:1 for j=1:c if coup(i,j)>=1 min13=i; end end end for i=1:l for j=1:c if coup(i,j)>=1 max13=i; end end end dist1=max13-min13; dist2=max12-min12; dist(1,t)=dist1; dist(2,t)=dist2; dist(3,t)=dist1/(dist2+2); if t>5 && U>1 VAL=3.6; else VAL=2.9; end Z=t; V(t,1)=b10/b4;V(t,2)=b2/b5;V(t,3)=b7/b3;V(t,4)=b4/b8;V(t,5)=b3/b6;V(t,6)=b9/b8;V(t,7)=b9/b4;V(t,8)=b10/b1;V(t,9)=b2/b3;V(t,10)=b7/b6; if b4/b10>0.85 && b2/b5<0.85 && b3/b6>0.85 && b9/b8<0.85 chiffre(1,Z)=2; elseif b10/b4>0.6 && b2/b5<0.8 && b4/b8>0.6 && b3/b6<=0.88 && b9/b4>0.85 && b7/b3<0.8 chiffre(1,Z)=3; elseif b10/b4<0.8 && b2/b5<0.8 && b7/b6<0.85 && b9/b4>0.85 chiffre(1,Z)=5; elseif b10/b1<0.85 && b2/b5>=0.9 && b2/b3<=1.6 && b7/b3>0.4 && b3/b6>0.9 && b9/b4>0.7 chiffre(1,Z)=4; elseif b10/b4>0.85 && b7/b3>=0.4 && b7/b3<=1.5 && b3/b6>0.8 && b9/b8>0.85 && b9/b4>0.85 && b9/b4<=1 && dist(3,Z)>=VAL chiffre(1,Z)=1; elseif b10/b4>0.8 && b4/b8>0.9 && b3/b6>0.85 && b9/b4>=0.9 && ttab4(1,Z)<VAL chiffre(1,Z)=7; else chiffre (1,Z)=11; end else chiffre (1,t)=99; end else chiffre (1,t)=22; end end [etiquetage,numero]=bwlabel(K2); region_extrait=regionprops(etiquetage,'BoundingBox'); [t1,t2]=size(chiffre); n=0; for E=1:t2 if chiffre(1,E)==99 c=imcrop(etiquetage,region_extrait(E).BoundingBox); [r1,r2]=size(c); for t=1:r1 for j=1:r2 if c(t,j)==E c(t,j)=E; else c(t,j)=0; end end end p = imfill(c,'holes'); c2=p-c; [r1,r2]=size(c2); ima1=zeros(100,100); ima2=zeros(100,100); for t=1:r1 for j=1:r2 if t<=r1/2 && j<=r2 ima1(t,j)=c2(t,j); else ima1(t,j)=0; end end end for t=1:r1 for j=1:r2 if t>=r1/2 && j<=r2 ima2(t,j)=c2(t,j); else ima2(t,j)=0; end end end %figure,imshow(ima1) num1=0; num2=0; y1=1; y2=1; for t=1:r1 for j=1:r2 if ima1(t,j)>=1 num1=num1+1; y1=t; end end end for t=r1:-1:1 for j=1:r2 if ima2(t,j)>=1 num2=num2+1; y2=t; end end end if num1==0 num1=1; end if num2==0 num2=1; end kl=num1/num2; NN(1,E)=num1; NN(2,E)=num2; NN(3,E)=kl; y1=y1+1; if kl>=0.9 && kl<=5 && y2-y1<2 chiffre(1,E)=0; elseif kl<=0.1 chiffre(1,E)=6; elseif kl>5 chiffre(1,E)=9; elseif kl>0.4 && kl<2 && y2-y1>2 chiffre(1,E)=8; elseif kl>0.1 && kl<0.4 chiffre(1,E)=4; end else chiffre(1,E)=chiffre(1,E); end end for i=1:t2 if chiffre(1,i)==22 && i==t2 chiff='NT'; elseif chiffre(1,i)==22 && i==1 chiff='NT'; elseif chiffre(1,i)==22 && i>2 && i<t2-2 chiff='Tunis'; end end figure(2) subplot(1,2,1) imshow(e1),title(strcat('chiffre=',num2str(chiffre))) subplot(1,2,2) imshow(e1),title(strcat('chiffre=',num2str(chiff))) toc;
2 件のコメント
Image Analyst
2015 年 4 月 15 日
I can't see the error message in all that. Please read these and fix your post, For example, by attaching the m-file with the paper clip icon.
Jan
2015 年 4 月 16 日
The French comments in the first part reduce the number of readers, who can understand this. The missing comments in the rest of the code make it impossible for anybody to find an error. Because without comments it is not clear what the code should do and if it contains bugs, one has to guess this. But then it is never clear if the guess and the intention of the code agree.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!