An auto-focusing method, apparatus, device and medium

By fusing phase information from multiple preset directions into the phase detection autofocus method, the problem of reduced focus sharpness and speed caused by the loss of effective phase information in traditional methods is solved, achieving higher focus accuracy and speed.

CN122372838APending Publication Date: 2026-07-10HUNAN GOKE MICROELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUNAN GOKE MICROELECTRONICS CO LTD
Filing Date
2026-06-09
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Traditional phase-detection autofocus methods calculate the amount of defocusing based on the phase difference in only one direction, resulting in decreased focus sharpness and speed, and the loss of effective phase information from other directions.

Method used

By determining the gradient information of the target pixel set in the area to be focused in multiple preset directions and fusing the phase information in multiple preset directions, focusing is performed using the effective phase information in multiple preset directions.

Benefits of technology

It significantly improves the sharpness and speed of autofocus, reduces the number of refocusing attempts, and enhances focusing accuracy and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122372838A_ABST
    Figure CN122372838A_ABST
Patent Text Reader

Abstract

This application discloses an autofocus method, apparatus, device, and medium, relating to the field of computer technology. The method includes: determining gradient information of a target pixel set on a region to be focused in multiple preset directions; the target pixel set being a set of pixels at preset positions in the region to be focused; fusing phase information from the multiple preset directions based on the gradient information; and focusing the region to be focused based on the fused phase information. Therefore, this application improves focusing sharpness and focusing speed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to an automatic focusing method, apparatus, device, and medium. Background Technology

[0002] Traditional phase detection autofocus (PDAF) methods, when calculating phase, only select phase difference results from a single direction (horizontal, vertical, diagonal, and anti-diagonal) using confidence filtering for the calculation of defocusing amount. This directly loses effective phase information from other directions, resulting in a decrease in focus sharpness and focusing speed. Therefore, the above-mentioned technical problems urgently need to be solved by those skilled in the art. Summary of the Invention

[0003] In view of this, the purpose of this invention is to provide an autofocus method, apparatus, device, and medium that improves focus sharpness and focusing speed, the specific solution of which is as follows: In a first aspect, this application discloses an autofocus method, comprising: Determine the gradient information of the target pixel set in multiple preset directions in the area to be focused; the target pixel set is the pixel set at a preset position in the area to be focused. Based on the gradient information, the phase information of the multiple preset directions is fused; The area to be focused is focused based on the fused phase information.

[0004] Optionally, determining the gradient information of the target pixel set in the focus area in multiple preset directions includes: Obtain multiple gradient operators in the multiple preset directions; Obtain the pixel matrix of the target pixel set; The gradient information is determined based on the plurality of gradient operators and the pixel matrix.

[0005] Optionally, determining the gradient information based on the plurality of gradient operators and the pixel matrix includes: Convolution operations are performed on the multiple gradient operators and the pixel matrix respectively to obtain multiple original gradient values ​​of the target pixel set; The gradient information of the target pixel set in the multiple preset directions is obtained based on the absolute values ​​of the multiple original gradient values.

[0006] Optionally, fusing the phase information of the multiple preset directions based on the gradient information includes: Obtain the phase information of each of the multiple preset directions; Based on the gradient information, the target weights of the phase information in each preset direction are determined; The fused phase information is obtained based on the phase information of each preset direction and the corresponding target weight.

[0007] Optionally, determining the target weights of the phase information in each preset direction based on the gradient information includes: The sum of gradient information in each preset direction is determined to obtain the target value. Determine the target ratio corresponding to each preset direction; the target ratio is the ratio of the gradient information of each preset direction to the target sum value; Based on the target ratio, the target weights of the phase information in each preset direction are determined.

[0008] Optionally, the preset direction includes a horizontal direction, a vertical direction, a diagonal direction, and an anti-diagonal direction.

[0009] Optionally, the process of obtaining the target pixel set includes: Extract pixels from all preset positions in the area to be focused, wherein the preset positions are at least one type of position among the upper left, lower left, upper right, and lower right positions in the area to be focused; The pixels at the preset positions are arranged according to their orientation in the area to be focused, with adjacent pixels touching each other, to obtain the target pixel set.

[0010] Secondly, this application discloses an autofocus device, comprising: The gradient determination module is used to determine the gradient information of the target pixel set in the focus area in multiple preset directions; the target pixel set is the pixel set at a preset position in the focus area. A phase fusion module is used to fuse phase information in multiple preset directions based on the gradient information; An autofocus module is used to focus on the area to be focused based on the fused phase information.

[0011] Thirdly, this application discloses an electronic device, comprising: Memory, used to store computer programs; A processor is configured to execute the computer program to implement the aforementioned autofocus method.

[0012] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned autofocus method.

[0013] As can be seen, this application proposes an autofocus method, comprising: determining gradient information of a set of target pixels in a region to be focused in multiple preset directions; the set of target pixels being a set of pixels at preset positions in the region to be focused; fusing phase information in the multiple preset directions according to the gradient information; and focusing the region to be focused based on the fused phase information. It is evident that this application fuses phase information in multiple preset directions and performs autofocus on the region to be focused based on the fused phase information. Compared to traditional methods that only filter phase difference results in a single direction based on confidence level, easily losing effective phase information in other directions, this application can fully utilize effective phase information in multiple preset directions, significantly improving the sharpness of autofocus. Meanwhile, traditional methods suffer from insufficient reliability of phase detection results due to the loss of effective phase information, often requiring multiple refocusing attempts, reducing focusing efficiency. Furthermore, this application effectively improves focusing accuracy and reduces the number of refocusing attempts by fusing phase information in multiple directions, thereby increasing the speed of autofocus. This application also proposes an autofocus device, equipment, and medium, which have the same technical effects as the above method. Attached Figure Description

[0014] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0015] Figure 1 This is a flowchart of an autofocus method disclosed in this application; Figure 2 This is a schematic diagram illustrating the extraction of a target pixel set within a focusing area as disclosed in this application; Figure 3 This is a flowchart of a traditional autofocus method. Figure 4 This is a flowchart of a specific autofocus method disclosed in this application; Figure 5 This is a schematic diagram of an automatic focusing device disclosed in this application; Figure 6 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

[0016] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0017] Traditional PDAF methods utilize phase-detection pixels in an image sensor to calculate phase difference (PD) information and convert this phase difference into defocusing distance, ultimately achieving fast focusing on the region of interest (ROI) in the image. The PDAF method mainly includes brightness compensation, phase calculation, defocusing distance calculation, and confidence level calculation. Specifically: brightness compensation uses a calibrated brightness gain coefficient to compensate for brightness differences between different phase-detection pixels; phase calculation uses the brightness-compensated phase-detection pixels for correlation calculations to obtain phase information; defocusing distance calculation uses the phase information and the calibrated defocus conversion coefficient (DCC) to calculate the required lens displacement; and confidence level calculation assesses the confidence level of the obtained phase information to determine whether to use the current PD result and adopt a PDAF focusing strategy. Traditional PDAF methods, when calculating phase, only select the phase difference results in a single direction (horizontal, vertical, diagonal, anti-angle) through confidence filtering for the calculation of defocus, which directly loses the effective phase information in other directions, resulting in a decrease in focus sharpness and focus speed.

[0018] Therefore, this application proposes an autofocus scheme to improve focusing clarity and speed.

[0019] This application discloses an autofocus method, see [link to relevant documentation]. Figure 1 As shown, the method includes: Step S11: Determine the gradient information of the target pixel set in multiple preset directions on the area to be focused; the target pixel set is the set of pixels at preset positions in the area to be focused.

[0020] It should be noted that the autofocus method provided in this application embodiment can be applied to electronic devices equipped with image sensors containing phase detection pixels. These electronic devices include, but are not limited to, digital cameras, smartphones, surveillance cameras, vehicle-mounted camera systems, or medical endoscopes. The input data for this autofocus method is the original pixel value corresponding to the target pixel set at a preset position within the focus area of ​​the image sensor; this is the raw digital signal directly output by the image sensor after photoelectric conversion. The autofocus method performs gradient calculations, convolution operations, and other processing on the aforementioned raw pixel values, ultimately outputting the defocus amount or lens displacement used to drive the lens motor. It can be understood that the output result can be directly transmitted to the autofocus actuator of the electronic device to control the lens to move to the corresponding focus position.

[0021] The region to be focused refers to the region of interest (ROI) in the image acquisition frame used for phase detection autofocus. The region to be focused can be manually selected by the user (e.g., by clicking on a location on a touchscreen) or automatically detected by the system (e.g., by face detection, subject tracking, etc.).

[0022] The target pixel set is the set of pixels corresponding to preset positions in the area to be focused. The process of obtaining the target pixel set includes: extracting pixels at all preset positions in the area to be focused, wherein the preset positions are at least one of the following positions: upper left, lower left, upper right, and lower right; arranging the pixels at the preset positions according to their orientation in the area to be focused, with adjacent pixels touching each other, to obtain the target pixel set.

[0023] Specifically, see Figure 2 As shown, within the area to be focused on in the sensor image, the entire area is pre-divided into multiple non-overlapping sub-blocks (pixel blocks). Each sub-block contains four symmetrically distributed directional points: top left (TL), bottom left (BL), top right (TR), and bottom right (BR). With the vertical center line of the sub-block as the axis, TL and TR are symmetrical about the left and right axes, and BL and BR are symmetrical about the left and right axes. With the horizontal center line of the sub-block as the axis, TL and BL are symmetrical about the top and bottom axes, and TR and BR are symmetrical about the top and bottom axes. With the geometric center point of the sub-block as the reference, TL and BR, and TR and BL are respectively centrally symmetrical.

[0024] During extraction, you can choose one type of position to extract. For example, if you choose the top left position as the preset position, you will traverse all sub-blocks within the area to be focused and extract all pixels located at the top left position in each sub-block. You can also choose multiple types of positions to extract. For example, if you choose the top left and top right positions as the preset positions, you will traverse all sub-blocks within the area to be focused and extract all pixels located at the top left and top right positions in each sub-block. You can also choose to extract all positions. For example, if you choose the top left, top right, bottom left, and bottom right positions as the preset positions, you will traverse all sub-blocks within the area to be focused and extract all pixels located at the top left, top right, bottom left, and bottom right positions in each sub-block.

[0025] Furthermore, all pixels at the preset positions extracted above are arranged according to their original orientation in the area to be focused, with adjacent pixels touching each other, to obtain the target pixel set. For the scenario where only the top-left pixel is extracted, all sub-blocks within the area to be focused are traversed, and the top-left pixel of each sub-block is taken sequentially and arranged according to the row and column order of the sub-block in the area to be focused. For example, the top-left pixels of the first sub-block in the first row, the second sub-block in the first row, the third sub-block in the first row, and so on, are arranged horizontally in sequence, and then the top-left pixels of the first sub-block in the second row, the second sub-block in the second row, the third sub-block in the second row, and so on, are arranged horizontally in sequence until all sub-blocks are covered. These pixels originally had a certain vertical and horizontal relationship within the area to be focused, and this relationship is retained after arrangement. For example, the top-left pixels of two sub-blocks originally in the same row of the area to be focused will remain adjacent horizontally after arrangement; similarly, the top-left pixels of two sub-blocks originally in the same column of the area to be focused will remain adjacent vertically. During arrangement, these top-left pixels, originally scattered among the sub-blocks and separated by other pixels, are connected end-to-end without gaps, ultimately forming a two-dimensional pixel array, i.e., the target pixel set. Corresponding to the scenario of simultaneously extracting pixels at the top-left and top-right positions, all sub-blocks within the area to be focused are traversed, and the top-left and top-right pixels of each sub-block are sequentially taken and arranged according to the row and column order of the sub-blocks within the area to be focused. For example, the top-left and top-right pixels of the first sub-block in the first row, the top-left and top-right pixels of the second sub-block in the first row, the top-left and top-right pixels of the third sub-block in the first row, and so on, are arranged horizontally in sequence. Then, the top-left and top-right pixels of the first sub-block in the second row, the top-left and top-right pixels of the second sub-block in the second row, and so on, are arranged horizontally in sequence until all sub-blocks are covered. These pixels originally had certain vertical and horizontal relationships within the area to be focused, and these relationships are retained after arrangement. For example, the top-left and top-right pixels that were originally in the same sub-block remain adjacent horizontally after arrangement; pixels in two sub-blocks that were originally in the same row within the area to be focused remain adjacent horizontally after arrangement. During arrangement, these points, which were originally scattered in the sub-blocks and separated by other pixels, are connected end-to-end without gaps, ultimately forming a two-dimensional pixel array, i.e., the target pixel set. For the scenario described above where all four types of position pixels are extracted, all sub-blocks within the area to be focused are traversed, and the top-left, top-right, bottom-left, and bottom-right position pixels of each sub-block are taken in turn and arranged according to the row and column order of the sub-blocks within the area to be focused.For example, the top-left, top-right, bottom-left, and bottom-right pixels of the first sub-block in the first row, the top-left, top-right, bottom-left, and bottom-right pixels of the second sub-block in the first row, the top-left, top-right, bottom-left, and bottom-right pixels of the third sub-block in the first row, and so on, are arranged horizontally in sequence. Then, the four types of pixels of the first sub-block in the second row, the four types of pixels of the second sub-block in the second row, the four types of pixels of the third sub-block in the second row, and so on, are arranged horizontally in sequence until all sub-blocks are covered. These pixels originally had certain vertical and horizontal relationships within the area to be focused, and these relationships are retained after arrangement. For example, the top-left and top-right pixels, and the bottom-left and bottom-right pixels in the same sub-block are still adjacent to each other after arrangement; pixels in two sub-blocks that were originally in the same row within the area to be focused remain adjacent to each other after arrangement. During arrangement, these points, which were originally scattered in the sub-blocks and separated by other pixels, are connected end-to-end without gaps, ultimately forming a two-dimensional pixel array, i.e., the target pixel set.

[0026] In this embodiment, determining the gradient information of a target pixel set in a region to be focused along multiple preset directions includes: acquiring multiple gradient operators along the multiple preset directions; acquiring a pixel matrix of the target pixel set; and determining the gradient information based on the multiple gradient operators and the pixel matrix. Specifically, determining the gradient information based on the multiple gradient operators and the pixel matrix includes: performing convolution operations on the multiple gradient operators and the pixel matrix respectively to obtain multiple original gradient values ​​of the target pixel set; and obtaining the gradient information of the target pixel set along the multiple preset directions based on the absolute values ​​of the multiple original gradient values. The following is a detailed explanation: 1. Determine the gradient operator.

[0027] The gradient operator in the horizontal direction for the set of target pixels in the region to be focused can be expressed as: ; For the horizontal gradient operator, which is a matrix with negative weights on the left, positive weights on the right, and zero weights in the middle, the principle is as follows: when this operator is convolved with the pixel matrix, the operator is multiplied by the corresponding pixel value and then summed. Essentially, this is a weighted difference calculation of the brightness values ​​of the right and left pixels. Therefore, the larger the absolute value of the convolution result, the more significant the change in brightness gradient of the target pixel set in the horizontal direction.

[0028] The gradient operator in the vertical direction of the target pixel set in the focusing area can be expressed as: ; For the vertical gradient operator, which is a matrix with negative weights at the top, positive weights at the bottom, and zero weights in the middle, the principle is as follows: when this operator is convolved with the pixel matrix, the operator is multiplied by the corresponding pixel value and then summed. Essentially, this is a weighted difference calculation of the brightness values ​​between the bottom and top pixels. Therefore, the larger the absolute value of the convolution result, the more significant the brightness gradient change of the target pixel set in the vertical direction.

[0029] The gradient operator of the target pixel set in the focus area along the diagonal direction can be expressed as: ; For the diagonal gradient operator, which is a matrix with negative weights on the top left and positive weights on the bottom right, the principle is as follows: when this operator is convolved with the pixel matrix, the operator is multiplied by the corresponding pixel value and then summed. Essentially, this is a weighted difference calculation of the brightness values ​​of the bottom right and top left pixels. Therefore, the larger the absolute value of the convolution result, the more significant the brightness gradient change of the target pixel set in the diagonal direction.

[0030] The gradient operator of the target pixel set in the focus area along the anti-angle direction can be expressed as: ; For the gradient operator in the anti-diagonal direction, which is a matrix with negative weights on the upper right and positive weights on the lower left, the principle is as follows: when this operator is convolved with the pixel matrix, the operator is multiplied by the corresponding pixel value and then summed. Essentially, this is a weighted difference calculation of the brightness values ​​of the lower left and upper right pixels. Therefore, the larger the absolute value of the convolution result, the more significant the brightness gradient change of the target pixel set in the anti-diagonal direction.

[0031] It should be noted that the gradient operator mentioned above is an empirical value for those skilled in the art, and other matrices may also be used, as long as they can accurately represent the gradient information in each direction.

[0032] 2. Obtain the pixel matrix.

[0033] Obtain the two-dimensional pixel matrix corresponding to the target pixel set. The two-dimensional pixel matrix refers to a two-dimensional data array formed by arranging the target pixels in the focus area of ​​the image sensor according to their spatial positions.

[0034] 3. Determine the gradient information based on the gradient operator and the pixel matrix.

[0035] Convolution operations are performed on the plurality of gradient operators and the pixel matrix respectively to obtain a plurality of original gradient values ​​of the target pixel set; the gradient information of the target pixel set in the plurality of preset directions is obtained based on the absolute values ​​of the plurality of original gradient values.

[0036] Taking the phase detection pixel at position TL as an example, its corresponding two-dimensional pixel matrix is: , The width and height are W and H, respectively.

[0037] (1) Horizontal direction: The gradient operator in the horizontal direction is convolved with the two-dimensional pixel matrix to obtain the convolution result, which is the original gradient value corresponding to each pixel position in the two-dimensional pixel matrix: ; Then, calculate the absolute value of the convolution result: ; Finally, the absolute values ​​of all the results are summed, and the sum represents the gradient information of the target pixel set in the corresponding horizontal direction: ; (2) Vertical direction: The gradient operator in the vertical direction is convolved with the two-dimensional pixel matrix to obtain the convolution result: ; Then, calculate the absolute value of the convolution result: ; Finally, the absolute values ​​of all the results are summed, and the sum represents the gradient information of the target pixel set in the corresponding vertical direction: ; (3) Diagonal direction: The gradient operator in the diagonal direction is convolved with the two-dimensional pixel matrix to obtain the convolution result: ; Then, calculate the absolute value of the convolution result: ; Finally, the absolute values ​​of all the results are summed, and the sum represents the gradient information of the target pixel set in the corresponding diagonal direction: ; (4) Opposite angle direction: The gradient operator in the anti-angle direction is convolved with the two-dimensional pixel matrix to obtain the convolution result: ; Then, calculate the absolute value of the convolution result: ; Finally, the absolute values ​​of all the results are summed, and the sum represents the gradient information of the target pixel set in the corresponding anti-angle direction: .

[0038] Step S12: Based on the gradient information, fuse the phase information of the multiple preset directions.

[0039] In this embodiment, phase information of each preset direction among the plurality of preset directions is obtained; target weights of the phase information of each preset direction are determined according to the gradient information; and the fused phase information is obtained according to the phase information of each preset direction and the corresponding target weights. The process of determining the target weights includes: determining the sum of the gradient information of each preset direction to obtain a target sum value; determining the target ratio value corresponding to each preset direction; the target ratio value is the ratio of the gradient information of each preset direction to the target sum value; and determining the target weights of the phase information of each preset direction according to the target ratio value. Obtaining the fused phase information according to the phase information of each preset direction and the corresponding target weights includes: performing a weighted summation operation on each phase information and the corresponding target weight to obtain the fused phase information.

[0040] Based on the foregoing, direction detection yields response values ​​in four directions: G_H_abs_sum, G_V_abs_sum, G_D_abs_sum, and G_AD_abs_sum. Larger values ​​indicate a stronger gradient response in that direction, representing more reliable phase information in that direction within the region to be focused. The calculation of target weights and phase fusion for each direction is as follows: (1) Target weight in the horizontal direction ; (2) Target weight in the vertical direction ; (3) Target weights in the diagonal direction ; (4) Target weight in the opposite angle direction ; (5) Phase fusion ; Among them, the PD (Phase Detection) results in the horizontal direction are as follows: ; ; Vertical PD results: ; ; PD results in the diagonal direction: ; ; PD results in the opposite direction: ; ; Where TL(t), TR(t), BL(t), and BR(t) represent the pixel sequences at the top left, top right, bottom left, and bottom right positions in the target pixel set, respectively, t is the sequence position index, and τ is the sequence offset.

[0041] Step S13: Focus on the area to be focused based on the fused phase information.

[0042] In this embodiment, autofocus is performed based on the fused phase information. Compared to traditional methods that only filter phase difference results in a single direction based on confidence level, easily losing effective phase information in other directions, this application can fully utilize the effective phase information in each preset direction, significantly improving the sharpness of autofocus. Meanwhile, traditional methods suffer from insufficient reliability of phase detection results due to the loss of effective phase information, often requiring multiple refocusing attempts and reducing focusing efficiency. This application, by fusing phase information from multiple directions, effectively improves focusing accuracy, reduces the number of refocusing attempts, and increases the speed of autofocus.

[0043] Furthermore, it should be noted that this embodiment can select any one (as mentioned above) or multiple (or more) positions from the four sub-regions TL, TR, BL, and BR within the sub-block to collect phase detection results and participate in subsequent calculations. Since the pixel brightness variation between adjacent positions within the focusing area is small, the difference between selecting a single position and selecting multiple positions is limited. The scheme of selecting a single (single-type) position for calculation has a simpler computational logic and lower computational load, while selecting multiple positions for calculation can further improve detection accuracy. Therefore, in practical applications, the choice can be flexibly made based on the device's computing power and focusing requirements. For ease of explanation, this embodiment only uses the TL position as an example.

[0044] The complete workflow of this application is as follows: First, the phase detection pixels of the image sensor output raw pixel signals, which enter the brightness compensation module. This module, combined with a brightness gain coefficient, corrects the brightness of the raw pixel values, eliminating brightness unevenness caused by exposure differences and sensor response deviations, ensuring the consistency of pixel data in subsequent processing. The corrected pixel data enters the core improvement part of this application: First, through the direction detection step, gradient information in four preset directions—horizontal, vertical, diagonal, and anti-diagonal—is extracted. Sobel gradient operators in different directions are convolved with the two-dimensional pixel matrix to obtain gradient response values ​​for each direction. Then, the phase fusion step is entered. Based on the relative proportion of gradient information in each direction, the target weight of the phase information in each direction is dynamically calculated, and the multi-directional phase results are weighted and fused to obtain the fused phase information. The fused phase information is input to the defocus calculation module. This module, combined with a preset defocus conversion coefficient, converts the phase difference information into a defocus amount or lens displacement that can directly drive the lens. Finally, this control signal is transmitted to the autofocus actuator of the electronic device, driving the lens to move to the corresponding focus position to achieve clear imaging. Compared to traditional phase detection schemes that rely solely on phase difference results in a single direction, this application reduces the number of refocusing attempts by fusing phase information from multiple directions, thereby improving the speed of autofocus.

[0045] The workflow of traditional phase detection schemes can be found in [reference needed]. Figure 3 After the phase calculation module outputs phase difference results in multiple directions such as horizontal, vertical, diagonal, and anti-diagonal, the confidence level of the phase information in each direction needs to be determined by the confidence calculation module. Only the phase difference result in a single direction can be selected for subsequent defocus calculation. Based on this confidence level result, it is determined whether to adopt the current PD result and which PDAF focusing strategy to use. The workflow of this application can be found in [link to relevant documentation]. Figure 4 This application eliminates the need for a confidence level filtering mechanism and additional confidence level calculation modules. Instead, it dynamically calculates the target weights of phase information in each direction based on the relative proportions of gradient information, and then weights and fuses the phase results from multiple directions to obtain fused phase information. This fused information can be directly used to calculate the defocusing amount. Compared to traditional phase detection schemes that rely solely on confidence level filtering for single-direction phase difference results, which are cumbersome and susceptible to texture direction influences, this application reduces the number of refocusing attempts by fusing multi-directional phase information. It also eliminates the additional steps of confidence level calculation and filtering, thereby further improving the speed and stability of autofocus.

[0046] As can be seen, this application proposes an autofocus method, comprising: determining gradient information of a set of target pixels in a region to be focused in multiple preset directions; the set of target pixels being a set of pixels at preset positions in the region to be focused; fusing phase information in the multiple preset directions according to the gradient information; and focusing the region to be focused based on the fused phase information. It is evident that this application fuses phase information in multiple preset directions and performs autofocus on the region to be focused based on the fused phase information. Compared to traditional methods that only filter phase difference results in a single direction based on confidence level, easily losing effective phase information in other directions, this application can fully utilize effective phase information in multiple preset directions, significantly improving the sharpness of autofocus. Meanwhile, traditional methods suffer from insufficient reliability of phase detection results due to the loss of effective phase information, often requiring multiple refocusing attempts, reducing focusing efficiency. Furthermore, this application effectively improves focusing accuracy and reduces the number of refocusing attempts by fusing phase information in multiple directions, thereby increasing the speed of autofocus. This application also proposes an autofocus device, equipment, and medium, which have the same technical effects as the above method.

[0047] Accordingly, this application also discloses an autofocus device, see [link to relevant documentation]. Figure 5 As shown, the device includes: The gradient determination module 11 is used to determine the gradient information of the target pixel set in the focus area in multiple preset directions; the target pixel set is the pixel set at a preset position in the focus area. The phase fusion module 12 is used to fuse the phase information of the multiple preset directions according to the gradient information; The autofocus module 13 is used to focus on the area to be focused based on the fused phase information.

[0048] For more detailed information on the working process of each of the above modules, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.

[0049] Furthermore, embodiments of this application also provide an electronic device. Figure 6 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.

[0050] Figure 6This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a display screen 23, an input / output interface 24, a communication interface 25, a power supply 26, and a communication bus 27. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the following steps; Determine the gradient information of the target pixel set in multiple preset directions in the area to be focused; the target pixel set is the pixel set at a preset position in the area to be focused. Based on the gradient information, the phase information of the multiple preset directions is fused; The area to be focused is focused based on the fused phase information.

[0051] In addition, the electronic device 20 in this embodiment can specifically be an electronic computer.

[0052] In this embodiment, the power supply 26 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 25 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 24 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0053] Furthermore, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored thereon may include computer programs 221, and the storage method may be temporary storage or permanent storage. The computer programs 221 may include, in addition to computer programs capable of performing the autofocus method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, computer programs capable of performing other specific tasks.

[0054] Furthermore, embodiments of this application also disclose a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned autofocus method.

[0055] For the specific steps of this method, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.

[0056] The various embodiments in this application are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. For the same or similar parts between the various embodiments, refer to each other. As for the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and relevant parts can be referred to in the method section.

[0057] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0058] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0059] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0060] The above provides a detailed description of an autofocus method, apparatus, device, and storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. An autofocus method, characterized in that, include: Determine the gradient information of the target pixel set in multiple preset directions in the area to be focused; The target pixel set is the set of pixels at a preset position in the area to be focused; Based on the gradient information, the phase information of the multiple preset directions is fused; The area to be focused is focused based on the fused phase information.

2. The autofocus method according to claim 1, characterized in that, The determination of gradient information of the target pixel set in the focus area in multiple preset directions includes: Obtain multiple gradient operators in the multiple preset directions; Obtain the pixel matrix of the target pixel set; The gradient information is determined based on the plurality of gradient operators and the pixel matrix.

3. The autofocus method according to claim 2, characterized in that, Determining the gradient information based on the plurality of gradient operators and the pixel matrix includes: Convolution operations are performed on the multiple gradient operators and the pixel matrix respectively to obtain multiple original gradient values ​​of the target pixel set; The gradient information of the target pixel set in the multiple preset directions is obtained based on the absolute values ​​of the multiple original gradient values.

4. The autofocus method according to claim 3, characterized in that, The step of fusing the phase information of the multiple preset directions based on the gradient information includes: Obtain the phase information of each of the multiple preset directions; Based on the gradient information, the target weights of the phase information in each preset direction are determined; The fused phase information is obtained based on the phase information of each preset direction and the corresponding target weight.

5. The autofocus method according to claim 4, characterized in that, The step of determining the target weights of the phase information in each preset direction based on the gradient information includes: The sum of gradient information in each preset direction is determined to obtain the target value. Determine the target ratio corresponding to each preset direction; the target ratio is the ratio of the gradient information of each preset direction to the target sum value; Based on the target ratio, the target weights of the phase information in each preset direction are determined.

6. The autofocus method according to any one of claims 1 to 5, characterized in that, The preset directions include horizontal, vertical, diagonal, and anti-diagonal directions.

7. The autofocus method according to any one of claims 1 to 5, characterized in that, The process of obtaining the target pixel set includes: Extract pixels from all preset positions in the area to be focused, wherein the preset positions are at least one type of position among the upper left, lower left, upper right, and lower right positions in the area to be focused; The pixels at the preset positions are arranged according to their orientation in the area to be focused, with adjacent pixels touching each other, to obtain the target pixel set.

8. An automatic focusing device, characterized in that, include: The gradient determination module is used to determine the gradient information of the target pixel set in the focus area in multiple preset directions; The target pixel set is the set of pixels at a preset position in the area to be focused; A phase fusion module is used to fuse phase information in multiple preset directions based on the gradient information; An autofocus module is used to focus on the area to be focused based on the fused phase information.

9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the autofocus method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, Used to store a computer program; wherein, when the computer program is executed by a processor, it implements the autofocus method as described in any one of claims 1 to 7.