Infinite impulse response filtering method and related apparatus
The infinite impulse response filtering method using parallel computing calculates the feedback value and filtering result of the input data in the current clock cycle using the feedback value of the previous clock cycle. This solves the problem that traditional methods cannot complete the filtering of two pixels in one clock cycle, and achieves more efficient filtering processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING ESWIN COMPUTING TECH CO LTD
- Filing Date
- 2023-03-01
- Publication Date
- 2026-07-21
AI Technical Summary
Traditional infinite impulse response filtering methods require serial calculation of filtering results when processing two pixels in hardware circuits, which makes it impossible to complete the process within one clock cycle and results in significant delays from multiplication and addition operations.
An infinite impulse response filtering method using parallel computing is employed, which optimizes the filtering process by calculating the input data feedback value and filtering result of the current clock cycle using the feedback value of the previous clock cycle in the current clock cycle.
It enables the parallel filtering of two pixels within one clock cycle, reducing filtering time and improving processing efficiency.
Smart Images

Figure CN116169984B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the technical field of data processing, specifically to an infinite impulse response filtering method and related apparatus. Background Technology
[0002] Passive autofocus adjusts the focus to the optimal position by driving the focus motor based on image sharpness. There are various algorithms for obtaining image sharpness, one of which is the high-frequency component method. The basic principle of the high-frequency component method is that the sharper the image, the larger the amplitude of the high-frequency components. The high-frequency components can be obtained by passing the image through a high-pass filter. Some image processors use infinite impulse response (IIR) filters to perform horizontal high-pass filtering on the image.
[0003] In practice, an Infinite Impulse Response (IIR) filter can process one pixel per clock cycle and output a filtered result based on hardware circuitry. In this case, the traditional IIR filtering method allows the calculation of the filtered result for one pixel within one clock cycle. However, if the IIR filter processes two pixels per clock cycle based on hardware circuitry, the difference equations used in the traditional IIR filtering method involve numerous multiplication and addition operations, and the filtering of the subsequent pixel requires the filtered result of the previous pixel as input. Therefore, it does not allow for parallel processing of a large number of calculations, and the filtering of two pixels cannot be completed within one clock cycle. Summary of the Invention
[0004] To address the aforementioned technical problems, this disclosure provides an infinite impulse response filtering method and related apparatus.
[0005] According to a first aspect of this disclosure, an infinite impulse response (IOR) filtering method is provided, wherein the IOR filtering method performs the following steps in parallel during the current clock cycle:
[0006] Calculate the feedback values of the two input data in the current clock cycle based on the feedback values calculated in the previous clock cycles.
[0007] In addition, based on the feedback value calculated in the previous clock cycle, the filtering result of the two input data in the previous clock cycle is calculated.
[0008] In each clock cycle, the feedback value of the two input data is the feedback value of the two input data in the canonical infinite impulse response filter structure, and the filtering result of the two input data is the filtering result of the canonical infinite impulse response filter structure of the two input data.
[0009] Optionally, the two input data in the current clock cycle include a first input data and a second input data, wherein,
[0010] The feedback value of the first input data is calculated using a first formula, which is:
[0011]
[0012] The feedback value of the second input data is calculated using a second formula, which is:
[0013]
[0014] Where x[n] represents the first input data, w[n] represents the feedback value of the first input data, x[n+1] represents the second input data, w[n+1] represents the feedback value of the second input data, and a i represents the first filter coefficient, L represents the filter order, and w[ni] represents the feedback value calculated from the clock cycle prior to the current clock cycle.
[0015] Optionally, before calculating the feedback value of the second input data using the second formula, the method further includes: obtaining (a1a) j -a j+1 The calculation results and a1a L The calculation results;
[0016] And, calculating the feedback value of the second input data using the second formula includes: using the obtained (a1a) in the second formula. j -a j+1 The calculation results and a1a L The calculation result is used to calculate the feedback value of the second input data.
[0017] Optionally, when the current clock cycle is the first clock cycle, w[ni] = 0 in the first formula, and w[nj] = 0 and w[nL] = 0 in the second formula.
[0018] Optionally, the two input data in the previous clock cycle include a third input data and a fourth input data, wherein,
[0019] The filtering result of the third input data is calculated using a third formula, which is:
[0020]
[0021] The filtering result of the fourth input data is calculated using a fourth formula, which is:
[0022]
[0023] Where y[m] represents the filtering result of the third input data, y[m+1] represents the filtering result of the fourth input data, and b k This represents the second filter coefficient, and m = n - 2.
[0024] Optionally, when the current clock cycle is the second clock cycle, w[mk] = 0 if k > 0 in the third formula, and w[m+1-k] = 0 if k > 1 in the fourth formula.
[0025] Optionally, the filter order is 2nd order.
[0026] According to a second aspect of this disclosure, a filter is provided that performs any of the infinite impulse response filtering methods described in the first aspect.
[0027] According to a third aspect of this disclosure, an image processor is provided, the image processor comprising:
[0028] The filter described in the second aspect is used to filter an image in the horizontal direction to obtain the filtering result of each pixel in the image;
[0029] And a sharpness calculation unit, which is used to determine the sharpness information of the image along the horizontal direction based on the filtering result.
[0030] According to a fourth aspect of this disclosure, a computer-readable storage medium is provided, on which a computer program or instructions are stored, which, when executed by a processor, implement the steps of any of the infinite impulse response filtering methods described in the first aspect.
[0031] The beneficial effects of this disclosure are:
[0032] The infinite impulse response filtering method disclosed herein is based on a canonical infinite impulse response filtering structure. It performs the following steps in parallel during the current clock cycle: calculating the feedback value of the two input data in the current clock cycle based on the feedback value calculated in the previous clock cycle; and calculating the filtering result of the two input data in the previous clock cycle based on the feedback value calculated in the previous clock cycle. This effectively reduces the filtering time, and the filtering of two pixels is completed within one clock cycle.
[0033] It should be noted that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this disclosure. Attached Figure Description
[0034] Figure 1This diagram illustrates the serial execution of filtering two pixels within one clock cycle.
[0035] Figure 2 A flowchart of the infinite impulse response filtering method in an embodiment of this disclosure is shown;
[0036] Figure 3 This diagram illustrates the parallel execution of filtering two pixels within one clock cycle in an embodiment of the present disclosure.
[0037] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure is shown. Detailed Implementation
[0038] To facilitate understanding of this disclosure, a more complete description will now be given with reference to the accompanying drawings, which illustrate preferred embodiments of the present disclosure. However, this disclosure may be implemented in various forms and is not limited to the embodiments described herein. Rather, these embodiments are provided to provide a thorough and complete understanding of the disclosure.
[0039] The frequency of an image is an indicator of the degree of drastic change in grayscale levels; it is the gradient of grayscale in a two-dimensional space. For example, a large desert area appears as a region with slow grayscale changes, corresponding to a low frequency value; while the surface properties of the desert's edge change drastically, appearing as a region with rapid grayscale changes and a higher frequency value. Infinite impulse response (IOR) filters are used to perform high-pass filtering in the horizontal direction, removing low-frequency components and retaining the high-frequency components that reflect image sharpness.
[0040] In the prior art, the infinite impulse response filter performs high-pass filtering on images in the horizontal direction using a direct type I infinite impulse response filter structure. The specific filtering process is as follows: for each row x of a given image, the filtering result y[n] of the nth pixel x[n] in that row is obtained based on the difference equation shown in formula (1), where a i and b i The filter coefficients are represented by ; the direct type I infinite impulse response filter structure corresponding to the difference equation shown in formula (1) has an M-section delay network for the input signal and an N-section delay network for the output signal.
[0041]
[0042] After obtaining the filtering results of each pixel in the image, the image sharpness F can be obtained based on formula (2). V , where V represents the number of pixels in the image.
[0043]
[0044] In a process where a single pixel is processed and a filtering result is output within one clock cycle based on hardware circuitry, the filtering result for one pixel can usually be calculated within one clock cycle by using a direct type I infinite impulse response filter structure with M=N=2. However, in a process where two pixels are processed and two filtering results are output within one clock cycle based on hardware circuitry, even with a direct type I infinite impulse response filter structure with M=N=2, the calculation process shown in formulas (3) and (4) must still be completed within one clock cycle.
[0045] y[n-1]=a0x[n-1]+a1x[n-2]+a2x[n-3]-b1y[n-2]-b2y[n-3] (3)
[0046] y[n]=a0x[n]+a1x[n-1]+a2x[n-2]-b1y[n-1]-b2y[n-2] (4)
[0047] As shown in formulas (3) and (4), the calculation of the filtering result y[n] of the next pixel x[n] requires waiting for the output of the filtering result y[n-1] of the previous pixel x[n-1]. Therefore, the filtering results y[n-1] and y[n] can only be calculated in a serial order. Figure 1 As shown. Furthermore, formulas (3) and (4) each contain 5 multiplication operations and 4 addition operations. The multiplication operation has a large delay; the bit width of the result obtained from the multiplication operation is also large, and the delay of the 4 addition operations contained in formulas (3) and (4) is also relatively large. Moreover, to avoid error accumulation, the filtered results y[n-1] and y[n] must maintain high precision, which means that the bit width of the filtered results y[n-1] and y[n] is very large, further increasing the delay of the addition and multiplication operations in formulas (3) and (4). Therefore, it is impossible to complete the filtering of two pixels within one clock cycle.
[0048] In view of this, the present disclosure provides an infinite impulse response filtering method. This infinite impulse response filtering method is based on a canonical infinite impulse response filtering structure and solves the technical problem that two pixels cannot be filtered within one clock cycle by optimizing the processing flow of infinite impulse response filtering.
[0049] Figure 2 The diagram shows a flowchart of the infinite impulse response filtering method provided in an embodiment of this disclosure. Figure 2 As shown, the infinite impulse response filtering method provided in this embodiment of the present disclosure performs the following steps in parallel during the current clock cycle:
[0050] Step S110: Calculate the feedback values of the two input data in the current clock cycle based on the feedback values calculated in the previous clock cycles.
[0051] Step S120: Calculate the filtering result of the two input data in the previous clock cycle based on the feedback value calculated in the previous clock cycle.
[0052] Specifically, in each clock cycle, the feedback value of the two input data is the feedback value of the two input data in the canonical infinite impulse response filter structure, and the filtering result of the two input data is the filtering result of the canonical infinite impulse response filter structure of the two input data.
[0053] Taking the nth input data x[n] as an example, the expression for the feedback value w[n] of x[n] in the canonical infinite impulse response filter structure is shown in formula (5), and the expression for the filtering result y[n] of the input data x[n] in the canonical infinite impulse response filter structure is shown in formula (6), where w[nk] represents the feedback value of the (nk)th input data x[nk] in the canonical infinite impulse response filter structure; a i b represents the first filter coefficient. k This represents the second filter coefficient, and L represents the filter order (the same applies below).
[0054]
[0055] It should be noted that, starting from the first clock cycle, the two input data are filtered sequentially in each clock cycle. That is, the (2r-2)th input data x[2r-2] and the (2r-1)th input data x[2r-1] are filtered in the r-th clock cycle. The clock cycle sequence number starts from 1, and the input data sequence number starts from 0.
[0056] In the process of filtering an image, if it is applied to the horizontal high-pass filtering of the image to calculate the image sharpness, then for row x of the image, the input data x[2r-2] of the r-th clock cycle is the gray value of the (2r-2)-th pixel of row x, and the input data x[2r-1] of the r-th clock cycle is the gray value of the (2r-1)-th pixel of row x.
[0057] In an optional embodiment, the two input data in the current clock cycle are denoted as the first input data x[n] and the second input data x[n+1]. The feedback value w[n] of the first input data x[n] is calculated by the first formula, the expression of which is shown in the above formula (5); the feedback value w[n+1] of the second input data x[n+1] is calculated by the second formula, the expression of which is shown in the following formula (7).
[0058]
[0059] Specifically, referring to formula (5), the feedback value w[n+1] of the second input data x[n+1] in the canonical infinite impulse response filter structure has the expression shown in formula (8). Substituting the feedback value w[n] shown in formula (5) into formula (8), we can obtain the above formula (7).
[0060]
[0061] In the first and second formulas above, w[ni] (i = 1, 2, ..., L) represents the feedback value calculated in the clock cycle before the current clock cycle. Therefore, the two feedback values to be calculated in the current clock cycle depend on the feedback values calculated in the clock cycle before the current clock cycle. When the current clock cycle is the first clock cycle, w[ni] = 0 in the first formula and w[nj] = 0 and w[nL] = 0 in the second formula. That is, the initial values of the feedback values are set to w[0] = x[0] and w[1] = x[1] - a1x[0].
[0062] Referring to formulas (5) and (7), the calculation of feedback values w[n] and w[n+1] in the current clock cycle depends only on the input data x[n] and x[n+1] of the current clock cycle and the feedback value calculated in the previous clock cycle. That is, the calculation of feedback value w[n] does not depend on feedback value w[n+1] and the calculation of feedback value w[n+1] does not depend on feedback value w[n]. Therefore, the calculation of feedback value w[n] and the calculation of feedback value w[n+1] can be performed in parallel.
[0063] Furthermore, before calculating the feedback value w[n+1] of the second input data x[n+1] using the second formula, the infinite impulse response filtering method provided in this embodiment further includes: obtaining (a1a j -a j+1 The calculation results and a1a L The calculation result; and the feedback value w[n+1] of the second input data x[n+1] calculated by the second formula, including: using the obtained (a1a) in the second formula. j -a j+1 The calculation results and a1a L The calculation result is used to calculate the feedback value of the second input data, thus reducing the multiplication operation in the second formula and making the calculation of the feedback value w[n+1] faster.
[0064] In an optional embodiment, the two input data in the previous clock cycle include a third input data x[m] and a fourth input data x[m+1]. The filtered result y[m] of the third input data x[m] is calculated using the third formula, and the filtered result y[m+1] of the fourth input data x[m+1] is calculated using the fourth formula. Referring to the above formula (6), the expression of the third formula is as shown in the following formula (9), and the expression of the fourth formula is as shown in formula (10), where m = n-2, that is, the third input data x[m] is x[n-2], and the fourth input data x[m+1] is x[n-1].
[0065]
[0066]
[0067] It should be noted that when the current clock cycle is the first clock cycle, since there is no clock cycle before the current clock, the filtering result is not calculated. When the current clock cycle is the second clock cycle, if k>0 in the third formula, w[mk]=0 can be set, and if k>1 in the fourth formula, w[m+1-k]=0 can be set, that is, the initial value of the filtering result is set to: y[0]=b0w[0]=b0x[0] and y[1]=b0w[1]+b1w[0]=b0x[1]+(b1-b0a1)x[0].
[0068] In the third and fourth formulas above, w[mk] (k = 1, 2, ..., L) represents the feedback value calculated in the clock cycle before the previous clock cycle, and w[m] and w[m+1] represent the feedback values calculated in the previous clock cycle. That is, the filtering results y[m] and y[m+1] calculated in the current clock cycle only depend on the feedback values calculated in the clock cycle before the current clock cycle, and therefore can be calculated in parallel with the calculation process of the feedback values w[n] and w[n+1].
[0069] Furthermore, the filter order L involved in the above formula can be set to 2. Thus, the first formula used to calculate the feedback value in the current clock cycle is shown in the following formula (11), the second formula used is shown in the following formula (12), the third formula used to calculate the filtering result in the current clock cycle is shown in the following formula (13), and the fourth formula used is shown in the following formula (14).
[0070] w[n]=x[n]-a1w[n-1]-a2w[n-2] (11)
[0071] w[n+1]=x[n+1]-a1x[n]+(a1a1-a2)w[n-1]+a1a2w[n-2] (12)
[0072] y[m]=b0w[m]+b1w[m-1]+b2w[m-2] (13)
[0073] y[m+1]=b0w[m+1]+b1w[m]+b2w[m-1] (14)
[0074] Figure 3 The diagram illustrates the parallel execution of filtering two pixels within one clock cycle when the filter order L=2. (Refer to...) Figure 3 The entire execution process can be as follows: In the first clock cycle, the feedback values w[0] and w[1] are calculated; in the second clock cycle, the filtering results y[0] and y[1] and the feedback values w[2] and w[3] are calculated in parallel based on the feedback values w[0] and w[1] calculated in the first clock cycle, and the calculated filtering results y[0] and y[1] are output in the third clock cycle; in the third clock cycle, the filtering results y[0] and y[1] and ... are calculated in parallel based on the feedback values w[0], w[1], w[2], and w[3] calculated in the first and second clock cycles, and so on, until all the input data to be filtered is filtered.
[0075] The infinite impulse response filtering method described above calculates the feedback values of two input data in the current clock cycle and the filtering results of two input data in the previous clock cycle in parallel within one clock cycle. That is, by optimizing the execution timing of the infinite impulse response filtering, the calculation of the feedback values of two input data and the calculation of the filtering results of two input data are completed within one clock cycle, which effectively reduces the filtering processing time in the infinite impulse response filtering.
[0076] Corresponding to the infinite impulse response filtering method provided above, this disclosure also provides a filter that performs the infinite impulse response filtering method described above, thereby achieving the technical effect of filtering two pixels within one clock cycle.
[0077] Corresponding to the filters provided above, this disclosure also provides an image processor, which includes the aforementioned filter and a sharpness calculation unit. The filter is used to perform the aforementioned infinite impulse response filtering method to filter the image horizontally, obtaining the filtering result for each pixel in the image. The sharpness calculation unit is used to determine the sharpness information of the image along the horizontal direction based on the filtering result. Specifically, the process of the filter performing horizontal filtering on the image and the process of the sharpness calculation unit determining the sharpness information of the image along the horizontal direction based on the filtering result can be referred to the relevant descriptions above, and will not be repeated here. Since the filter can complete the filtering of two pixels within one clock cycle, the image processor can determine the sharpness of the image in real time, thereby enabling rapid adjustment of the focus to the optimal position in passive autofocus.
[0078] This disclosure also provides an electronic device, which can be an image processing device. For example... Figure 4 As shown, the electronic device 1300 includes a memory 1310 and an image processor 1320, as well as a program stored in the memory 1310 and executable on the image processor 1320. When executed by the image processor 1320, the program can perform the functions of the aforementioned filter and sharpness calculation unit, achieving the same technical effect. Of course, the electronic device may also include auxiliary sub-devices such as a power supply component 1330, a network interface 1340, and an input / output interface 1350.
[0079] Those skilled in the art will understand that all or part of the steps in the embodiments of the above-described infinite impulse response filtering method can be implemented by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. Therefore, this disclosure also provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program can implement the various processes in the embodiments of the above-described infinite impulse response filtering method. The computer-readable storage medium can be any medium capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0080] Since the program stored in the readable storage medium can execute the steps of any of the infinite impulse response filtering methods provided in the embodiments of this disclosure, the beneficial effects achievable by any of the infinite impulse response filtering methods provided in the embodiments of this disclosure can be realized, as detailed in the preceding embodiments, and will not be repeated here. The specific implementation of each of the above operations can be found in the preceding embodiments, and will not be repeated here.
[0081] It should be noted that in describing the various embodiments in this specification, the focus is on the differences from other embodiments, while the same or similar parts between the various embodiments can be understood by referring to each other. For the system embodiments, since they are basically similar to the method embodiments, the relevant parts can be referred to the description of the method embodiments.
[0082] Furthermore, it should be noted that in the apparatus and method of this disclosure, it is obvious that the components or steps can be decomposed and / or recombined. These decompositions and / or recombinations should be considered equivalent solutions of this disclosure. Moreover, the steps performing the above series of processes can naturally be executed in the order described, but are not necessarily required to be executed in chronological order; some steps can be executed in parallel or independently of each other. Those skilled in the art will understand that all or any step or component of the method and apparatus of this disclosure can be implemented in any computing device (including processors, storage media, etc.) or network of computing devices, in hardware, firmware, software, or a combination thereof, which can be achieved by those skilled in the art using their basic programming skills after reading the description of this disclosure.
[0083] Finally, it should be noted that the above embodiments are merely examples for clearly illustrating this disclosure and are not intended to limit the implementation. Those skilled in the art can make other variations or modifications based on the above description. It is neither necessary nor possible to exhaustively list all possible implementations here. However, obvious variations or modifications derived therefrom are still within the scope of this disclosure.
Claims
1. An infinite impulse response filtering method, characterized in that, The following steps are executed in parallel during the current clock cycle: Calculate the feedback values of the two input data in the current clock cycle based on the feedback values calculated in the previous clock cycles. In addition, based on the feedback value calculated in the previous clock cycle, the filtering result of the two input data in the previous clock cycle is calculated. In each clock cycle, the feedback value of the two input data is the feedback value of the two input data in the canonical infinite impulse response filter structure, and the filtering result of the two input data is the filtering result of the canonical infinite impulse response filter structure of the two input data. The two input data in the current clock cycle include the first input data and the second input data, wherein, The feedback value of the first input data is calculated using a first formula, which is: ; The feedback value of the second input data is calculated using a second formula, which is: ; Where x[n] represents the first input data, w[n] represents the feedback value of the first input data, x[n+1] represents the second input data, w[n+1] represents the feedback value of the second input data, and a i represents the first filter coefficient, L represents the filter order, and w[ni] represents the feedback value calculated from the clock cycle prior to the current clock cycle.
2. The infinite impulse response filtering method according to claim 1, characterized in that, Before calculating the feedback value of the second input data using the second formula, the method further includes: obtaining (a1a) j -a j+1 The calculation results and a1a L The calculation results; And, calculating the feedback value of the second input data using the second formula includes: using the obtained (a1a) in the second formula. j -a j+1 The calculation results and a1a L The calculation result is used to calculate the feedback value of the second input data.
3. The infinite impulse response filtering method according to claim 1, characterized in that, When the current clock cycle is the first clock cycle, w[ni]=0 in the first formula, and w[nj]=0 and w[nL]=0 in the second formula.
4. The infinite impulse response filtering method according to claim 1, characterized in that, The two input data in the previous clock cycle include the third input data and the fourth input data, where, The filtering result of the third input data is calculated using a third formula, which is: ; The filtering result of the fourth input data is calculated using a fourth formula, which is: ; Where y[m] represents the filtering result of the third input data, y[m+1] represents the filtering result of the fourth input data, and b k This represents the second filter coefficient, and m = n - 2.
5. The infinite impulse response filtering method according to claim 4, characterized in that, When the current clock cycle is the second clock cycle, in the third formula, if k>0, then w[mk]=0, and in the fourth formula, if k>1, then w[m+1-k]=0.
6. The infinite impulse response filtering method according to claim 4, characterized in that, The filter order is 2.
7. A filter, characterized in that, Perform the infinite impulse response filtering method according to any one of claims 1-6.
8. An image processor, characterized in that, include: The filter of claim 7 is used to filter an image in the horizontal direction to obtain the filtering result of each pixel in the image; And a sharpness calculation unit, which is used to determine the sharpness information of the image along the horizontal direction based on the filtering result.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program or instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1-6.