The content of the invention
It is an object of the invention to overcome the deficiencies of the prior art and provide a kind of magnetic searched for automatically based on binary-state threshold
Photoimaging defect inspection method, optimal binary-state threshold is searched for automatically, so as to realize defects detection exactly.
For achieving the above object, the magneto-optic image defects detection method that the present invention is searched for automatically based on binary-state threshold
Comprise the following steps:
S1:The magneto optic images of test specimen are obtained using magneto-optic imaging device, gray processing is carried out and handles to obtain magneto-optic gray-scale map;
S2:Mean filter is carried out to magneto-optic gray-scale map, obtains filtered image I;
S3:Binary-state threshold is searched for, it is comprised the following steps that:
S3.1:Search for the maximum obtained in image I in all pixels point pixel value and be designated as G, maximum filler pixels are set
Value K=λ G, λ are the constant more than 1;
S3.2:Order filling number t=1, initialization packed height value h1;
S3.3:According to height value htImage I is filled, matrix Φ after being filled, its formula is as follows:
Φ=ht·H-Ω
Wherein, Ω is image I pixel matrix, and H is and Ω size identical unit matrixs;
S3.4:Each pixel in matrix Φ is scanned, obtains the pixel that element value in matrix Φ is more than or equal to 0
Quantity, pixel quantity is saved as into filling area S (t);
S3.5:If ht< K, into step S3.6, otherwise into step S3.7;
S3.6:Make t=t+1, ht=ht-1+ Δ h, Δ h represent packed height step-length, return to step S3.3;
S3.7:According to each packed height htCarried out curve fitting with corresponding filling area S (t), obtain filling area
Relative to the change curve X of packed height;
S3.8:Search obtains the packed height in curve X corresponding to filling area growth rate maximumMake binaryzation threshold
Value Expression rounds up;
S4:Binaryzation is carried out to image I according to the step S3 binary-state threshold T for searching for obtain, obtains magneto-optic binary picture
Picture;
S5:Contour detecting is carried out to magneto-optic binary image, obtains the profile of each spot;
S6:The area R for each spot that calculation procedure S5 is obtainedq, q=1,2 ..., Q, Q expression amount of speckle;
S7:By the area R of each spotqBy being arranged from small to large, normalizing is carried out in section [1, Q] to area value
Change, q-th of area value after note normalization is γq;The poor Δ γ of two neighboring area value is calculated successivelyq′=γq′+1-γq′, q '
=1,2 ..., Q-1, once Δ γq′> τ, τ represents default threshold value, by γq′And its all areas block before is accordingly to be regarded as doing
Disturb, backfilled spot corresponding to interference using global gray-scale map in magneto-optic gray level image, the magneto-optic gray-scale map after backfill
As defects detection result figure.
The magneto-optic image defects detection method that the present invention is searched for automatically based on binary-state threshold, first to obtaining magneto-optic gray-scale map
Mean filter is carried out, binary-state threshold is then searched for automatically, has used the pixel filling of " pouring water " formula to scan in search procedure
Method, the filling area under different packed heights is calculated, fitting obtains change of the filling area relative to packed height
Curve, search obtain packed height in curve corresponding to filling area growth rate maximum as optimal binaryzation threshold values,
Then binary conversion treatment is carried out to the magneto optic images, recycles and spot is obtained to binary picture progress contour detecting, calculate each spot
The area of point, by filtering out interference of the method exclusive PCR hot spot of fleck to defect, so as to detect to obtain defect.
Then the present invention filters out interference, so as to rapidly and accurately by searching for optimal binary-state threshold automatically using area
Extraction obtains clearly defect information.
Embodiment
In order to which technical scheme is better described, the principle of the present invention is briefly described first.
In magneto-optic gray level image, the pixel value of those suspected defects part is less than non-defective part, but defect does not have in itself
Fixed depth and shape, slave pattern identify to be difficult to accomplish clearly to detect defect.Therefore, used in defects detection of the present invention
Image object is the magneto optic images after binaryzation.By binaryzation the edge of defect and positional information can be made largely complete
Portion is shown.Further according to the characteristic of image, it is filtered by different algorithms, so as to obtain the image of defect.By with
Upper analysis is understood, in magneto-optic detection, image binaryzation is particularly important.So image binaryzation when use the selection of threshold value
Often most important, prior art is all empirically determined threshold values in many cases, to the photo of original the magneto optic images
Quality has very big requirement and limitation.
Fig. 1 is the pixel value schematic diagram of rejected region.As shown in figure 1, because the pixel value of defect part is smaller, therefore
Rejected region pixel value gradually increases inside-out.Therefore when carrying out filling from low to high to gray level image, not
Same height, the area of filling is different.It is not only of different sizes, and area growth rate is also different.On defect side
At edge, area growth rate, which has one, significantly to be increased, and is fallen after rise again afterwards, and a kind of change of serpentine shape is presented.According to
Upper principle can search for obtaining binary-state threshold.
Fig. 2 is the embodiment for the magneto-optic image defects detection method that the present invention is searched for automatically based on binary-state threshold
Flow chart.As shown in Fig. 2 the present invention includes following step based on the magneto-optic image defects detection method that binary-state threshold is searched for automatically
Suddenly:
S201:Obtain magneto-optic gray-scale map:
The magneto optic images of test specimen are obtained using magneto-optic imaging device, gray processing is carried out and handles to obtain magneto-optic gray-scale map.
S202:Mean filter:
Mean filter is carried out to magneto-optic gray-scale map, obtains filtered image I.Filter window in filtering is not easy to set
Put too small, the general length of side is more than 5 pixels.It is too small that part bad pixel can be caused not filter out, cause filling below to be united
Meter figure fluctuation is larger, reduces the search precision of binary-state threshold.
S203:Binary-state threshold is searched for automatically:
Due to every time detection when illumination and material difference, the pixel value of the magneto optic images it is of different sizes, it is necessary to two-value
It is different to change threshold values, therefore the present invention proposes a kind of binary-state threshold automatic search method of " pouring water " formula, to adapt to
Different images.Fig. 3 is the automatic search routine figure of " pouring water " formula binary-state threshold.As shown in figure 3, " pouring water " formula binary-state threshold is certainly
Dynamic searching method comprises the following steps:
S301:Maximum filler pixels value is set:
Search for the maximum obtained in image I in all pixels point pixel value and be designated as G, maximum filler pixels value K=λ are set
G, λ are the constant more than 1, and λ=1.2 are set in the present embodiment.The effect of maximum filler pixels value is the process in filling scanning
It is middle to ensure to finish entire image filling.
S302:Initialization filling sweep parameter:
Order filling number t=1, initialization packed height value h1。h1Starting pixel value is filled for setting, can be according to reality
Border is needed to set, and h is set in the present embodiment1=1.
S303:Blank map picture:
According to height value htImage I is filled, matrix Φ after being filled, that is, completes following formula operation:
Φ=ht·H-Ω
Wherein, Ω is image I pixel matrix, and H is and Ω size identical unit matrixs.After resulting filling
In matrix Φ, the Pixel Information for being filled part is contained.
S304:Statistics is filled pixel quantity:
Each pixel in matrix Φ is scanned, obtains the pixel quantity that element value in matrix Φ is more than or equal to 0,
Pixel quantity is saved as into filling area S (t).When pixel in matrix Φ element value be more than or equal to 0, illustrate to fill out at this
In filling, the pixel is successfully filled, and element value is less than 0 pixel, then illustrates that current packed height is also failed to original
Pixel value covers.This is equivalent to, using fault location as depression, then pour water, filling area S (t) is equivalent to by the face of water submerged
Product.
S305:Judge whether ht< K, if it is, into step S306, otherwise into step S307.
S306:Make t=t+1, ht=ht-1+ Δ h, Δ h expression packed height step-length, is arranged as required to, return to step
S303。
S307:Curve matching:
Understand that optimal binary-state threshold is made corresponding to filling area growth rate maximum according to principle explanation before
Packed height, and obtained by the process before using be packed height and corresponding filling area discrete data point, therefore
Need according to each packed height htCarried out curve fitting with corresponding filling area S (t), obtain filling area relative to filling
The change curve X of height.The method of curve matching has a lot, and specific method can select according to being actually needed.In order that
It is accurately calculated, reduces agitation error, the present embodiment uses the approximating method based on cubic spline interpolation.
Fig. 4 is change curve exemplary plot of the obtained filling area of fitting relative to packed height.As shown in figure 4, horizontal seat
Packed height is designated as, ordinate is filling area.Filling scanning can be divided into by 5 stages by Fig. 4, be to scheming after filtering first
Dim spot as in is poured, followed by background is poured, and after transitional region, that is, is carried out to real defect position
Pouring, occur the most fast region of area growth rate at this moment, be then leveled off delaying, most image is filled at last.Initially filled out setting
Fill height value h1When, the first two region can be skipped, since transitional region, can so reduce amount of calculation.
S308:Search for binary-state threshold:
Search obtains the packed height in curve X corresponding to filling area growth rate maximumMake binary-state threshold Expression rounds up, and it is the packed height searched because of the curve X obtained according to fitting to roundMay
It is not integer value.
Because in the filling process, magneto-optic picture background color is also required to be filled in itself, and due to photon and sensor
The measurement error of itself, background colour can be caused also to have the different gray value of height.So in initial filling procedure, when filling out
Fill before the bottommost that height reaches flaw height value, the changing tendency of a serpentine shape also occurs in curve X, several in background
Filling is finished between the minimum pixel value in defect part, it may appear that a relatively flat region, the region are referred to as
" transition region ".After the region, local this of maximum slope can be assumed that as at optimal threshold values in curve X change.It is based on
Analyze above, the present embodiment proposes following searching method:
First derivative curve X is tried to achieve to change curve X1With Second derivative curves X2.With step-length σ to Second derivative curves X2
Scan for, if the second dervative X of ith search2(i) > 0, X2(i-1) < 0, then think that now i corresponds to first derivative
Curve X1In minimum value, continue search for, if the second dervative X of jth time search2(j) < 0, X2(j-1) > 0, then think
Now i corresponds to first derivative curve X1In maximum, then packed height corresponding during jth time search is that filling area increases
Packed height corresponding to long rate maximum
S204:Image binaryzation:
Search for obtain binary-state threshold T to image I progress binaryzations according to step S203, obtain magneto-optic binary image.
S205:Spot contour detecting:
Contour detecting is carried out to magneto-optic binary image, obtains the contour images of each spot.
Fig. 5 is spot profile testing method flow chart in the present embodiment.As shown in figure 5, spot contour detecting is including following
Step:
S501:Magneto-optic binary image medium filtering:
Because independent pixel point can not form the spot block of a closure, it is considered as pixel bad point, so first to magneto-optic two
Value image does median filter process, to filter out independent pixel point.Filter window is unsuitable excessive, takes [3,3]~[10,10] to be
Preferably, because too conference makes spot object excessively smooth, defect information precision reduces, too small and can not make that spot block can not be formed
Part is cut.
S502:Edge check:
Use " canny " operator that the profile of magneto-optic binary image is calculated, obtain the edge of magneto-optic binary image
Image L, edge image L size are consistent with magneto-optic binary image, remember that its size is M × N, edge pixels point in edge image
Value be 1, the value of non-edge pixels point is 0.
S503:Row sequence number p=1 is made, makes spot sequence number q=1.
S504:Scan non-zero pixels point:
Pth row pixel in edge image L is scanned, in pixel point set ApThe middle seat for recording each non-zero pixels
Mark.
S505:Judge whether ApFor sky, if it is, into step S506, otherwise into step S508.
S506:Judge whether p < N, if it is, into step S507, otherwise spot contour detecting terminates.
S507:Make p=p+1, return to step S504.
S508:Initialize the pixel queue O of q-th of spotqFor sky.
S509:Determine spot profile starting point:
By pixel point set ApIn first pixel as OqIn first pixel Oq(1), that is, by ApIn first non-zero
Profile starting point of the pixel as q-th of spot.
S510:Make pixel sequence number f=2 in spot.
S511:Determine next contour pixel:
Remember Oq(f-1) coordinate is (m, n), in magneto-optic binaryzation edge image L successively according to direction just on, upper right is right,
Bottom right, just under, lower-left, positive left and upper left is traveled through, that is, travel through pixel (m-1, n), (m-1, n+1), (m, n+1), (m+1,
N+1), (m+1, n), (m+1, n-1), (m-1, n-1), once finding non-zero pixels, then judge the pixel whether in pixel team
Arrange OqIn, if it is, search is next, otherwise non-zero pixels coordinate is assigned in pixel queue OqF-th of pixel Oq(f)。
S512:Judge whether Oq(f)=Oq(1), if it is not, into step S513, otherwise into step S514.
S513:Make f=f+1, return to step S511.
S514:In pixel queue OqMiddle deletion Oq(f), it is seen that now the Contour searching of q-th of spot finishes, and its is all
Pixel point coordinates is all recorded in pixel queue OqIn.
S515:Update magneto-optic binary image:
After the Contour searching of q-th of spot, because the profile between spot can not have intersection, it is therefore desirable in magneto-optic
In binaryzation edge image L, by pixel queue OqThe pixel value of middle all pixels coordinate is set to 0.
S516:Make q=q+1, return to step S504.
S206:Calculate each speck area:
The area of each spot in calculation procedure S205.Fig. 6 is speck area calculation flow chart in the present embodiment.Such as Fig. 6
It is shown, speck area calculate the step of include:
S601:Draw spot profile diagram:
The each spot profile obtained according to step S205, drafting obtain spot profile diagram.Its detailed process is:Initialization
With the magneto optic images size identical all black picture, pixel value corresponding to pixel in profile queue is then set to 1, you can obtain
Spot profile diagram.
S602:Make spot sequence number q=1.
S603:Search for spot boundary coordinate:
According to the pixel queue O of q-th of spotq, search for and obtain the maximum x of abscissa in each pixelmax, minimum value
xmin, and the maximum y of ordinatemax, minimum value ymin。
S604:Make row sequence number p '=xmin, q-th of speck area Rq=0.
S605:Scanning pth ' row include pixel:
Search obtains belonging to pixel queue O in pth ' rowqIn pixel, be ranked up from big to small by ordinate.Note is searched
The pixel quantity that rope obtains is H, pixel quantity V of the spot included in the rowp' calculated according to below equation:
Wherein,Expression rounds downwards.Because spot is a closed contour, therefore the intersection point of scan line and profile is
Have into having what is, therefore the wire-frame image vegetarian refreshments typically searched is even number, but be in particular cases strange there is also some
It is several, because odd number wire-frame image vegetarian refreshments there are a variety of situations, used for simplicity, in the present embodiment and cast out last wire-frame image
The mode (rounding H/2 downwards) of vegetarian refreshments estimates pixel quantity that the row are included.Due to there is odd number contour pixel
The possibility very little of point, therefore this estimation mode can't bring substantial influence to final area result.
S606:Area accumulation:
Make the area R of q-th of spotq=Rq+Vp′。
S607:Judge whether p ' < xmax, if it is, into step S608, otherwise into step S609.
S608:Make p '=p '+1, return to step S605.
S609:Judge whether that q < Q, Q represent the amount of speckle that step S205 is obtained, if it is, into step S610, it is no
Then the spotted areal calculation of institute terminates.
S610:Make q=q+1, return to step S603.
S207:Defects detection:
By step S206, the area of each spot can be obtained, is arranged from small to large according to area.Due to existing
Background profile, its area is maximum, therefore last spot is background block, and penultimate starts to lack to be doubtful in the magneto optic images
Fall into spot.Because defect area can be more than in general magnetic domain spot block or pixel perturbations spot, so if to adjacent after sequence
It is poor that the area of two spots is made, and in the presence of defective, has the part that an area increases suddenly, i.e. detectable accordingly to be lacked
Fall into.Its specific method is:
By the area R of each spotqBy being arranged from small to large, area value is normalized in section [1, Q],
Q-th of area value after note normalization is γq.The poor Δ γ of two neighboring area value is calculated successivelyq′=γq′+1-γq′, q '=
1,2 ..., Q-1, once Δ γq′> τ, τ represent default threshold value, then the γq′+1To γQ-1Corresponding spot is defect, γQ
For background, by γq′And its all areas block before is accordingly to be regarded as disturbing, and adopts spot corresponding to interference in magneto-optic gray level image
Backfilled with global gray-scale map, the magneto-optic gray-scale map after backfill is defects detection result figure.In general, in order to preferably
Defect and interference are distinguished, threshold tau >=1 is set, 1 is set in the present embodiment.
It can be seen that due to γQCorresponding spot is background, and when test specimen does not have defect, institute's spottiness is the interference such as magnetic domain,
It is evident that Δ γQ-1=γQ-γQ-1It is bigger, therefore background can be excluded, to γ1To γQ-1Corresponding spot
Backfilled;When test specimen is defective, it is assumed that the area value corresponding to defect isSo exist
Judge to disturb, so as to by γ1ExtremelyCorresponding interference spot is backfilled, and retains defect and background.
In order to which the technique effect of the present invention is better described, experimental verification has been carried out using a specific test specimen.Fig. 7 is
Test specimen picture used in the present embodiment.As shown in fig. 7, test specimen uses silicon steel sheet, the wherein wide 1mm of defect in the present embodiment, it is deep
0.2mm.Fig. 8 is the magneto-optic gray-scale map of test specimen shown in Fig. 7.As shown in figure 8, defect can be reflected in magneto-optic gray-scale map, but it is all
Also many black splotches are enclosed, are the recall rates that defect is disturbed caused by the influence of magnetic domain etc..Magneto-optic gray-scale map is carried out equal
Value filtering.Fig. 9 is the image after magneto-optic gray-scale map mean filter.Then binary-state threshold is searched for automatically.Figure 10 is filling area
Curve and single order, Second derivative curves.As shown in Figure 10, in the first derivative of filling area, first after minimum value
Maximum is optimal threshold values position, and the place that filling area growth rate is maximum, is just a peak value of second dervative, from
And search binary-state threshold.Then binaryzation can be carried out to magneto-optic gray-scale map.Figure 11 is magneto-optic binary image.To magneto-optic
Binary image carries out contour detecting and obtains spot, then calculates the area of each spot, filters out interference by area, realizes and lack
Fall into detection.Figure 12 is defects detection result figure., will be dry in magneto-optic binary image in order to preferably show defects detection result
The pixel pixel value that spot corresponding to disturbing is included is arranged to 0.Figure 13 is the magneto-optic binary picture of defects detection result.Such as figure
Shown in 12 and 13, defect information is extracted well, and the influence of magnetic domain spot has been reduced to minimum level.Figure 14 is former
Magneto-optic gray-scale map comparison diagram after beginning magneto-optic gray-scale map and filling.As shown in figure 14, magnetic domain can be excluded substantially using the present invention
Interference, obtains accurate defects detection result.
In addition, in order to illustrate beneficial effects of the present invention, defects detection is carried out using six kinds of conventional filtering reinforcement methods
Contrast on effect.Figure 15 is the magneto-optic gray-scale map result of six kinds of conventional filtering reinforcement methods.Comparison diagram 14 and Figure 15 can be seen
Go out, although six kinds of conventional filtering reinforcement methods can reduce the interference of magnetic domain to a certain extent, its effect well below
The present invention.It can be seen that relative to prior art, the present invention can more accurately extract defect image.
Although the illustrative embodiment of the present invention is described above, in order to the technology of the art
Personnel understand the present invention, it should be apparent that the invention is not restricted to the scope of embodiment, to the common skill of the art
For art personnel, if various change in the spirit and scope of the present invention that appended claim limits and determines, these
Change is it will be apparent that all utilize the innovation and creation of present inventive concept in the row of protection.