Self-adapting automatic focus method based on shade of gray value
Technical field
The present invention designs the self-adapting automatic focus method based on shade of gray value.
Background technique
Conventional cell pathological diagnosis method is by acquisition human body cell sample, and dyeing, then the mode of microscopic observation is difficult to
Adapt to the demand of practical application.With the development of technology, automatic diagosis technology is come into being.The technology automatically controls microscope and moves
It is dynamic to focus, it acquires and automatically analyzes and identify abnormal cell after picture under mirror, effectively doctor is assisted to realize Illnesses Diagnoses, reduced
While doctor's labor intensity, the diagnosis susceptibility and specificity of doctor are improved.
DNA ploidy body analytical technology is measured cell nuclear dna relative amount, DNA is surpassed by image analysis and identification technology
The cell recognition for crossing normal range (NR) comes out, and further confirms that for doctor.It is compared with the traditional method, which only needs doctor to check
The select a small number of abnormal cells of instrument, manually complete the browsing and range estimation to sample cell without doctor, effectively reduce
The workload of doctor.It is important that this technique avoids the subjectivity of doctor's microscopic observation and due to caused by visual fatigue partially
Difference further improves the accuracy rate of Illnesses Diagnoses.
Influencing the automatic focusing effect of microscope, mainly there are two key factors: clarity discriminant function and searching method.It is existing
Stage, common sharpness evaluation function mainly had four classes: the evaluation function based on spatial domain, the evaluation function based on transform domain,
Evaluation function based on comentropy is based on statistical evaluation function.And the most commonly used is based on spatial domain and based on statistics
Evaluation function.The sharpness evaluation function of traditional classical has: gray variance function (VAR), is drawn grey scale difference function (SMD)
General Laplacian operater (SML), energy gradient operator, image entropy and based on Spectrum Conversion etc..Evaluation function based on transform domain is general
Computation complexity is high, and poor in timeliness, such as the microscope focus method based on wavelet transformation need image carrying out wavelet decomposition, so
After calculate evaluation of estimate, there is a method in which carrying out detection evaluation using discrete transform pair image object, such method is due to wanting
Corresponding transformation is made so the calculating time is longer.The image definition based on strong edge width histogram proposed by Zhang Tianyu
Evaluation function is a kind of grey level histogram by calculating strong edge proposed in the field of spatial domain, determines strong edge
Width is to judge the method for image definition, due to the method it needs to be determined that the position of strong edge, so robustness is bad.Afterwards
To combine half scan imaging method by S.Matsui etc., devise the point spread function with special nature, is keeping acquiring figure
Under the premise of image height signal-to-noise ratio, the performance of depth from defocus estimation is substantially improved, which has stronger robustness.
Peizhen Qiu is rebuild using luxuriant and rich with fragrance alunite transformation as digital hologram, realizes that digital hologram focuses.Answering in adaptive principle later
On the basis of, Yuqing Xiao copy retina establish model, realize it is a kind of based on adaptive retina sampling model from
Dynamic focus method.
The present invention proposes a kind of self-adapting automatic focus method based on shade of gray value.This method is first with the sky of defocus
White image obtains an importance factors as references object compared with present image, Lai Hengliang pixel gray value difference
Calculate participation;Then whether clear with the number evaluation image of neighbor pixel gray value difference.Algorithm is using adaptive point
Stage variable step-size search mode completes the automatic positioning of microscope figure image focus.Show what the present invention provided by testing test
Focusing evaluation algorithms has the advantages that computation complexity is low, unimodality is good, timeliness is good, can be realized quick, accurately micro-
Mirror focuses automatically.
Summary of the invention
The purpose of the present invention is to solve existing Auto-focusing Algorithm for Microscope in computation complexity, unimodality, timeliness
Property Shortcomings in a certain respect, and propose a kind of self-adapting automatic focus method based on shade of gray value.
Foregoing invention purpose is mainly achieved through the following technical solutions:
Step 1: collecting gray level image A from camera, xth row, the pixel value of y column are represented with g (x, y);
Step 2: whether clear using sharpness evaluation function evaluation image.This step present invention provides two methods:
Method 1:
Wherein α be out-of-focus image average gray value, be a constant, acquiring method are as follows: first on whole slide with
Machine acquires the image of 10 complete defocus, is averaging gray value, which is α.The setting formula of b are as follows:
min[g′(x,y)-g′(x+1,y)]
Method 2:
β is threshold value, takes method are as follows:
β=max [g ' (x, y)-g ' (x-1, y)]
Wherein g ' (x, y) is the pixel gray value of out-of-focus image, and the gray value difference of image is most when β is unfocused
Big value.
Step 3: finding focus using self-adaptive search algorithm.When initial position Range Focusing point farther out when use
Method 1 is quickly close with larger step size, and application method 2 is when Range Focusing point is closer with small step-length search one by one, it is ensured that essence
Exactness.Three kinds of step-lengths have been used during becoming step search:
(1) at initial position, farther out, image is in the state of serious defocus to distance focal point, and picture material is almost all back
Scape content, i.e. in Fig. 2 when x < g, step-length is set as big step-length S at this time, carries out image definition evaluation using method 1, quickly to
Focus search.
(2) when leaning on perifocus, at this time it can be seen that picture material, but picture material is in smudgy clear state,
That is in Fig. 2 when g < x < G, at this moment step-length is set as smaller step-length S1, still image definition evaluation is carried out using method 1, to focus
Search.It is process of the thick focal zone to smart focal zone transition in the process of g to G, so the setting of g can be set as currently scheming
As in pixel gray value difference maximum value be just marginally larger than β when x position, G be present image in pixel gray level value difference
The position of x, the determination method of β value have been provided in second step when number of the maximum value of value greater than β is more than V, and the value of V can be free
Setting.
(3) when near focal point, the content of image is more apparent at this time, but can also have fuzzy edge contour, this
When step-length is set as smaller value Sm, method 2 carries out image definition evaluation letter, then carries out slow step search.
Step 4: repeat the above steps two and step 3 until focus on focus.
Invention effect
The present invention provides a kind of self-adapting automatic focus methods based on shade of gray value.The gray scale of DNA is acquired first
Then whether clear image evaluates the image using the method in sharpness evaluation function in step 2, finally according to evaluation
As a result, carrying out focus search with the method in step 3, a clearly DNA gray level image is finally obtained.Through overtesting table
Evaluation in the bright present invention is all significantly improved and improves in unimodality, acuteness, timeliness, then using adaptively searching
Suo Fangfa is quick and accurately navigates to focus.Test result data are as shown in figure 3, sharpness evaluation function in the present invention
It will be better than SMD, SML, VAR function in unimodality, timeliness, acuteness, combining adaptive searching method makes entirely poly-
Burnt process is more quickly and accurate.
Detailed description of the invention
Fig. 1 is to focus flow chart;
Fig. 2 is searching method figure;
Fig. 3 is experimental result comparison diagram, and Fig. 3-1 is sharpness evaluation function focusing curve comparison diagram, and Fig. 3-2 is clarity
Evaluation function operation time comparison diagram.
Specific implementation method
Specific embodiment 1: illustrate that present embodiment, present embodiment are based on shade of gray value in conjunction with Fig. 1 and Fig. 2
Self-adapting automatic focus method is specifically prepared according to the following steps:
Step 1: opening camera;
Step 2: Image Acquisition, collects gray level image A from camera, A (x, y), which is used, represents ground x row, the pixel of y column
Value;
Step 3: clarity is evaluated:
(1) sharpness evaluation function Back function:
Wherein α be out-of-focus image average gray value, be a constant, acquiring method are as follows: first on whole slide with
Machine acquires the image of 10 complete defocus, is averaging gray value, which is α.The setting formula of b are as follows:
min[g′(x,y)-g′(x+1,y)]
(2) sharpness evaluation function SD function:
β is threshold value, takes method are as follows:
β=max [g ' (x, y)-g ' (x-1, y)]
Wherein g ' (x, y) is the pixel gray value of out-of-focus image, and the gray value difference of image is most when β is unfocused
Big value.
Step 4: focus search.The effect of this process is carried out according to the result of the sharpness evaluation function in step 3
Focus search.When initial position Range Focusing point farther out when it is quickly close with larger step size using Back function, distance is poly-
Using SD function with small step-length search one by one when focus is closer, it is ensured that accuracy.It is used during becoming step search
Three kinds of step-lengths:
(1) at initial position, farther out, image is in the state of serious defocus to distance focal point, and picture material is almost all back
Scape content, i.e. in Fig. 2 when x < g, step-length is set as big step-length S at this time, carries out image definition evaluation using Back function, quickly
To focus search.
(2) when leaning on perifocus, at this time it can be seen that picture material, but picture material is in smudgy clear state,
That is in Fig. 2 when g < x < G, at this moment step-length is set as smaller step-length S1, still image definition evaluation is carried out using Back function, to coke
Point search.It is process of the thick focal zone to smart focal zone transition in the process of g to G, so the setting of g can be set as currently
In image the maximum value of pixel gray value difference be just marginally larger than β when x position, G be present image in pixel gray value
The position of x, the determination method of β value have been provided in step 2 when number of the maximum value of difference greater than β is more than V, and the value of V can be free
Setting.
(3) when near focal point, the content of image is more apparent at this time, but can also have fuzzy edge contour, this
When step-length is set as smaller value Sm, SD function carries out image definition evaluation letter, then carries out slow step search.
In search process, the sharpness evaluation function of whole process are as follows:
Wherein G is setting threshold values, and acquiring method has provided in (2), converts evaluation function when z-axis is moved to G point.
Step 5: repeating step 3 and step 4 until navigating to focal position.
Embodiment 1:
The present embodiment, the self-adapting automatic focus method based on shade of gray value are specifically to be prepared according to the following steps:
Purposes, technical schemes and advantages in order to clearly illustrate the embodiment of the present invention are clearer, tie below
Closing attached drawing, invention is further explained.
One embodiment of the present of invention are as follows:
The invention is applied in " cancer cell automatic tester " that we voluntarily research and develop, which has PC machine, automatically shows
Micro mirror, full HD video camera and cell analysis software composition.
Automatic full sheet sweep test in the system apply our foregoing inventions " based on shade of gray value it is adaptive from
Cell glass slide is placed on objective table it by dynamic focus method ", first user, starting scanning, into image acquisition phase, tool
Steps are as follows for body:
S1, plurality of pictures A is first taken1,A2,...,AN, the average gray value of every picture is sought, is then averaging gray scale again
It is worth weighted average, which is indicated with α;
S2, judge whether image is clear using sharpness evaluation function Back function.Calculation formula are as follows:
Wherein the acquiring method S1 of α has been provided, the setting formula of b are as follows:
min[g′(x,y)-g′(x+1,y)]
S3, focus search is carried out.At this time in corresponding diagram 2 when x < g, step-length is set as big step-length S, quickly to focus search.g
Setting can be set as pixel gray value difference in present image maximum value be just marginally larger than β when x position.β value obtains
Setting:
β=max [g ' (x, y)-g ' (x-1, y)]
S4, S2, S3 process are repeated up to g point position, sets smaller value S1 for step-length at this time, continue to repeat S2, S3 mistake
Cheng Zhizhi G point position, as shown in Figure 2.G is that number of the maximum value greater than β of pixel gray value difference in present image is more than V
When x position, the determination method of β value provided in S3, and the value of V can freely be set.,
S5, arrival G point postpone, and whether clear using clarity discriminant function SD criteria function image, discriminant function is public
Formula are as follows:
Wherein provided in the setting S3 of β.
S6, it sets step-length to smaller value Sm, searches for focal position, by step-length to set Sm/2 anti-if crossing focal position
To search.
S7, S5 and S6 step is repeated, until searching focal position.
Entire focusing is as shown in Figure 1, entire search routine is as shown in Figure 2.
The present invention can also have other various embodiments, without deviating from the spirit and substance of the present invention, this field
Technical staff makes various corresponding changes and modifications in accordance with the present invention, but these corresponding changes and modifications all should belong to
The protection scope of the appended claims of the present invention.