Then yesterday's work continued. Some of the positioning process is based on the color of the license plate positioning, and their own according to the digital image of some morphological methods to locate.
Related to the code.
1. The relative color image is grayscale, then the image is opened operation. The wavelet transform is used to obtain the three components of the image. Considering that the vertical component of the license plate is more abundant, the vertical component is used for subsequent operation. Note that some of the parameters here may be related to your image size, so adjust according to the actual situation.
Image=imread ('D:\1_2 learning \ image processing \ license Plate Recognition \matlab_car_plate-recognization\car_example\car0.jpg');%get Picture im=Double(Rgb2gray (Image)); Im=imresize (im,[1024x768,2048]);% re-set the picture size [1024x768,2048]% %Grayscale Stretching% Im=imadjust (image,[0.15 0.9],[]); S=strel ('Disk',Ten);%strei function Bgray=imopen (im,s);Open Sgray s image% Figure,imshow (Bgray), title ('Background Image');%Output Background Image% %using the original image and background image for subtraction, enhance the image Im=imsubtract (Im,bgray);two picture subtraction% figure,imshow (Mat2gray (IM));'enhance black and white images');%output black and white image [Lo_d,hi_d]=wfilters ('DB2','D'); %d decomposition Filters[c,s]= Wavedec2 (IM,1, lo_d,hi_d); %lo_d isThe Decomposition low-Pass Filter%decomposition vector C corresponding bookkeeping matrix sisize=prod (S (1,:));%element Multiplication%CA= C (1: isize);%ca49152CH= C (isize+ (1: isize)); CV= C (2*isize+ (1: isize)); CD= C (3*isize+ (1: Isize));%CA= Reshape (Ca,s (1,1), S (1,2)); CH= Reshape (Ch,s (2,1), S (2,2) ); CV= Reshape (Cv,s (2,1), S (2,2) ); CD= Reshape (Cd,s (2,1), S (2,2));
Get results
2. The image obtained in the above process is detected on the edge vertical direction, and then the open and closed operation of morphology is used to enlarge each area with more abundant vertical direction. Finally, the non-conforming area is filtered. Part of the code:
I2=edge (CV,'Sobel', Thresh,'Vertical');%based on the sensitivity threshold specified thresh, direction on the specified direction, A1=imclearborder (I2,8); %8 connected suppression and image boundary-connected Light object SE=strel ('Rectangle',[Ten, -]);%[Ten, -]i4=Imclose (a1,se); St=ones (1,8); %the selected structure element bg1=imclose (I4,ST); %closed Operation Bg3=imopen (BG1,ST); %Open Operation Bg2=imopen (bg3,[1 1 1 1]'); I5=bwareaopen (Bg2, -);%Remove pattern I5 with less than 2000 area=imclearborder (I5,4); %8 The Light object Figure,imshow (I5) connected with the image boundary and the connected suppression;'removing small objects from an object');
Get the filter results:
The next thing we want to do is to pick out the license plate area from these areas of choice.
3 Here we are going to use some prior knowledge about license plates. In 2007, the license plate standard stipulated that the car license plate length 440mm, width 140mm. The ratio is 440/140≈3.15. according to the size of the image pixel, here the selection criteria for the width of 70 to 250, the height between 15 to 70, while the width and height ratio should be greater than 0.45, you can more accurately obtain the approximate location of the license plate. Of course, the width and height values are also set according to your image size, and the size is different, the value is slightly difference.
%region filtering using aspect ratios [L,num]= Bwlabel (I5,8);%callout The connected part of the binary image, C3 is the image after morphological processing feastats=regionprops (L,'Basic');%calculating the feature size area of an image region=[feastats.area];%Area Area BoundingBox=[feastats.boundingbox];%[x y width height] license plate frame size RGB= Label2rgb (L,'Spring','k','Shuffle'); %logo image conversion to RGB imageLX=1;%The number of possible license plate regions with statistical width and height to meet the requirements Getok=zeros (1,Ten);%statistics meet the number of requirements forL=1: num%num is the number of color-coded areas width=boundingbox ((l1)*4+3); Hight=boundingbox ((l1)*4+4); Rato=width/hight;%calculate the license plate aspect ratio
% is determined using the known wide height and the approximate location of the license plate. if(width> -& width< -& hight> the& hight< -& (rato>3&rato<8) & ((Width*hight) >area (L)/2))%width> -& width< the& hight> the& hight< -Getok (LX)=l; LX=lx+1; Endendstartrow=1; startcol=1; [Original_hihgt Original_width]=size (CA);
Of course, this is only a preliminary determination, often the result is that several areas to be selected to meet the requirements. By observing its histogram, it is found that the histogram of the license plate area has many peaks and troughs, and the general regional changes are less obvious. Therefore, according to its variance, the number of peaks and troughs to determine the license plate area. Experimental results show that the effect is quite good.
fororder_num=1: lx-1%using vertical projection to calculate the number of peaks to determine the region Area_num=Getok (Order_num); Startcol=round (BoundingBox (area_num-1)*4+1)-2);%Start column StartRow=round (BoundingBox (area_num-1)*4+2)-2);%Start line width=boundingbox ((area_num-1)*4+3)+2;%License plate width hight=boundingbox ((area_num-1)*4+4)+2;%license plate High Uncertaincy_area=ca (startrow:startrow+hight,startcol:startcol+width-1); %get the possible license plate area Image_binary=binaryzation (Uncertaincy_area);histcol_unsure of image binary Value=sum (Uncertaincy_area);Calculate vertical Projection histcol_unsure=smooth (Histcol_unsure)';% Smoothing FilterHistcol_unsure=smooth (Histcol_unsure)';% Smoothing FilterAverage_vertical=mean (histcol_unsure); Figure,subplot (2,1,1), bar (histcol_unsure); Subplot (2,1,2), Imshow (Mat2gray (Uncertaincy_area)); [Data_1 data_2]=size (histcol_unsure); Peak_number=0; %Judging the number of peaks forj=2:d ata_2-1%Judging the number of peaksif(Histcol_unsure (j) >histcol_unsure1) & (Histcol_unsure (j) >histcol_unsure (j+1)) Peak_number=peak_number+1; End End Valley_number=0; %determine the number of troughs forj=2:d ata_2-1 if(Histcol_unsure (j) 1) & (Histcol_unsure (j) 1) & (Histcol_unsure (j) <average_vertical)%The trough value is smaller than the average valley_number=valley_number+1; End End%peak_number<= the ifpeak_number>=7& peak_number<= -&valley_number>=4& (startcol+width/2) >=original_width/6& (startcol+width/2) <=5*original_width/6.... & (startrow+hight/2) >=original_hihgt/6& (startrow+hight/2) <=original_hihgt*5/6%further confirmation of possible area Select_unsure_area (count)=Area_num; Standard_deviation (count)=STD2 (histcol_unsure);Calculate standard deviation Count=count+1; end Endcorrect_num_area=0; Max_standard_deviation=0;if(count<=2) %there is only one area Correct_num_area=select_unsure_area (count-1);Else fornum=1: count-1 if(num) > Standard_deviationmax_standard_deviation) max_standard_deviation=standard_deviation (num); Correct_num_area=Select_unsure_area (num); End End End
Get zone:
That's about as much as positioning. Here to explain, some of the above parameters and your picture specifications have a relationship, not you can easily take a piece to identify, according to your actual adjustment. Probably so much, welcome to exchange, reproduced please indicate the source, thank you.
"Original" Location and identification---of blue license plate based on MATLAB