Image definition evaluation method for three-dimensional object
Technical Field
The invention relates to the field of computer vision technology and image processing, and designs an image definition evaluation method for a three-dimensional object.
Background
With the application and development of machine vision, the acquisition of high-definition images is of great significance in the field of industrial detection, in the industrial detection process, an experienced machine vision engineer mainly spends a long time to adjust a lens focusing ring to obtain clear images, and focusing results are different due to human factors, so that an imaging system does not reach an optimal use state, and therefore, the research of an automatic focusing technology is of great significance. An important ring of the automatic focusing technology is the evaluation of image definition, and the quality of an image definition evaluation function directly influences the automatic focusing precision. Most of the image definition evaluation functions proposed at home and abroad aim at the whole image, different planes have different definitions for a three-dimensional object, and different planes have different definition requirements according to specific requirements, so that the aim of global definition evaluation on the whole image cannot be achieved. The invention carries out local evaluation on the interested area and can solve the problems.
Disclosure of Invention
In order to solve the problems, the invention provides an image definition evaluation method based on a three-dimensional object, which utilizes an automatic focusing device, wherein the automatic focusing device comprises a steering engine, a camera, a focusing ring and a workbench, the focusing ring is connected to the camera, the focusing ring carries out focusing through the steering engine, the workbench is positioned below the focusing ring, and an object to be measured is placed on the workbench, and the method is characterized by comprising the following steps:
(1) starting a steering engine to enable a focusing ring to rotate, triggering a camera to collect a group of images at fixed time intervals, enabling the definition of the images to be from fuzzy to clear and then to be fuzzy, and recording scale values corresponding to each photo; the manual setting is carried out by an industrial personal computer at fixed time intervals;
(2) preprocessing each image, wherein the preprocessing comprises median filtering to remove noise, and threshold segmentation is used for carrying out binarization processing on the images;
(3) performing Canny edge detection on the preprocessed image, and extracting the image edge;
(4) extracting gray values in a fixed range in the interested edge normal direction, wherein the fixed range is formed by extending pixel points with the same length from edges to two sides, and taking the obtained gray values as a point set;
(5) performing curve fitting by using a least square method to obtain an index coefficient D serving as an index for evaluating the image definition;
(6) outputting the index coefficient D of each interested area, and taking the average value as the definition evaluation index of the image;
(7) and comparing the indexes of each image to obtain the clearest image and enabling the focusing ring to rotate to the specified position.
The curve fitting method in the step (5) is as follows:
the curve function is of the form:
wherein y represents the gray value at the x position, A, B, C, D, E is the parameter to be determined; set point set as { (x)1,y1),(x2,y2),…,(xn,yn) The objective function is:
is provided with
Using least squaresThe normal non-linear fitting method finds the parameter A, B, C, D, E such that L is minimized. The invention fits the curve by calling the nlnfit function in MATLAB.
The invention has the advantages that the local evaluation can be carried out on the specific area, and the requirement of accurate evaluation definition can be met aiming at specific requirements.
Drawings
Fig. 1 shows an automatic focusing mechanism designed by the present invention.
FIG. 2 is a flowchart illustrating operation of an embodiment of the present invention.
Fig. 3 is a diagram of the function variation corresponding to different exponential coefficients D.
Fig. 4 shows workpieces with different degrees of sharpness.
Fig. 5 is a pre-processed image.
Fig. 6 is an image after edge detection.
FIG. 7 is a gray value array of the four interested edges in the left image of FIG. 4 in the fixed range in the normal direction and the fitting result.
FIG. 8 is a gray value array of the four interested edges in the right image of FIG. 4 in the fixed range in the normal direction and the fitting result.
FIG. 9 is a graph of a set of images evaluating sharpness.
Detailed Description
Example (b):
as shown in figure 1, an automatic focusing device is designed, the automatic focusing device comprises a steering engine 1, a camera 2, a focusing ring 3 and a workbench 4, the focusing ring 3 is connected to the camera 2, the focusing ring 3 carries out focusing through the steering engine 1, the workbench 4 is located below the focusing ring, and an object 5 to be measured is placed on the workbench 4. Starting the steering engine 1 to enable the focusing ring 3 to rotate, collecting a group of images, evaluating the collected images to obtain the image with the highest definition, and enabling the focusing ring 3 to rotate to the corresponding position by using the steering engine 1 to finally achieve the purpose of automatic focusing.
The invention will now be described in more detail by way of example with reference to the accompanying drawings.
This example acquires a total of 23 images with different degrees of blur. As shown in fig. 4, 2 images were selected for display. The specific operation process of the invention is as follows:
the method comprises the following steps: the industrial personal computer controls the steering engine to drive the focusing ring to rotate, and triggers the camera to collect a group of images, so that the definition of the images is changed from fuzzy to clear and then fuzzy, and the scale value corresponding to each photo is recorded.
Step two: each image is preprocessed, wherein the preprocessing includes median filtering to remove noise, and the threshold segmentation is used for carrying out binarization processing on the images, as shown in fig. 5.
Step three: and carrying out Canny edge detection on the preprocessed image, and extracting the image edge. As shown in fig. 6.
Step four: extracting the gray values in the fixed range in the normal direction of the edge of interest, as shown in fig. 3, sorting the gray values from left to right or from top to bottom in the normal direction to form an array, fitting the array by using a least square fitting method, in this embodiment, selecting 40 pixels on the left and right of the edge, and extracting the gray values of the 80 pixels as a point set, as shown in fig. 7 and 8.
Step five: and performing curve fitting on the point set, wherein the function form of the curve fitting is as follows:
the larger the value of D, the larger the slope of the curve, the larger the gray scale change, and the sharper the image. As shown in fig. 6 and 7, the gray value in the edge range corresponding to the blurred image in the left image of fig. 4 changes smoothly, the slope of the fitted curve is small, the gray value in the edge range corresponding to the sharp image in the right image of fig. 4 changes steeply, and the slope of the fitted curve is large.
Step six: the D values obtained from the four regions of each image are averaged to serve as the evaluation index of the image, and the indexes obtained from the 23 images are output and plotted in a graph, as shown in fig. 9. It can be seen that the invention has the advantages of strong unimodal property and high sensitivity. The focusing ring is rotated to the position where the image is clearest, the workpiece is moved to any position, and the parameters obtained by the algorithm are unchanged, so that the stability of the algorithm is high.