A list,

1.1 Topic Content

Metal plates are widely used in industrial production and production and life. Due to sheet metal manufacture process involves many factors such as equipment, process and the effect of metal plate surface is easy to appear more kinds and forms of defects, the defects of metal plate wear resistance, corrosion resistance, magnetic properties and beautiful sex can cause varying degrees of impact, will ultimately affect the magnetic properties of the metal plate and plating effect. So for manufacturing metal plate, surface defect detection is an essential process, on the one hand, the defective product can be detected by surface defect detection in a timely manner, to ensure the quality of the metal plate, from the maintenance of the credibility of enterprises, on the other hand can also be based on the analysis of test results found problems in the production process in time, and promptly solve [1]. Based on the metal surface defect photo data set provided on the Internet, we will construct the corresponding algorithm to detect, identify, classify and measure the defects on the metal surface.

1.2 Requirements

The identification and classification of metal surface defects have the following specific requirements:

(1) According to the characteristics of the images of metal surface defects, appropriate gray scale transformation (contrast enhancement and filtering) is carried out on the images;

(2) Perform global optimization threshold segmentation for metal surface defect images;

(3) Extracting the boundary coordinates of binary images;

(4) Feature extraction of metal defects;

(5) Classification and supervised training of metal defects;

(6) Complete the judgment of metal defect type and the calculation of location size;

(7) Completed the GUI design of metal defect detection.

2

After consulting relevant materials, we learned that common metal surface defects are mainly as follows. They are: crazing, surface impurities, patches, pitted surface, rolled in scale and scratches. They correspond to Figure (a)- Figure (f) respectively.



We consider only three types: surface spots (FIG. B), surface rolled oxide scale (FIG. (e)) and surface scratches (FIG. (f)).

The main steps of image processing include contrast enhancement, filtering, threshold segmentation, morphological processing, feature extraction, classification training, defect location calculation and GUI integrated operation display.

Step.1: Enhanced contrast

Because lighting system and so on, we found that the metal surface flaws in the original image and the background of the metal surface is small, the grayscale difference between gray level range is small, so the contrast is low, metal flaws are not obvious, it is bad for the image post-processing, we need to use some methods to increase the contrast of the image. Common contrast enhancement methods include logarithmic transformation, power law transformation, gray level stratification, gray level normalization, contrast stretching, histogram equalization, histogram specification and so on. Considering that the background light intensity of different photos is not the same, so the methods of constant parameters (such as logarithmic transformation, power law transformation, gray level stratification, contrast stretching) are not suitable for all pictures, so we consider using gray level normalization and histogram equalization.

Step.2: filtering

All kinds of noise, including Gaussian noise and salt and pepper noise, will inevitably be introduced in the process of taking photos. At the same time, the metal surface itself has a certain texture. Noise and texture will cover up metal surface defects to a certain extent, which will lead to errors in extraction. We need to filter the image first to reduce subsequent false detection. Filtering methods are mainly divided into spatial filtering and frequency filtering, and their relationship satisfies the convolution theorem. The spatial filtering mainly includes mean filtering, median filtering, Gaussian filtering and bilateral filtering. Frequency filtering note Fourier transform filtering, discrete cosine transform filtering and wavelet transform filtering. These algorithms can reduce noise, but also filter out some details, resulting in the loss of some defect details. So we need to find a new filtering algorithm to achieve.

Step.3: threshold segmentation

After we get the filtered image, we also need to perform binarization threshold processing, so as to properly extract the defect information. Traditional threshold segmentation needs to determine the threshold value, but for different complex metal defect images, we cannot use the same threshold value for all images, so we plan to use global/local optimal threshold segmentation to automatically determine the best threshold value.

Step.4: Morphological treatment

Limited by the quality of the original image and the image threshold segmentation algorithm, some areas that should be connected in the binary image may be segmented by the threshold. For example, the scratch defect is incorrectly segmented due to a low gray value at a certain point, resulting in a scratch may be separated into multiple line segments. So we need to do a closed operation to connect neighboring objects. At the same time, some defects in the image are large (such as large scratch width), and after the subsequent edge detection, the two edges of a line are far apart, so the line extraction algorithm will mistakenly regard the same line as two parallel scratches. Therefore, we also need to refine the defects.

Step.5: Feature extraction

This part can use two methods, one is based on general feature extraction algorithm (such as HOG, LBP, Haar algorithm, etc.); The other is to categorize scratches directly based on specific features of the specific metal defects we are testing for. I’ll test both approaches separately.

Step.6: Classification training

If we use a general feature extraction algorithm, we will conduct classification supervision training for it. The commonly used supervised learning algorithms include :K neighbor algorithm (KNN), naive Bayes algorithm, decision tree algorithm, support vector machine (SVM), logistic regression and so on. Since support vector machine has excellent generalization ability and can obtain much better effect than other algorithms in small sample training set [6], we plan to choose support vector machine algorithm.

Step.7: Calculation of defect location size

After we extract the defect, we need different features to characterize the size and location of the defect. For “rolled in oxide scale”, the number of “rolled in oxide scale” is used to characterize the size of the defect, and its centroid is used to characterize its position; For spots, we use the proportion of the area in spots to the whole picture to characterize the size of the defect. For scratches, the two endpoints of scratches are used to represent the location of defects, and the length of scratches is used to standard the size of defects.

Step 8: GUI design

For the convenience of users, we design the GUI interface, can choose the pictures in a computer, and can display after click on the “image processing” to extract the defect information (type and position and size), the length of scratch, we can let the user to enter the camera focal length and the length of the object distance, and calculate the actual scratch size according to the geometrical optics knowledge, And the size of the image surface of each scratch and the actual size are displayed. At the same time, the GUI allows users to go to the download site of the dataset by pressing a button.

Ii. Source code

// Overview of the work: The main function of this code is to realize the detection, classification and measurement of three kinds of defects on the metal surface, and use GUI to encapsulate for users to use. The GUI can import grayscale images from the computer, and then process them. It can determine the type of defects, mark detected defects on the original picture, and measure the size of different defects (different defect measurement standards are different). -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / / important function introduction: #pushbutton1_Callback(hObject, eventdata,handles): Pushbutton2_Callback (hObject, eventData,handles): The callback function for key 2(the 'import image' button), It is mainly the image import #Ga(Theta,num): the initialization of the Garbor convolution kernel of the image # FilterImage (A6,Gaborfiter):Garbor filtering algorithm # Thres (image): the maximum entropy threshold segmentation algorithm of grayscale image # the location (s) : 'rolling into the oxide skin defect positioning and display # houghtran () : for hoff round' scratch 'defects detection # LBP (varargin) : online' local binary pattern # feature extraction algorithm of SVM. M: independent m file, LBP feature extraction and training and testing of SVM(support vector machine) supervised learning algorithm for all metal defect photos -------------------------------------------------------------------------------------------- %} %% function varargout = App (varargin) %GUI = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @app_OpeningFcn, ... 'gui_OutputFcn', @app_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end %% function app_OpeningFcn(hObject, eventdata, handles, Varargin) % GUI initialization function %modified by:Faust.Cao HA = AXES ('units','normalized','pos',[0 0 1 1]) uistack(ha,'down'); % back.jpg ii=imread('C:\Users\ Lenovo \Desktop\ Metal Surface Defect Classification and Measurement GUI System \back.jpg'); image(ii); colormap gray set(ha,'handlevisibility','off','visible','off'); handles.output = hObject; guidata(hObject, handles); %% function varargout = app_OutputFcn(hObject, eventData, handles) Varargout {1} = handles. Output; %% function pushbutton1_Callback(hObject, eventData, handles) % global a5; % global svmModel; % global variable, call Axis off from svm.m file; % Remove axes coordinates and fully display the image A6 = A5; a=str2double(get(handles.edit1,'string')); B =str2double(get(handles. Edit2,'string')); % read user input distance d=a/(b-a); Vertical magnification ma= Max (Max (a6)) is calculated by Gauss formula; mi=min(min(a6)); A6 (ii,jj)=255*double(a6(ii,jj)-mi)./double(ma-mi); Ab = filterImage (a6); % image segmentation ss= Thres (ab); ab1=im2bw(ab,ss/255); [B,L]=bwboundaries(ab1); % binary graph edge coordinate extraction [x,y]=size(B); mm=0; For I =1:x ll=length(B{I}); if ll>mm mm=ll; If mm<120 set(handles. Text8,'string',' handlebar '); % Output defect type [xc,yc]= findCenter (B,ab); Axes (handles. Axes2); % set imshow(a6) at axes2; hold on; plot(yc+12,xc+12,'*'); % plus the boundary lost during filtering [dd,bb]=size(xc); Tex =[' total ',num2str(dd),' more than one ']; set(handles.text10,'string',tex); % output defect information % in text10 text box is not 'rolled in oxide scale' defect, continue to judge else % original image and binary image for mask processing, note that the size of the two is different, so first remove the edge of the original image a6(1:12,:)=[]; a6(177:188,:)=[]; a6(:,1:12)=[]; a6(:,177:188)=[]; mu1=uint8(ab1).*a6; mu2=uint8(1-ab1).*a6; t0=mu1(mu1~=0); m1=mean(t0); t1=mu2(mu2~=0); m2=mean(t1); Judge whether the defect is spots or scratches: spots darker than the background, scratches cooler than the background; If m1<m2+20 set(handles. Text8,'string',' defects are spots '), then SVM training results can be used to classify the images. all=bwarea(ab1); % Calculate spot area pro=100*all/176/176; Tex =[' speckle area ratio is ',num2str(pro),'%']; set(handles.text10,'string',tex); axes(handles.axes2); imshow(a6); hold on; For k = 1:length(B) boundary = B{k}; Plot (boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2) End % defect is scratch else a6=adapthisteq(a6); % adaptive histogram equalization enhanced contrast ss= Thres (a6); ab1=im2bw(a6,ss/255); ab1=imclose(ab1,strel('square',6)); Ab1 =bwmorph(ab1,'thin',5); ab1=bwmorph(ab1,'thin',5); Ab1 =edge(ab1,'Canny'); % Canny operator edge extract set(handles. Text8,'string',' defect is scratch '); axes(handles.axes2); imshow(a6); hold on; % Below is the subsequent processing and display of scratch extraction [Point,ang]= Houghtran (AB1); % Hough line detection on the processed binary graph CEN = Zeros (Length (ang),2); po=zeros(length(ang),4); an=zeros(length(ang),1); thm=mean(abs(ang)); Abs (THM)<45% THM =40; abs(THM)<45% THM =40; The else % horizontal THM = 60; end le=length(cen); For kk=1:le cen(kk,1)=(point(kk,1)+point(kk,3))/2; cen(kk,2)=(point(kk,2)+point(kk,4))/2; point(kk,5)=cen(kk,1); point(kk,6)=cen(kk,2); End % if THM ==40% point=sortrows(point,5); endCopy the code

3. Operation results