An image autofocusing method and processing terminal for an imaging device
By combining hill-climbing and simulated annealing algorithms, adaptively adjusting the step size, and comprehensively evaluating image features, the problems of inaccurate focusing and slow speed in existing technologies are solved. This achieves automatic focusing that quickly finds the global optimal solution and adapts to optimal focusing under various conditions.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU BAOLUN ELECTRONICS CO LTD
- Filing Date
- 2024-10-10
- Publication Date
- 2026-06-30
Smart Images

Figure CN119110164B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, specifically to an image autofocusing method and processing terminal for an imaging device. Background Technology
[0002] Autofocus technology is widely used in various optical devices, including imaging devices such as cameras, microscopes, and telescopes. By integrating autofocus technology into these devices, consumers can easily capture or observe clearly focused images automatically. For imaging devices, which are among the most widely used everyday electronic devices, autofocus technology is even more significant. To ensure the effectiveness of autofocus in imaging devices, the first step is to evaluate the focus of the captured image. Only images that pass the focus evaluation can guarantee a clear image from autofocus. The next step is to further implement autofocus based on the focus evaluation.
[0003] Existing focus evaluation methods often use a single parameter for assessment, such as evaluating focus solely based on the sharpness of image pixels. Using such a single parameter to evaluate focus performance has limitations, leading to inaccurate focusing results. For example, it is difficult to determine the focusing quality of an imaging device's lens at different locations within a captured image.
[0004] Furthermore, automatic focusing based on existing focusing evaluation methods struggles to find the optimal focusing position, making it difficult to obtain the clearest and highest-quality image. Even when a reasonably clear, high-quality image is achieved, the use of a single algorithm—for example, a hill-climbing algorithm—leads to slow search speeds due to the inability to quickly find the second convergence condition, resulting in slow autofocus and image capture. This poses a problem for applications with high time sensitivity. Additionally, it often gets bogged down in finding local optima, failing to find the global optimum (the best focusing point globally), thus impacting the final focusing effect and image quality. Summary of the Invention
[0005] To address the shortcomings of existing technologies, the present invention aims to provide an image autofocusing method and processing terminal for an imaging device, which can solve the problems described in the background art.
[0006] The technical solution to achieve the objective of this invention is: an image autofocusing method for an imaging device, comprising the following steps:
[0007] Step 1: Obtain several target images;
[0008] Step 2: Randomly generate a parameter set that characterizes the lens physical parameters of the imaging device;
[0009] Step 3: Based on the parameter set as the initial position of the lens, the neighborhood generation rule is used to perform operations on the preset step size at the initial position to generate a neighborhood, and each neighborhood corresponds to a lens position.
[0010] Step 4: Starting from the initial position of the lens, acquire the target image corresponding to each lens position, calculate the focus effect evaluation value of each target image, and evaluate the quality of the focus effect by comparing the magnitude of the focus effect evaluation values corresponding to different lens positions.
[0011] Step 5: Optimize the focusing effect of the target image at each lens position based on the hill-climbing algorithm to obtain the locally optimal lens position;
[0012] Step 6: Process the local optimum solution based on the simulated annealing algorithm to obtain the optimum solution, which is the optimum lens position. The parameter set corresponding to the optimum lens position is used as the shooting parameters for autofocus. The imaging device performs autofocus based on these shooting parameters.
[0013] Furthermore, in step 1, at least two different target images are included. Different target images refer to images obtained by shooting the same target object from different shooting angles. After obtaining the target images, the target images are further preprocessed. The preprocessing includes one or more of the following: normalization, noise reduction, cropping, scaling, and grayscale processing.
[0014] Furthermore, in step 2, the lens physical parameters include focal length, aperture, and focusing distance of the aperture. These parameters are integers, calculated based on the lens physical parameters using a preset mathematical formula.
[0015] The integer is calculated based on the lens's physical parameters according to a preset mathematical formula. Its specific implementation process includes:
[0016] The adjustable focal length range is divided into several equally spaced intervals, and each interval is numbered.
[0017] The adjustable aperture range is divided into several equally spaced intervals, and each interval is numbered.
[0018] The adjustable range of the focus distance is divided into several equally spaced intervals, and each interval is numbered.
[0019] All numbers are positive integers.
[0020] The parameter set is calculated using the following mathematical formula:
[0021] Parameter group = focal length number * A + aperture number * B + focusing distance * C,
[0022] In the formula, A, B and C are all preset constants.
[0023] Furthermore, in step 3, the operation includes addition and subtraction operations, so that the position obtained by adding or subtracting a preset step size based on the initial position of the lens is the corresponding neighborhood, and the position of the neighborhood is the lens position corresponding to the neighborhood.
[0024] Furthermore, in step 3, the preset step size is adaptively adjusted based on the operation calculation to adapt to changes in the focusing effect evaluation. If the changes in the focusing effect evaluation are small, the preset step size changes small; if the changes in the focusing effect evaluation are large, the preset step size changes large.
[0025] Furthermore, the change in the focus effect evaluation is represented by the rate of change. Let Fi be the focus effect evaluation at the i-th lens position, then the rate of change Fratti for the i-th focus effect evaluation is given by the following formula:
[0026] Fratei=(Fi-Fi-1) / Fi-1
[0027] If Fratti > the first preset threshold F1 > 0, then the preset step size for the i-th step is increased based on the previous step size, and the increase rate is equal to Fratti.
[0028] If Fratti < the second preset threshold F2 < 0, then the preset step size for the i-th step is reduced based on the previous step size, and the reduction rate is equal to Fratti.
[0029] If F2 < Fratti < F1, then the preset step size for the i-th iteration remains unchanged, which is equal to the preset step size of the previous iteration.
[0030] Furthermore, in step 4, the focusing effect evaluation value F is calculated according to formula ①:
[0031] F=ω1×S+ω2×C+ω3×E+ω4×D+ω5×G------①
[0032] In the formula, ω1-ω5 represent the weight coefficients of the corresponding parameters, S represents the sharpness value of the target image, C represents the contrast of the target image, E represents the entropy of the target image, D represents the sharpness difference measure of the target image, and G represents the standard deviation of the gradient magnitude of the target image.
[0033] Further, in step 5, the preprocessed target image, the parameter set, the preset step size, and the focus effect evaluation value are used as inputs to the hill-climbing algorithm, including:
[0034] Starting from the initial shot position, a neighborhood solution is generated according to the neighborhood generation rule. Then, the target image corresponding to the shot position of each neighborhood solution is obtained from the target image set, thereby obtaining the focus effect evaluation value corresponding to each target image.
[0035] Starting with the target image corresponding to the initial lens position, the focus effect evaluation value of the current lens position is compared with the focus effect evaluation value of the target image corresponding to the next lens position. If the focus effect evaluation value of the next lens position is better than the focus effect evaluation value of the current lens position, the next lens position is updated to the neighborhood solution of the current lens position. This search continues until no better focus effect evaluation value can be found. At this point, a local optimum is reached, thus finding the locally optimum lens position.
[0036] Furthermore, in step 6, the local optimum is processed using the simulated annealing algorithm to obtain the optimal solution. The specific implementation process includes the following steps:
[0037] Step S1: Use the local optimal solution output by the hill climbing algorithm as the current solution L_current;
[0038] Step S2: Within a large range of the current solution, randomly generate a new lens position L_new according to the probability distribution and use it as a new solution. Compare the focus effect evaluation values corresponding to the current solution L_current and the new solution L_new, and calculate the difference ΔF between the two focus effect evaluation values.
[0039] Step S3: If ΔF < 0, it indicates that the focusing effect evaluation value corresponding to the lens position L_new is better, that is, the new solution is better than the current solution. Therefore, the new solution L_new is used to replace the original current solution L_current, and the new solution L_new is used as the current solution. Then, proceed to step S6.
[0040] If ΔF > 0, the probability of accepting a new solution is determined based on the current temperature T of the simulated annealing algorithm. The probability P of accepting a new solution is calculated using the Boltzmann probability distribution formula, which is shown below: P = exp(-ΔF / T).
[0041] Generate a random number r. If r < P, then accept the new solution L_new as the current solution L_current; if r ≥ P, then keep the current solution L_current unchanged.
[0042] Step S6: Press T t+1 =T t ×α updates the temperature at the next moment, T. t T represents the current temperature. t+1The temperature at the next moment is represented by α, which represents the temperature decay coefficient. Based on the new temperature, it is determined whether the simulated annealing algorithm meets the termination condition: the current temperature drops below the preset temperature threshold T_min, or the number of consecutive iterations of the simulated annealing algorithm exceeds the preset number of iterations threshold and no better solution is found. When the simulated annealing algorithm terminates, its output current solution is taken as the final optimal solution of the simulated annealing algorithm. This optimal solution is also the parameter set required for the final autofocus shooting of the lens.
[0043] A processing terminal, comprising:
[0044] Memory, used to store program instructions;
[0045] A processor for running the program instructions to perform the steps of the image autofocusing method of the imaging device.
[0046] The beneficial effects of this invention are: This invention can effectively find the globally optimal focusing parameters, ensuring that the image captured under this focusing is the clearest, and combines the hill-climbing algorithm and the simulated annealing algorithm to achieve automatic focusing.
[0047] Existing single hill-climbing algorithms are prone to getting stuck in local optima, while single simulated annealing algorithms, although capable of escaping local optima to some extent, may be somewhat blind in the early stages of the search. This technical solution combines hill-climbing and simulated annealing algorithms. After the hill-climbing algorithm initially finds a local optimum, the simulated annealing algorithm can accept poor solutions with a certain probability, thus increasing the likelihood of exploring a globally better solution and greatly improving the global search capability.
[0048] A single hill-climbing algorithm may slow down its convergence speed when approaching the optimal solution due to its fixed step size and limited search range. Simulated annealing algorithms have a wider search range at higher temperatures, but their convergence speed gradually decreases as the temperature drops. In this technical solution, the hill-climbing algorithm uses an adaptive step size adjustment strategy to dynamically adjust the search step size based on the focusing effect evaluation, quickly finding a local optimum. This allows for flexible adaptation at different search stages, improving search efficiency and providing a better starting point for the simulated annealing algorithm. It also reduces the blind search inherent in simulated annealing, thereby accelerating the overall convergence speed and enhancing the overall real-time performance.
[0049] In practical applications, image quality and lighting conditions may vary. Individual hill-climbing and simulated annealing algorithms are relatively weak at adapting to these changes. This technical solution, by combining the advantages of both algorithms, can better cope with various complex situations and interference factors. Even under unfavorable conditions, it can find a better focusing position and has stronger robustness.
[0050] Existing single algorithms may perform well in specific image types or shooting environments, but poorly in others. This technical solution, by fusing two algorithms, can adapt to a wider range of image types, shooting scenes, and device conditions. Whether the image is simple or has complex textures, whether the environment is bright or the scene is dim, it can effectively achieve autofocus, thus having broader applicability. Attached Figure Description
[0051] Figure 1 A flowchart illustrating the image focus evaluation method;
[0052] Figure 2 A flowchart illustrating the method for achieving image autofocus;
[0053] Figure 3 This is a flowchart illustrating the principle framework of the present invention;
[0054] Figure 4 This is a schematic diagram of the processing terminal. Detailed Implementation
[0055] The present invention will be further described below with reference to the accompanying drawings and specific embodiments:
[0056] like Figures 1-4 As shown, an image autofocusing method for an imaging device includes the following steps:
[0057] Step 1: The imaging device takes pictures of the same target object from at least two different shooting angles to obtain a target image set, which includes at least two target images containing the target object.
[0058] The target object can be a plant, an animal, or a scene, such as a cloud in the sky or a chair by the river.
[0059] By using the same imaging device to photograph the same target object from different shooting angles, a series of images can be obtained, which constitute the target image set.
[0060] Preprocessing is performed on all target images in the target image set to obtain preprocessed target images and a preprocessed target image set. Preprocessing includes one or more of the following: normalization, denoising, cropping, scaling, and grayscale conversion.
[0061] The process includes several steps: Normalization, which limits the pixel values of the target image to a preset range (e.g., normalizing all pixel values to the [0, 1] interval); Denoising, which filters out noise interference in the target image to make the edges and details clearer and avoid misjudgments in subsequent focus evaluation; Cropping and scaling, which remove irrelevant areas from the target image, allowing focus evaluation and autofocus calculations to focus on key areas for more accurate focus assessment; and Grayscale conversion, which reduces computational complexity.
[0062] Step 2: Randomly generate a parameter set representing the lens physical parameters of the imaging device, including focal length, aperture, and aperture focusing distance.
[0063] For example, the parameter set of the lens physical parameters is an integer, which is calculated based on the lens physical parameters according to a preset mathematical formula.
[0064] For example, if a lens's focal length is adjustable from 50mm to 200mm, this range can be divided into several intervals, such as 50 equal intervals, each representing a 3mm variation. These 50 intervals can be numbered, for example, from 1 to 50, in ascending order of focal length. If the lens's aperture is adjustable from F1.4 to F16, it can be divided into several equal intervals, such as 6 equal intervals, numbered 1-6. If the focusing distance is adjustable from 0.5 to 10m, it can be divided into 20 equal intervals, numbered 1-20. Thus, a parameter set can be generated based on these lens physical parameters. For example, the parameter set can be calculated using the following mathematical formula: Parameter set = Focal length number * 120 + Aperture number * 4 + Focusing distance number. By randomly generating a set of parameter values, which are random numbers, and then using the mathematical formula based on these random numbers, the focal length number, aperture number, and focus distance number can be calculated. This allows us to determine the specific values of the focal length, aperture, and focus distance, and thus determine the lens's physical parameters based on this set of parameters.
[0065] Of course, the random number needs to be generated randomly within the range of values in the parameter group, and the range of values in the parameter group is affected by the values of the physical parameters of each lens.
[0066] Step 3: Based on the randomly generated parameter set as the initial position of the lens, the neighborhood generation rule is used to perform operations on the preset step size at the initial position of the lens to generate a neighborhood, and each neighborhood corresponds to a lens position.
[0067] The operation includes addition and subtraction, that is, based on the initial camera position, the position obtained by adding or subtracting a preset step size is the corresponding neighborhood, and the position of the neighborhood is the camera position corresponding to the neighborhood.
[0068] The neighborhood generation rule can determine which locations near the initial shot position will be considered as neighborhood solutions.
[0069] For example, the preset step size is adaptively adjusted based on the operation calculation to adapt to changes in the focus effect evaluation. Small changes in the focus effect evaluation result in a small change in the preset step size, while large changes result in a large change in the preset step size. When the focus effect evaluation changes within a certain range with moderate fluctuations, the preset step size remains fixed.
[0070] For example, the focusing effect at the i-th lens position is evaluated as F. i Then the rate of change of the i-th focusing effect evaluation is Frat i The formula is as follows:
[0071] Frate i =(F i -F i-1 ) / F i-1
[0072] If Frat i If the first preset threshold F1 > 0, then the preset step size for the i-th step is increased based on the previous step size (i.e., i-1), and the increase rate is equal to Frate. i If Frate i If the second preset threshold F2 < 0, then the preset step size for the i-th step is reduced based on the previous step size, and the reduction rate is equal to Frate. i If F2 < Frate i If F < F1, the preset step size for the i-th iteration remains unchanged, which is equal to the preset step size of the previous iteration. When the rate of change in the focus effect evaluation exceeds a preset threshold greater than 0, it indicates a significant improvement in the focus effect evaluation, and the preset step size needs to be adaptively increased according to the magnitude of the improvement (i.e., the rate of change). When the rate of change in the focus effect evaluation is less than a preset threshold less than 0, it indicates a decrease in the focus effect evaluation or an insignificant improvement, and the preset step size needs to be adaptively decreased according to the magnitude of the decrease (i.e., the rate of change). When the rate of change in the focus effect evaluation is between these two preset thresholds, there is no need to increase or decrease the preset step size.
[0073] Step 4: Starting from the initial lens position, acquire the target image corresponding to each lens position, calculate the focus effect evaluation value for each target image, and evaluate the focus effect by comparing the magnitudes of the focus effect evaluation values corresponding to different lens positions. The focus effect evaluation value F is calculated according to formula ①:
[0074] F=ω1×S+ω2×C+ω3×E+ω4×D+ω5×G------①
[0075] In the formula, ω1-ω5 represent the weight coefficients of the corresponding parameters, S represents the sharpness value of the target image, C represents the contrast of the target image, E represents the entropy of the target image, D represents the sharpness difference measure of the target image, and G represents the standard deviation of the gradient magnitude of the target image.
[0076] S, C, E, D, and G can all be calculated using existing technologies, and therefore will not be elaborated upon here. For example, M and N are the number of rows and columns of the target image, respectively. M[i,j] represents the gradient magnitude at pixel coordinates (i,j). G x [i,j] 2 and G y [i,j] 2 These represent the horizontal gradient and the vertical gradient, respectively.
[0077] The focus effect of the target image is positively correlated with the focus effect evaluation value F. The larger the focus effect evaluation value F, the better the focus effect, and vice versa.
[0078] The above steps can evaluate the focus effect of an image. By combining parameters such as sharpness value, contrast, entropy, sharpness difference measure, and standard deviation of gradient magnitude, it can effectively evaluate the focus quality at various locations in the image, more accurately assess the focus effect at each location, and more realistically reflect the actual focus effect.
[0079] Furthermore, the hill-climbing algorithm is improved by adaptively adjusting the step size based on the focusing effect evaluation value, thereby improving search efficiency and accuracy and ensuring that local optima are found more quickly and accurately.
[0080] In order to achieve automatic focusing of the imaging device, the present invention, based on the above-mentioned focusing evaluation, further includes the following steps to achieve automatic focusing with optimal focusing effect.
[0081] Step 5: Optimize the focusing effect of the target image at each lens position based on the hill-climbing algorithm to obtain the locally optimal lens position.
[0082] For example, the preprocessed target image, the parameter set, the preset step size, and the focus effect evaluation value are used as inputs to the hill-climbing algorithm, thereby outputting a local optimal solution for the lens position.
[0083] Starting from the initial lens position, a neighborhood solution is generated according to the neighborhood generation rule, and the target image corresponding to the lens position of each neighborhood solution is obtained from the target image set, thereby obtaining the focusing effect evaluation value corresponding to each target image.
[0084] Starting with the target image corresponding to the initial lens position, the focus effect evaluation value of the current lens position is compared with the focus effect evaluation value of the target image corresponding to the next lens position. If the focus effect evaluation value of the next lens position is better than the focus effect evaluation value of the current lens position, the next lens position is updated to the neighborhood solution of the current lens position. This search continues until no better focus effect evaluation value can be found. At this point, a local optimum is reached, thus finding the locally optimum lens position.
[0085] For example, when calculating the focus effect evaluation value for each neighborhood location, the neighborhood generation task for the current lens location is assigned to multiple computing cores or threads. If there are 11 neighborhood solutions at the current location requiring focus effect evaluation values, the task can be evenly distributed among multiple cores. For instance, with four cores, each core is responsible for calculating the focus effect evaluation values for 2-3 neighborhood solutions, accelerating the overall calculation process and improving real-time performance. After the cores complete their calculations, shared memory is used to facilitate data exchange between cores. During parallel processing, task allocation is dynamically adjusted based on the calculation speed and task complexity of each core to ensure load balancing among them. A relevant monitoring mechanism is established to monitor computational demands in real time. When a preset threshold is exceeded, all cores are activated; otherwise, only some cores are activated to reduce power consumption.
[0086] Step 6: Process the local optimum solution based on the simulated annealing algorithm to obtain the optimum solution, which is the optimum lens position. The parameter set corresponding to the optimum lens position is used as the shooting parameters for autofocus. The imaging device performs autofocus based on these shooting parameters, that is, it takes pictures according to the focal length, aperture and focus distance determined by the optimum solution.
[0087] For example, the simulated annealing algorithm is used to process local optima to obtain the optimal solution. The specific implementation process includes the following steps:
[0088] Step S1: Take the local optimal solution output by the hill climbing algorithm as the current solution L_current;
[0089] Step S2: Within a large range of the current solution, randomly generate a new lens position L_new according to the probability distribution and use it as a new solution. Compare the focus effect evaluation values corresponding to the current solution L_current and the new solution L_new, and calculate the difference ΔF between the two focus effect evaluation values.
[0090] Step S3: If ΔF < 0, it indicates that the focusing effect evaluation value corresponding to the lens position L_new is better, that is, the new solution is better than the current solution. Therefore, the new solution L_new is used to replace the original current solution L_current, and the new solution L_new is used as the current solution. Then, step S6 is executed.
[0091] If ΔF > 0, the probability of accepting a new solution is determined based on the current temperature T of the simulated annealing algorithm. The probability P of accepting a new solution is calculated using the Boltzmann probability distribution formula, which is shown below: P = exp(-ΔF / T).
[0092] Generate a random number r. If r < P, then accept the new solution L_new as the current solution L_current; if r ≥ P, then keep the current solution L_current unchanged.
[0093] Step S6: Press T t+1 =T t ×α updates the temperature at the next moment, T. t T represents the current temperature. t+1 The value represents the temperature at the next moment, and α represents the temperature decay coefficient. Based on the new temperature, it is determined whether the simulated annealing algorithm meets the termination conditions. The termination conditions include: the current temperature drops below a preset temperature threshold T_min, or the number of consecutive iterations of the simulated annealing algorithm exceeds a preset iteration threshold and no better solution is found. When the simulated annealing algorithm terminates, its output current solution is taken as the final optimal solution of the simulated annealing algorithm. This optimal solution is also the parameter set required for the lens's final autofocus shooting.
[0094] For example, the final lens position information output by the simulated annealing algorithm is used as the optimal solution and fed back to the autofocus function in real time. The output final lens position is directly related to autofocus; it represents the position that allows the image to achieve the sharpest possible image under the current shooting conditions. When the simulated annealing algorithm converges and outputs the final lens position, this position corresponds to the position that achieves the optimal focus performance evaluation under the current conditions.
[0095] Based on the lens's physical characteristics and the control system's parameter settings, the lens position value can be converted into the corresponding focal length. Typically, the lens's control system has a mapping relationship that associates the lens position information with the actual focal length. Through this mapping relationship, the focal length at which the image is sharpest can be determined from the optimal lens position data output by the simulated annealing algorithm.
[0096] Through all the above steps, the optimal focusing parameters can be found, ensuring that the image captured under this focusing condition is the clearest. Furthermore, by combining the hill-climbing algorithm and the simulated annealing algorithm, automatic focusing can be achieved.
[0097] Existing single hill-climbing algorithms are prone to getting stuck in local optima, while single simulated annealing algorithms, although capable of escaping local optima to some extent, may be somewhat blind in the early stages of the search. This technical solution combines hill-climbing and simulated annealing algorithms. After the hill-climbing algorithm initially finds a local optimum, the simulated annealing algorithm can accept poor solutions with a certain probability, thus increasing the likelihood of exploring a globally better solution and greatly improving the global search capability.
[0098] A single hill-climbing algorithm may slow down its convergence speed when approaching the optimal solution due to its fixed step size and limited search range. Simulated annealing algorithms have a wider search range at higher temperatures, but their convergence speed gradually decreases as the temperature drops. In this technical solution, the hill-climbing algorithm uses an adaptive step size adjustment strategy to dynamically adjust the search step size based on the focusing effect evaluation, quickly finding a local optimum. This allows for flexible adaptation at different search stages, improving search efficiency and providing a better starting point for the simulated annealing algorithm. It also reduces the blind search inherent in simulated annealing, thereby accelerating the overall convergence speed and enhancing the overall real-time performance.
[0099] In practical applications, image quality and lighting conditions may vary. Individual hill-climbing and simulated annealing algorithms are relatively weak at adapting to these changes. This technical solution, by combining the advantages of both algorithms, can better cope with various complex situations and interference factors. Even under unfavorable conditions, it can find a better focusing position and has stronger robustness.
[0100] Existing single algorithms may perform well in specific image types or shooting environments, but poorly in others. This technical solution, by fusing two algorithms, can adapt to a wider range of image types, shooting scenes, and device conditions. Whether the image is simple or has complex textures, whether the environment is bright or the scene is dim, it can effectively achieve autofocus, thus having broader applicability.
[0101] like Figure 4 As shown, the present invention also provides a processing terminal 100, which includes:
[0102] Memory 101 is used to store program instructions;
[0103] The processor 102 is configured to run the program instructions to perform the steps of the image autofocus method of the imaging device.
[0104] The embodiments disclosed in this specification are merely illustrative of one aspect of the invention, and the scope of protection of the invention is not limited to these embodiments. Any other functionally equivalent embodiments fall within the scope of protection of the invention. Those skilled in the art can make various other corresponding changes and modifications based on the technical solutions and concepts described above, and all such changes and modifications should fall within the scope of protection of the claims of this invention.
Claims
1. An image autofocusing method of an imaging apparatus, characterized by, Includes the following steps: Step 1: Obtain several target images; Step 2: Randomly generate a parameter set that characterizes the lens physical parameters of the imaging device; Step 3: Based on the parameter set as the initial position of the lens, a neighborhood generation rule is used to perform operations on a preset step size at the initial position to generate a neighborhood. Each neighborhood corresponds to a lens position. The operation includes addition and subtraction, so that the position obtained by adding or subtracting a preset step size from the initial position of the lens is the corresponding neighborhood, and the position of this neighborhood is the lens position corresponding to that neighborhood. The preset step size is adaptively adjusted based on the operation calculation to adapt to changes in the focusing effect evaluation. If the changes in the focusing effect evaluation are small, the preset step size will change small; if the changes in the focusing effect evaluation are large, the preset step size will change large. Step 4: Starting from the initial position of the lens, acquire the target image corresponding to each lens position, calculate the focus effect evaluation value of each target image, and evaluate the quality of the focus effect by comparing the magnitude of the focus effect evaluation values corresponding to different lens positions. Step 5: Use the preprocessed target image, the parameter set, the preset step size, and the focus effect evaluation value as input to the hill-climbing algorithm, including: Starting from the initial lens position, a neighborhood solution is generated according to the neighborhood generation rule, and the target image corresponding to the lens position of each neighborhood solution is obtained from the target image set, thereby obtaining the focusing effect evaluation value corresponding to each target image; Starting from the target image corresponding to the initial lens position, the focus effect evaluation value of the current lens position is compared with the focus effect evaluation value of the target image corresponding to the next lens position. If the focus effect evaluation value of the next lens position is better than the focus effect evaluation value of the initial lens position, the next lens position is updated to the current lens position. This process continues until no better focus effect evaluation value can be found. At this point, a local optimum is reached, thus finding the local optimum lens position. Step 6: Process the local optimum solution based on the simulated annealing algorithm to obtain the optimum solution, which is the optimum lens position. The parameter set corresponding to the optimum lens position is used as the shooting parameters for autofocus. The imaging device performs autofocus based on the shooting parameters. The change in the focus effect evaluation is represented by the rate of change. Let Fi be the focus effect evaluation at the i-th lens position, then the rate of change Fratti for the i-th focus effect evaluation is given by the following formula: Fratei = (Fi - Fi-1) / Fi-1 If Fratti > the first preset threshold F1 > 0, then the preset step size for the i-th step is increased based on the previous step size, and the increase rate is equal to Fratti. If Fratti < the second preset threshold F2 < 0, then the preset step size for the i-th step is reduced based on the previous step size, and the reduction rate is equal to Fratti. If F2 < Fratti < F1, then the preset step size for the i-th iteration remains unchanged, which is equal to the preset step size of the previous iteration.
2. The image autofocusing method of the imaging device according to claim 1, characterized in that, In step 1, at least two different target images are included. Different target images refer to images obtained by shooting the same target object from different shooting angles. After obtaining the target images, the target images are further preprocessed. The preprocessing includes one or more of the following: normalization, noise reduction, cropping, scaling, and grayscale processing.
3. The image autofocusing method of the imaging device according to claim 1, characterized in that, In step 2, the lens physical parameters include focal length, aperture and focusing distance. The parameter set is an integer, which is calculated based on the lens physical parameters according to a preset mathematical formula. The integer is calculated based on the lens's physical parameters according to a preset mathematical formula. Its specific implementation process includes: The adjustable range of the focal length is divided into several intervals at equal intervals, and each interval is numbered. The adjustable range of the aperture is divided into several intervals at equal intervals, and each interval is numbered. The adjustable range of the focus distance is divided into several intervals at equal intervals, and each interval is numbered. All numbers are positive integers; The parameter set is calculated using the following mathematical formula: Parameter group = focal length number * A + aperture number * B + focusing distance * C; In the formula, A, B and C are all preset constants.
4. The image autofocusing method of the imaging device according to claim 1, characterized in that, In step 4, the focusing effect evaluation value F is calculated according to formula ①: - - - - - - ① In the formula, ω1-ω5 represent the weight coefficients of the corresponding parameters, S represents the sharpness value of the target image, C represents the contrast of the target image, E represents the entropy of the target image, D represents the sharpness difference measure of the target image, and G represents the standard deviation of the gradient magnitude of the target image.
5. The image autofocusing method of the imaging device according to claim 1, characterized in that, In step 6, the local optimum is processed using the simulated annealing algorithm to obtain the optimal solution. The specific implementation process includes the following steps: Step S1: Use the local optimal solution output by the hill climbing algorithm as the current solution L_current; Step S2: Within a large range of the current solution, randomly generate a new lens position L_new according to the probability distribution and use it as a new solution. Compare the focus effect evaluation values corresponding to the current solution L_current and the new solution L_new, and calculate the difference ΔF between the two focus effect evaluation values. Step S3: If ΔF < 0, it indicates that the focusing effect evaluation value corresponding to the lens position L_new is better, that is, the new solution is better than the current solution. Therefore, the new solution L_new is used to replace the original current solution L_current, and the new solution L_new is used as the current solution. Then, proceed to step S6. If ΔF > 0, the probability of accepting a new solution is determined based on the current temperature T of the simulated annealing algorithm. The probability P of accepting a new solution is calculated using the Boltzmann probability distribution formula, which is as follows: P = exp(-ΔF / T). Generate a random number r. If r < P, then accept the new solution L_new as the current solution L_current; if r ≥ P, then keep the current solution L_current unchanged. Step S6: Update the temperature for the next moment according to Tt+1 = Tt×α, where Tt represents the current temperature, Tt+1 represents the temperature for the next moment, and α represents the temperature decay coefficient. Based on the new temperature, determine whether the simulated annealing algorithm meets the termination condition. The termination condition includes: the current temperature drops below the preset temperature threshold T_min, or the number of consecutive iterations of the simulated annealing algorithm exceeds the preset iteration threshold and no better solution is found. When the simulated annealing algorithm terminates, its output current solution is taken as the final optimal solution of the simulated annealing algorithm, which is also the parameter set required for the final autofocus shooting of the lens.
6. A processing terminal, characterized in that, It includes: Memory, used to store program instructions; A processor for running the program instructions to perform the steps of the image autofocusing method of the imaging apparatus as claimed in any one of claims 1-5.