function Touying (g) f=rgb2gray (g);% [M n]=size (f); [Row col]=size (f);% T=graythresh (f)% t=t*255% for i=1:row% for j=1:col% if (f (i,j) >t)% f (i,j) = 255; % Else F (i,j) =0;% end% end% ENDF=IM2BW (f,0.85); Figure,imshow (f); A=zeros (row,1); B=zeros (col,1); % h=fspecial (' average ', 3); % mean filter% F=IM2BW (round (Filter2 (h,f))),% Imshow (f) for I=1:row for J=1:col A (i) =a (i) +f (i,j);% transverse projection endend% for j= 1:col% for i=1:row% B (j) =b (j) +f (i,j);% Vertical projection% end% end% figure,plot (1:col,b) percent above is the projection of the white pixels in the rows and columns%%%%%%%%%%%%%% Original%%%%%%%%%%%%%%% for i=1:row% from top to bottom% if (a (i) >60)% horizontal projection greater than 50 where to cut% break;% end% end% p=i;% record at this time value% for i= row:-1:1% if (A (i) >60)% break;% end% end% q=i;%%%%%%%%%%% own revision%%%%%%%%%%%%%c=0;d=0;for i=1:row% from top down I F (A (i) >50)% transverse projection of more than 50 place for cutting c=c+1; if (c>20) break end endendp=i-20;% records the value at this time for I=row:-1:1 if (a (i) >50) d=d+1; if (d>20) break End Endendq=i+20;f=f (p:q,:);%%%%%%%% revision ends, Success%%%%%%%%%figure,imshow (f)%%%%%%%% continue to add%%%%%%%%%%%x=0;y=0; [Row1 col1]=size (f); for J=1:col1 for I=1:row1 B (j) =b (j) +f (i,j);% longitudinal projection endendfigure,plot (1:col1,b) for j=1:col1% Cut x=x+1 from left to right if (b (j) >7)% vertical projection greater than 50; if (x>15) break end Endendm=j-20;for j=col1:-1:1% is cut from right to left if (b (j) >7)% vertical projection is greater than 50 y=y+ 1; if (y>15) Break End endendn=j+20;m,n,col1,row1f=f (:, m:n); Figure,imshow (f);%plot (1:row,a), Figure,plo T (1:col,b)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wide=0;% flag=0;% if sum (f (:, wide+1)) ~=0% flag=1;% wide=wide +1;% end% if flag==1% while sum (f (:, wide+1)) ~=0% wide=wide+1;% end% end% if (wide<10)% is considered interference% f (: , [1:wide]) =0;% End%%%%%%%%%% Second revision%%%%%%%%%%%%%%%%% figure,imshow (f) c=zeros (+) k=1;if (k<17) for i= (c (k) +1): N if (mod (k,2)) if (b (i) >1)% projection has a threshold value of 3 C (k) =i; k=k+1; End Else if (b (i) <1) C (k) =i; k=k+1; End End endend% C (1), C (2), C (3), C (4), C (5), C (6), C (7), C (8), C (9), C (D), C (one), C (D), C (D), C (+) Z1=f (1:end,c (1): C (2)); Z2=f (1:end,c (3): C (4)); Z3=f (1:end,c (5): C (6)); Z4=f (1:end,c (7): C (8)); Z5=f (1:end,c (9): C (10)); Z6=f (1:end,c (one): C (12)); Z7=f (1:END,C): C (+)),% z8=f (1:end,c (): C (16)); Figure,subplot (241), Imshow (Z1), title (' One '), hold Onsubplot (242), Imshow (Z2), title (' both '), subplot (243), Imshow (Z3 ), title (' Three '); subplot (244), imshow (Z4), title (' Four '), subplot (245), Imshow (Z5), title (' Five '), subplot (246), I Mshow (Z6), title (' Six '), subplot (247), Imshow (Z7), title (' Seven '),%subplot (248), Imshow (Z8), title (' Eight ');%imwrit E (Z1, ' z1.jpg ')%imwrite (Z2, ' z2.jpg ')%imwrite (Z3, ' z3.jpg ')%imwrite (Z4, ' z4.jpg ')%imwrite (Z5, ' z5.jpg ')%imwrite (Z6, ' Z6.jpg ')%imwrite (Z7, ' z7.jpg ')%imwrite (Z8, ' z8.jpg ')
This code after several changes, or failed, do not know whether the projection has a problem. But if the threshold is good enough, it can be cut out of characters.
Algorithm of license plate segmentation in MATLAB