Fast automatic focusing method of microscope based on Flame Image Process
Technical field
The present invention relates to microscope automatic focus technical field, especially a kind of fast automatic focusing method of microscope based on Flame Image Process.
Background technology
Traditional microscope focus method is to adopt manually the mode of regulating, this method place one's entire reliance upon people's visual inspection and manual adjustments, and focusing efficiency is very low.Auto focusing method based on image processing techniques is applied in the microscope focusing process gradually in recent years, but these methods also exist focusing speed to be absorbed in local extremum, the problem that focusing accuracy is not high slowly, easily at present.
Automatic focus is a gordian technique in the full-automatic Image Acquisition, is widely used in fields such as digital camera, photomicrograph, retrofit, optical measuring device, robot visual guidance.Automatic focus can be divided into active focusing according to its focusing principle and passive type focuses on two kinds.Active focusing is based on range measurement principle mostly, because this method needs extra distance-measuring equipment, therefore adopts the general volume of equipment of this method bigger, and price is higher.Passive type focuses on the focus state that only utilizes the current system of sequence digital image analysis that has obtained, and regulates lens parameters repeatedly according to certain search strategy control motor, up to obtaining distinct image.This mode does not rely on any distance-measuring equipment, is the basis with Digital Image Processing and analytical technology fully, is more conducive to the integrated and microminiaturized of system, and can reduce system cost greatly, therefore in digital camera and various instrument and equipment, is used widely.
Passive type automatic focus relates generally to two key issues: one is to focus on evaluation function, and one is the extremum search strategy, many to the research that focuses on evaluation function at present, and is also having a lot of problems not obtain fine solution aspect the extremum search strategy.
The extremum search strategy that has proposed at present is a lot, and wherein most widely used is hill-climbing algorithm (CMS), and its principle is as shown in Figure 1, at first, sets an initial position P
0And calculate the focusing evaluation function value F (P of this position
0), select a direction (such as selecting to the right) the certain step-length S in-position P of motion then arbitrarily
1And calculate the focusing evaluation function value F (P of this position
1), compare F (P
0) and F (P
1) size, if F (P
0)<F (P
1), then keep the constant continuation search of direction until F (P
0)>F (P
1), next carry out reverse search, search procedure is the same with the forward lookup process; But step-length is less than the forward lookup step-length; Generally get the half the or littler of forward step-length, so under the situation that is satisfying certain accuracy requirement, search maximal value repeatedly, this position is best focus position.The CMS algorithm performance is more stable, and search precision is higher, but has a very big problem: the search step number is too much, and algorithm is very consuming time! Especially after search " top more ", return the definite numerical standard of definite neither one of step-length; Very random; The size of returning step-length under many circumstances has very big influence to the stability and the real-time of algorithm, step-length is too for a short time cause searching for step number too much, system real time will descend greatly, step-length can cause excessively " pushing up more " too greatly again; Excessively must return again again after " top more ", this also can greatly influence the entire system performance.
To above situation, a lot of scholars have proposed the improvement algorithm, such as based on slope adaptive step searching algorithm, curve fitting searching algorithm etc., but these algorithms all exist problems such as noiseproof feature is poor, adaptability is wide, stability is not high.Such as variable step-size search algorithm based on slope; Because noise effect causes focusing curve to have a lot of local extremums; Do not existed in the relation of these local extremum place slopes with step-length; The unavoidable failure of search like this, slope itself is a relative concept in addition, only relies on former and later two focus function measure values can't effectively define slope.The curve fitting searching algorithm comes approximate focus evaluation function curve with a mathematical function; This algorithm in particular cases can be obtained reasonable effect at some; But the non-constant of versatility, this is height correlation owing to focusing on evaluation function with picture material, same focusing evaluation function is not on all four to its form of pictures different; In some cases even differ greatly, therefore can't go match with a general purpose function.
In fact, be that classical hill-climbing algorithm or a lot of algorithm that improves do not consider that all mechanical motion is to the influence of system real time ability in the real system.Present most of autofocus system all is to carry out the search of best focal plane with step motor drive camera lens or objective table; And motor movement is very consuming time with respect to Flame Image Process; The calculating that generally focuses on the evaluation function value such as the image of a secondary 800*600 only needs several milliseconds to accomplish; But motor movement then can consume great amount of time comparatively speaking; Generally just start with, but speed improves for the very-short-reach motion and have little significance, and the bump of motor will be very serious also in this case from improving movement velocity in order to reduce the motor movement time.Therefore radical solving method is started with from search strategy exactly, seeks a kind of algorithm that can find maximum value with minimum step number.Through analyze hill-climbing algorithm we find step number what return the big or small closely related of step-length after with " top more ", if algorithm ability fast return of " top more " back near maximum value, the overall performance of system will obtain the lifting of essence so.
Summary of the invention
In order to overcome the slow and coarse deficiency of focusing of existing microscope automatic focus speed, the invention provides a kind of fast automatic focusing method of microscope based on Flame Image Process.
The technical solution adopted for the present invention to solve the technical problems is: a kind of fast automatic focusing method of microscope based on Flame Image Process; The automatic focus process is divided into thick focusing and two stages of fine focus; Adopt different focusing evaluation function and extremum search strategy in the different stages; Adopt the grey scale difference evaluation function and climb the mountain fast and recall searching algorithm in the thick focusing stage; And introduce the decision-making factor and prevent that searching algorithm is absorbed in local extremum, adopt evaluation function and the long search strategy of small step in the fine focus stage based on the laplace operator.
According to another embodiment of the invention, further comprise the steps:
(1) objective table initial position setting: the motor-driven objective table moves to the initial position that pre-sets along the Z axle; Place microslide to be observed on the objective table; Said initial position is positioned near the microscope focal plane; Generally be positioned at the focal plane upside, this initial position is as self-focusing starting point;
(2) microscope slightly focuses on: start the camera collection video, adopt the grey scale difference evaluation function and climb the mountain fast and recall searching algorithm and carry out coarse focus;
(3) microscope fine focus: adopt evaluation function and the long search strategy of small step to carry out fine focus based on the laplace operator.
According to another embodiment of the invention; Further comprise said objective table initial position setting, confirm that this position generally is positioned at the micro objective below by the limit switch that photoelectric sensor constitutes; Apart from micro objective lower plane 0.1mm; This position can change to some extent when adopting different microscopes, objective table or slide, and photoelectric sensor sends signal and gives controller behind the arrival initial position, the stop motion of controller control motor.
According to another embodiment of the invention, comprise that further said microscope slightly focuses on, and comprises the steps:
(1) setting search step-length S
0With decision-making factor threshold value Th: step-size in search is that microscope stage stops the distance of moving during this for the first time from the setting in motion to the post exercise, and decision-making factor threshold value Th representative value can get 0.02, when adopting different focusing evaluation functions, can change to some extent;
(2) start the camera collection video;
(3) the motor-driven objective table along the Z axle with step-length S
0Carry out search by hill climbing, every observation position motor stop motion in the search procedure is taken out the two field picture in the internal memory and is calculated definition values, and the present invention requires the definition values Y of three adjacent observation positions of search procedure record
L, Y
MAnd Y
R, and calculate the decision-making vitamin T, said definition values also promptly focuses on the evaluation function measure value, calculates as follows:
Step 1, the image pre-service: said image is carried out medium filtering and gaussian filtering, with filtering noise to focusing on the measure value influence of evaluation function;
Step 2, calculate the definition values of image after the pre-service: establish that the image length and width are M * N after the said pre-service, (x y) is pixel (x, the gray-scale value of y) locating, then evaluation function Y to v
LExpression formula is (Y as follows
MAnd Y
RCalculate according to identical formula):
Said decision-making vitamin T calculates according to following formula:
(4) search procedure decision-making: judge the magnitude relationship and the relation of the factor with threshold value of making a strategic decision between definition values, based on the strategy of these relation decision search, specifically decision-making is as follows:
If Y
L<Y
M<Y
R, perhaps T<Th then continues towards former direction search;
If Y
R<Y
L, and T>Th, then stop towards former direction search;
(5) calculate layback: utilizing climbs the mountain fast recalls searching algorithm and confirms the distance value that need return after the search procedure " top more ";
(6) recall fast: calculate layback S
bAfter, the motor-driven objective table is pressed and former direction move distance S in the opposite direction along the Z axle
bAnd stop, this moment, objective table arrived near the focal plane.
According to another embodiment of the invention, further comprise said microscope fine focus, comprise the steps:
(1) obtains a two field picture: from current internal memory, extract a two field picture as pending image;
(2) the long search by hill climbing of small step: with the long S of small step
1Carry out search by hill climbing, generally get
Every observation position motor stop motion in the search procedure is taken out the two field picture in the internal memory and is calculated definition values, and the present invention requires the definition values Y of two adjacent observation positions of search procedure record
LAnd Y
R, Y wherein
LPairing picture numbers is positioned at Y
RBefore the pairing picture numbers, said definition values also promptly focuses on the evaluation function measure value, calculates as follows:
Step 1, the image pre-service: pending image is carried out medium filtering and gaussian filtering, with filtering noise to focusing on the measure value influence of evaluation function;
Step 2 is calculated and is focused on the evaluation function measure value: to the focusing evaluation function measure value Y of pretreated image calculation based on the Laplace evaluation function
L, establishing said image length and width is M * N, (x y) is pixel (x, the gray-scale value of y) locating, then evaluation function Y to v
LExpression formula is (Y as follows
RPressing the same manner calculates):
(3) search procedure decision-making: judge the magnitude relationship between definition values, based on the strategy of these relation decision search, specifically decision-making is as follows:
If Y
L<Y
R, then continue towards former direction search;
If Y
L>Y
R, then stop towards former direction search, found the focal plane this moment.
According to another embodiment of the invention; Further comprise the described back-track algorithm of climbing the mountain fast; It is the fast search algorithm of extreme value in a kind of microscope automatic focus process; This algorithm, makes after the search procedure " top more " and can return near the extreme point with a step with the relation between " top more " back layback with reasonable assumption and the approximate evaluation function measure value of having set up.According to optical imaging concept, desirable focusing evaluation function curve should satisfy unimodal symmetry, establishes the search by hill climbing process successively through a P
L, P
MAnd P
R, three point coordinate are respectively (X
L, Y
L), (X
M, Y
M), (X
R, Y
R), step-size in search is S
0, maximum point P to be searched
ACoordinate is (X
A, Y
A).Layback S then
bWith sharpness measure value Y
L, Y
R, Y
MAnd initial step length S
0Between concern S
b=f (Y
L, Y
M, Y
R, S
0) as follows:
The invention has the beneficial effects as follows; One aspect of the present invention has improved the automaticity that microscope focuses on; Solved traditional focus method focusing speed on the other hand and be absorbed in problems such as local extremum, focusing accuracy are not high slowly, easily, had very high reliability and practicality, can be widely used in the microscopic system; This algorithm also has good universality simultaneously, can be applicable in the self-focusing picture system of some other needs.
Compared with prior art, the invention has the advantages that:
(1) the automatic focus process is divided into thick focusing and two stages of fine focus; The thick focusing stage adopts grey scale difference to focus on the evaluation function and the back-track algorithm of climbing the mountain fast; This has strengthened the real-time of system greatly; The fine focus stage is adopted focusing evaluation function and the long searching algorithm of small step based on the Laplace operator, has greatly strengthened the reliability of system;
(2) in thick focusing process, pass through to introduce the decision-making factor, avoided the extremum search process to be absorbed in local extremum, improved the reliability of auto-focusing algorithm greatly;
(3) in thick focusing process, adopt the back-track algorithm of climbing the mountain fast; Make after the search procedure " more top " and can return near the extreme point with a step; Improved greatly and returned step-length more behind the classical search by hill climbing algorithm " top " and be difficult to confirm and return problem such as search procedure complicated and time consumption, improved the real-time and the practicality of algorithm greatly.
Description of drawings
Below in conjunction with accompanying drawing and embodiment the present invention is further specified.
Fig. 1 is traditional automatic focus search by hill climbing algorithm synoptic diagram;
Fig. 2 is the microscope fast automatic focusing algorithm flow chart that the present invention proposes;
Fig. 3 is ideal focusing evaluation function curve and climbs the mountain fast and recall the search synoptic diagram: (a) climb the mountain for fast and recall first kind of situation of search; (b) recall second kind of situation of search for climbing the mountain fast;
Fig. 4 is one embodiment of the present of invention " automatic tubercle bacillus detector " software and hardware structure figure.
Embodiment
Combine accompanying drawing and preferred embodiment that the present invention is done further detailed explanation now.These accompanying drawings are the synoptic diagram of simplification, basic structure of the present invention only is described in a schematic way, so it only show the formation relevant with the present invention.
Like Fig. 2 is the microscope fast automatic focusing algorithm flow chart that the present invention proposes; A kind of fast automatic focusing method of microscope based on Flame Image Process; The automatic focus process is divided into thick focusing and two stages of fine focus; Adopt different focusing evaluation function and extremum search strategy in different stage, adopt the grey scale difference evaluation function and climb the mountain fast and recall searching algorithm, and the introducing factor of making a strategic decision prevents that searching algorithm is absorbed in local extremum in the thick focusing stage; Adopt evaluation function and the long search strategy of small step in the fine focus stage based on the laplace operator; Evaluation function half width based on the laplace operator is minimum, and sensitivity is higher, therefore can obtain higher precision in the fine focus stage.
The present invention includes following steps:
(1) objective table initial position setting: the motor-driven objective table moves to the initial position that pre-sets along the Z axle; Place microslide to be observed on the objective table; Said initial position is positioned near the microscope focal plane; Generally be positioned at the focal plane upside, this initial position is as self-focusing starting point;
(2) microscope slightly focuses on: start the camera collection video, adopt the grey scale difference evaluation function and climb the mountain fast and recall searching algorithm and carry out coarse focus;
(3) microscope fine focus: adopt evaluation function and the long search strategy of small step to carry out fine focus based on the laplace operator.
Said objective table initial position setting; Limit switch by photoelectric sensor constitutes is confirmed; This position generally is positioned at the micro objective below, and apart from micro objective lower plane 0.1mm, this position can change to some extent when adopting different microscopes, objective table or slide; Photoelectric sensor sends signal to controller after arriving initial position, the stop motion of controller control motor.
Said microscope slightly focuses on, and comprises the steps:
(1) setting search step-length S
0With decision-making factor threshold value Th: step-size in search is that microscope stage stops the distance of moving during this for the first time from the setting in motion to the post exercise; In operating process; This step-length is generally expressed with umber of pulse, and therefore concrete numerical value follows the correlation parameter of the controller, driver and the motor that are adopted relevant, and the value of this step-length is also determining the real-time and the robustness of algorithm to a certain extent simultaneously; Therefore must constitute through testing definite according to real system; This step-length to the general influence of algorithm is: step-length is too little, causes algorithm consuming time serious, is absorbed in local extremum easily in the focusing incipient stage simultaneously; Step-length is excessive, causes search procedure very easily " top more ", if " top more " is very serious; Then cause algorithm to restrain; The representative value of step-length can get 300, and decision-making factor threshold value Th follows the focusing evaluation function that is adopted relevant, and decision-making factor threshold value Th can value be 0.02 when adopting grey scale difference to focus on evaluation function; Equally, this threshold value can be changed with the focusing evaluation function value that is adopted according to the system configuration of reality;
(2) start the camera collection video: camera in internal memory, can be opened up a region of memory earlier, based on different requirement with video acquisition in computer; The video flowing of being gathered all can be deposited in internal memory or other storage mediums; Such as hard disk, also can only deposit a two field picture, when also promptly beginning the current frame image collection former frame image is override; The internal memory that is consumed is minimum like this, generally adopts this mode;
(3) begin rough automatic focus: the motor-driven objective table along the Z axle with step-length S
0Carry out search by hill climbing; Every observation position motor stop motion in the search procedure; Take out the two field picture in the internal memory and calculate the focusing evaluation function measure value (also claiming definition values) based on grey scale difference, the present invention requires the definition values Y of three adjacent observation positions of search procedure record
L, Y
MAnd Y
R, and calculate the decision-making vitamin T, concrete steps are following:
Step 1, the starter motor driving objective table axially descends move distance S along Z
0
Step 2 waits for a period of time to guarantee that the image acquisition process exposure finishes, and there is relation the stand-by period, general desirable 50ms with the camera exposure time;
Step 3 is taken out a two field picture as pending image from internal memory;
Step 4, pending image is carried out pre-service: at first carry out medium filtering, the filtering template size is got 5*5, carries out gaussian filtering then, the filtering template size is also got 5*5, like this can filtering noise to focusing on the measure value influence of evaluation function;
Step 5, calculate the definition values of image after the pre-service: establish that the image length and width are M * N after the said pre-service, (x y) is pixel (x, the gray-scale value of y) locating, then evaluation function Y to v
RExpression formula is following:
Step 6, the motor-driven objective table axially descends move distance S along Z
0, handle according to step 2 to step 5 again then, different is, and that to calculate in step 5 is Y
MValue, computing method are with Y
RComputing method identical;
Step 7 is calculated the decision-making vitamin T, and computing formula is following:
Step 8, search procedure is tentatively made a strategic decision: follow the direction and the search procedure of the relation decision search between decision-making factor threshold value whether to stop concrete the decision-making as follows according to the decision-making factor values:
If T<Th then continues towards former direction search;
If T>Th then stops towards former direction search;
Step 9 is if continue towards former direction search, then with Y
MValue compose to Y
L, then with Y
RValue compose to Y
M, also be Y
LValue by Y
MOverride, and Y
MValue by Y
ROverride;
Step 10 is then handled according to step 2 to step 9 towards former direction search if continue again;
Step 11, search procedure is made a strategic decision again: judge the magnitude relationship and the relation of the factor with threshold value of making a strategic decision between definition values, according to the strategy of these relation decision search, specifically decision-making is as follows:
If Y
L<Y
M<Y
R, perhaps T<Th then continues towards former direction search;
If Y
R<Y
L, and T>Th, then stop towards former direction search;
Step 12 is then calculated layback if stop towards former direction search; Computation process adopts to climb the mountain fast recalls searching algorithm; Said climbing the mountain fast recalled searching algorithm, is the fast search algorithm of extreme value in a kind of microscope automatic focus process, and this algorithm is started with from analyzing focusing evaluation function tracing pattern;, make after the search procedure " top more " and can return near the extreme point with the relation between " top more " back layback with reasonable assumption and the approximate evaluation function measure value of having set up with a step.According to optical imaging concept, desirable focusing evaluation function curve should satisfy unimodal symmetry, and Fig. 2 has provided ideal focusing evaluation function curve, establishes the search by hill climbing process successively through a P
L, P
MAnd P
R, three point coordinate are respectively (X
L, Y
L), (X
M, Y
M), (X
R, Y
R), step-size in search is S
0, maximum point P to be searched
ACoordinate is (X
A, Y
A).Layback S then
bWith sharpness measure value Y
L, Y
R, Y
MAnd initial step length S
0Between concern S
b=f (Y
L, Y
M, Y
R, S
0) as follows:
If Y
L<Y
R<Y
M, maximum point P then is described
AAt a P
MThe right side, like Fig. 3 (a), at this moment
If Y
R<Y
L<Y
M, maximum point P then is described
AAt a P
MThe left side, like Fig. 3 (b), at this moment
Step 13 is recalled: calculate layback S fast
bAfter, the motor-driven objective table is pressed and former direction move distance S in the opposite direction along the Z axle
bAnd stop, this moment, objective table arrived near the focal plane, and the coarse focus process finishes.
Said microscope fine focus comprises the steps:
(1) obtains a two field picture: from current internal memory, extract a two field picture as pending image;
(2) the long search by hill climbing of small step: with the long S of small step
1Carry out search by hill climbing, generally get
Every observation position motor stop motion in the search procedure is taken out the two field picture in the internal memory and is calculated definition values, and the present invention requires the definition values Y of two adjacent observation positions of search procedure record
LAnd Y
R, Y wherein
LPairing picture numbers is positioned at Y
RBefore the pairing picture numbers, said definition values also promptly focuses on the evaluation function measure value, calculates as follows:
Step 1, the image pre-service: pending image is carried out medium filtering and gaussian filtering, with filtering noise to focusing on the measure value influence of evaluation function;
Step 2 is calculated and is focused on the evaluation function measure value: to the focusing evaluation function measure value Y of pretreated image calculation based on the Laplace evaluation function
L, establishing said image length and width is M * N, (x y) is pixel (x, the gray-scale value of y) locating, then evaluation function Y to v
LExpression formula is (Y as follows
RPressing the same manner calculates):
(3) search procedure decision-making: judge the magnitude relationship between definition values, based on the strategy of these relation decision search, specifically decision-making is as follows:
If Y
L<Y
R, then continue towards former direction search;
If Y
L>Y
R, then stop towards former direction search, found the focal plane this moment.
The described back-track algorithm of climbing the mountain fast; It is the fast search algorithm of extreme value in a kind of microscope automatic focus process; This algorithm, makes after the search procedure " top more " and can return near the extreme point with a step with the relation between " top more " back layback with reasonable assumption and the approximate evaluation function measure value of having set up.According to optical imaging concept, desirable focusing evaluation function curve should satisfy unimodal symmetry, establishes the search by hill climbing process successively through a P
L, P
MAnd P
R, three point coordinate are respectively (X
L, Y
L), (X
M, Y
M), (X
R, Y
R), step-size in search is S
0, maximum point P to be searched
ACoordinate is (X
A, Y
A).Layback S then
bWith sharpness measure value Y
L, Y
R, Y
MAnd initial step length S
0Between concern S
b=f (Y
L, Y
M, Y
R, S
0) as follows:
One embodiment of the present of invention are:
The method is applied in " automatic tubercle bacillus detector " that we research and develop voluntarily, and this system is made up of PC, full microscope, video camera, printer and picture and text analysis software, system architecture such as Fig. 4.Wherein video camera adopts the HV3103UC of Beijing company of Daheng; Full microscope comprises light path part and mechanical part; Wherein light path part adopts the BA3000i of Chongqing photoelectric instrument company; Mechanical part requires design voluntarily by us according to the full microscope motion control; Comprise: controller, driver, stepper motor, program-controlled objective table etc., this part can be accomplished microscopical automatic three stereo-motions control, comprise that the control microscope carries out automatic focus and according to preset scanning pattern slide carried out automatically scanning etc.
Automatic focus certain applications in this system our foregoing invention " based on the fast automatic focusing method of microscope of Flame Image Process "; After the system start-up, microscope stage moves to initial position under the driving of motor, this initial position next-door neighbour micro objective below; Apart from micro objective lower plane 0.1mm; After starting auto-focus function, microscope stage begins coarse focus along the Z axle with step-length 300 under the driving of motor, and the focusing process can be accomplished in 2 seconds; System started the fine focus process automatically after coarse focus was accomplished; The fine focus process can be accomplished in 1 second, and therefore whole focusing process can be accomplished in 3 seconds, and focusing accuracy is very high.Need to prove that being provided with of initial position is very crucial, improper if initial position is provided with, then accumulation process need expend the long time, but the focusing process still can accomplish smoothly, focusing accuracy is also unaffected.
We rely on to have carried out a large amount of tests; The result shows; The fast automatic focusing method of microscope that we propose has well solved the traditional algorithm focusing speed and has been absorbed in local extremum slowly, easily; The problem that focusing accuracy is not high has very high reliability, practicality and admissibility.
With above-mentioned foundation desirable embodiment of the present invention is enlightenment, and through above-mentioned description, the related work personnel can carry out various change and modification fully in the scope that does not depart from this invention technological thought.The technical scope of this invention is not limited to the content on the instructions, must confirm its technical scope according to the claim scope.