Image interpolation method, device and computer readable storage medium
By distinguishing between flat and non-flat regions in image interpolation and using difference value judgment and different interpolation algorithms, the problem of images failing to render details in flat regions is solved, thus improving image detail.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANNING FUGUI PRECISION IND CO LTD
- Filing Date
- 2021-09-30
- Publication Date
- 2026-05-29
AI Technical Summary
In existing technologies, images cannot effectively render details in flat areas.
By selecting a 2*2 pixel area, the difference value of the RGB three color gamut values is calculated to determine whether the pixel is a flat area, and different interpolation algorithms are selected for interpolation based on the difference value, including the first interpolation algorithm and the second interpolation algorithm.
It improves the color gradation in flat areas of the image and increases detail in both dark and bright areas.
Smart Images

Figure CN115908125B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to image interpolation technology, and in particular to an image interpolation method, apparatus and computer-readable storage medium. Background Technology
[0002] In existing techniques, the image to be interpolated is divided into M x N squares. The mean square error of grayscale at the four endpoints of each gray square is calculated and compared with a threshold to determine whether the square is a flat or complex area. Then, different interpolation methods are selected based on the region. This method directly uses a threshold as the judgment benchmark and cannot reproduce details in flat areas. Summary of the Invention
[0003] In view of the above, it is necessary to provide an image interpolation method, apparatus and computer-readable storage medium that can solve the technical problem that images cannot present details in flat areas in the prior art.
[0004] This invention provides an image interpolation method, comprising: selecting a 2*2 pixel region in a target image and obtaining the RGB three-color gamut values of all pixels; sequentially reading the RGB three-color gamut values of four pixels, calculating the difference between the RGB three-color gamut values of the four pixels, and determining whether the four pixels are a flat region based on the difference; if the four pixels are not a flat region, performing interpolation using a first interpolation algorithm, and if the four pixels are not a flat region, performing interpolation using a second interpolation algorithm; traversing all pixels in the target image until all pixels have been interpolated; and outputting the interpolated target image.
[0005] Optionally, the second interpolation algorithm is a quadratic interpolation method.
[0006] Optionally, when the four pixels are not flat areas, the four pixels are at the boundary or in a complex area.
[0007] Optionally, determining whether the four pixels are flat regions based on the difference value includes: if the difference value of at least two of the three color gamuts is less than a preset value, then the four pixels are determined to be flat regions; otherwise, they are not flat regions.
[0008] Optionally, when determining whether the four pixels are flat regions, the first interpolation algorithm is used for interpolation, which includes: when the difference between two of the three color gamuts is less than a preset value, and the difference between the remaining one is greater than a predetermined value, it is determined that the four pixels are of the same color system but different colors, and the color gamut with the largest difference value is subjected to 4-pixel to 16-pixel interpolation calculation.
[0009] Optionally, when determining whether the four pixels are flat regions, the first interpolation algorithm is used for interpolation, which includes: when the difference values of the three color gamuts are all less than a preset value, it is determined that the four pixels are the same color, and then one of the four pixels is used for direct interpolation.
[0010] This invention also provides an apparatus comprising a memory, a processor, and an image interpolation program stored in the memory and executable on the processor. When executed by the processor, the image interpolation program implements the steps of the image interpolation method described above.
[0011] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the image interpolation method described above.
[0012] Compared to existing technologies, the image interpolation method, apparatus, and computer-readable storage medium described herein can distinguish between flat and non-flat areas, and for flat areas of an image, increase color levels and improve details in dark and bright areas. Attached Figure Description
[0013] Figure 1 This is a diagram illustrating the operating environment of a device according to a preferred embodiment of the present invention.
[0014] Figure 2 This is a program module diagram of a preferred embodiment of the image interpolation system of the present invention.
[0015] Figure 3 This is a flowchart of an image interpolation method according to a preferred embodiment of the present invention.
[0016] Figure 4 This is a schematic diagram of the RGB three-color gamut values of four pixels of the target image in a preferred embodiment of the present invention.
[0017] Explanation of main component symbols
[0018] Device 1 Image interpolation system 10 memory 20 processor 30 Get Module 101 Calculation module 102 Judgment Module 103 Interpolation module 104 Output module 105 step S300~S312 Detailed Implementation
[0019] See Figure 1 The diagram shown illustrates the operating environment of a preferred embodiment of device 1 according to the present invention. Device 1 includes an operating image interpolation system 10. Device 1 also includes a memory 20 and a processor 30, etc.
[0020] The memory 20 includes at least one type of readable storage medium, such as flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. The processor 30 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip.
[0021] See Figure 2 The diagram shown is a program block diagram of a preferred embodiment of the image interpolation system 10 of the present invention.
[0022] The image interpolation system 10 includes an acquisition module 101, a calculation module 102, a judgment module 103, an interpolation module 104, and an output module 105. The modules are configured to be executed by one or more processors (in this embodiment, one processor 30) to complete the invention. A module, as referred to in this invention, is a computer program segment that executes a specific instruction. The memory 20 is used to store the program code and other data of the image interpolation system 10. The processor 30 is used to execute the program code stored in the memory 20.
[0023] The acquisition module 101 is used to select a 2*2 pixel region in the target image and acquire the RGB three-color gamut values of all pixels.
[0024] In this embodiment, the target image is the image to be interpolated. Color is composed of RGB three colors, and the range of RGB pixel values can be represented by the interval [0, 255]. Normally, the human retina contains three types of cone cells: red, green, and blue, also known as the three primary colors.
[0025] The calculation module 102 is used to read the RGB three-color gamut values of four pixels in sequence and calculate the difference between the RGB three-color gamut values of the four pixels.
[0026] Divide the interval [0, 255] into N equal parts. Within the preset interval range, the default color is the same. For example, if the RGB pixel value is an integer, then divide [0, 255] into 80 equal parts. If the pixel value difference is within the preset interval range of 3, the default color is the same.
[0027] The judgment module 103 is used to determine whether the four pixels are flat areas based on the difference value.
[0028] In this embodiment, non-flat regions include boundaries and complex regions. When four pixels are not in a flat region, they are located at either a boundary or a complex region. Specifically, determining whether the four pixels are flat regions based on the difference value includes: if the difference value of at least two of the three color gamuts is less than a preset value, then the four pixels are determined to be flat regions; otherwise, they are non-flat regions.
[0029] For example, if the preset value is set to the range of 3 mentioned above, that is, when the difference between two color gamuts in the three color gamuts is less than 3 or the difference between all three color gamuts is less than 3, then the four pixels are determined to be a flat area; otherwise, they are non-flat areas. Figure 4 As shown, a 2x2 pixel region is selected in the target image, and four pixels are taken from the top, bottom, left, and right sides. The RGB color gamut values of the four pixels are read respectively: A1[R1,G1,B1], A2[R2,G2,B2], B1[R3,G3,B3], and B2[R4,G4,B4]. Calculate whether the difference between the RGB color gamut values of the four pixels is ≤3.
[0030] The interpolation module 104 is used to perform interpolation using the first interpolation algorithm when the judgment module 103 determines that the four pixels are flat areas.
[0031] Specifically, when determining whether the four pixels form a flat region, the first interpolation algorithm is used for interpolation. The first interpolation algorithm is as follows:
[0032] As mentioned above, when the difference between two color gamuts in the three color gamuts is less than a preset value or when the difference between all three color gamuts is less than a preset value, the four pixels are determined to be flat areas.
[0033] The first case is:
[0034] When the difference values of the three color gamuts are all less than the preset value, it is determined that the four pixels are the same color, and one of the four pixels is directly interpolated.
[0035] For example, if the difference values of all three color gamuts are less than 3, at least one of the four pixels is selected to fill the remaining 12 pixels.
[0036] The second scenario: When the difference between two of the three color gamuts is less than a preset value, while the difference between the remaining one is greater than a predetermined value, it is determined that the four pixels are of the same color system but different colors. Then, the color gamut with the largest difference value is subjected to 4-pixel to 16-pixel interpolation calculation.
[0037] For example, if the difference between two of the three color gamuts is less than 3, while the difference between the remaining one is greater than 3, the original 4 pixels are filled into the four corners, linear interpolation is performed between each pair of corners, and the calculated pixels are filled in.
[0038] By judging the flat areas as described above, we can filter whether they are the same color or the same color system. If they are the same color, we can directly copy the RGB pixel values, saving calculation time.
[0039] The interpolation module 104 is also used to perform interpolation using a second interpolation algorithm when the judgment module 103 determines that the four pixels are non-flat regions.
[0040] Specifically, when the four pixels are not in a flat region, a second interpolation algorithm is used for interpolation. In this embodiment, the second interpolation algorithm is a quadratic interpolation method.
[0041] Quadratic interpolation is a method used to search for the minimum point of a univariate function within a defined initial interval. If the approximation does not yet meet the required accuracy, this method can be used repeatedly to fit the function until the given accuracy is achieved. This will not be elaborated further in this case.
[0042] The interpolation module 104 is also used to traverse all pixels in the target image until all pixels have been interpolated.
[0043] Specifically, the interpolation algorithm is used to sequentially take four pixels from the target image and perform the interpolation until all pixels have been interpolated.
[0044] Output module 105 is used to output the interpolated target image.
[0045] By applying the above method to the above device, it is possible to increase color levels and improve details in both dark and bright areas of the image, especially in flat areas.
[0046] See Figure 3 The diagram shows a flowchart of an image interpolation method according to a preferred embodiment of the present invention. The image interpolation method is applied to device 1. The image interpolation method can be executed by the processor 30. Figure 2 It is implemented by modules 101 to 105 shown.
[0047] Step S300: Select a 2*2 pixel region in the target image and obtain the RGB three-color gamut values of all pixels.
[0048] In this embodiment, the target image is the image to be interpolated. Color is composed of RGB three colors, and the range of RGB pixel values can be represented by the interval [0, 255]. Normally, the human retina contains three types of cone cells: red, green, and blue, also known as the three primary colors.
[0049] Step S302: Read the RGB three-color gamut values of the four pixels in sequence and calculate the difference between the RGB three-color gamut values of the four pixels.
[0050] Divide the interval [0, 255] into 100 equal parts. Within the preset interval, the default color will be the same. For example, if the RGB pixel value is an integer, then divide [0, 255] into 80 equal parts. If the pixel value difference is within the preset interval range of 3, the default color will be the same.
[0051] Step S304: Determine whether the four pixels are flat regions based on the difference value. If the four pixels are flat regions, proceed to step S306; if the four pixels are non-flat regions, proceed to step S308.
[0052] In this embodiment, non-flat regions include boundaries and complex regions. When four pixels are not in a flat region, they are located at either a boundary or a complex region. Specifically, determining whether the four pixels are flat regions based on the difference value includes: if the difference value of at least two of the three color gamuts is less than a preset value, then the four pixels are determined to be flat regions; otherwise, they are non-flat regions.
[0053] For example, if the preset value is set to the range of 3 mentioned above, that is, when the difference between two color gamuts in the three color gamuts is less than 3 or the difference between all three color gamuts is less than 3, then the four pixels are determined to be a flat area; otherwise, they are non-flat areas. Figure 4 As shown, a 2x2 pixel region is selected in the target image, and four pixels are taken from the top, bottom, left, and right sides. The RGB color gamut values of the four pixels are read respectively: A1[R1,G1,B1], A2[R2,G2,B2], B1[R3,G3,B3], and B2[R4,G4,B4]. Calculate whether the difference between the RGB color gamut values of the four pixels is ≤3.
[0054] Step S306: Perform interpolation using the first interpolation algorithm.
[0055] Specifically, when determining whether the four pixels form a flat region, the first interpolation algorithm is used for interpolation. The first interpolation algorithm is as follows:
[0056] As mentioned above, when the difference between two color gamuts in the three color gamuts is less than a preset value or when the difference between all three color gamuts is less than a preset value, the four pixels are determined to be flat areas.
[0057] The first case is:
[0058] When the difference values of the three color gamuts are all less than the preset value, it is determined that the four pixels are the same color, and one of the four pixels is directly interpolated.
[0059] For example, if the difference values of all three color gamuts are less than 3, at least one of the four pixels is selected to fill the remaining 12 pixels.
[0060] The second scenario: When the difference between two of the three color gamuts is less than a preset value, while the difference between the remaining one is greater than a predetermined value, it is determined that the four pixels are of the same color system but different colors. Then, the color gamut with the largest difference value is subjected to 4-pixel to 16-pixel interpolation calculation.
[0061] For example, if the difference between two of the three color gamuts is less than 3, while the difference between the remaining one is greater than 3, the original 4 pixels are filled into the four corners, linear interpolation is performed between each pair of corners, and the calculated pixels are filled in.
[0062] By judging the flat areas as described above, we can filter whether they are the same color or the same color system. If they are the same color, we can directly copy the RGB pixel values, saving calculation time.
[0063] Step S308: Use the second interpolation algorithm to perform interpolation.
[0064] Specifically, when the four pixels are not in a flat region, a second interpolation algorithm is used for interpolation. In this embodiment, the second interpolation algorithm is a quadratic interpolation method.
[0065] Quadratic interpolation is a method used to search for the minimum point of a univariate function within a defined initial interval. If the approximation does not yet meet the required accuracy, this method can be used repeatedly to fit the function until the given accuracy is achieved. This will not be elaborated further in this case.
[0066] Step S310: Traverse all pixels in the target image until all pixels have been interpolated.
[0067] Specifically, steps S300 to S308 are repeated sequentially, taking four pixels from the target image, until all pixels have been interpolated.
[0068] Step S312: Output the interpolated target image.
[0069] By applying the above method to the above device, it is possible to increase color levels and improve details in both dark and bright areas of the image, especially in flat areas.
[0070] It is worth noting that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. An image interpolation method, characterized in that, The method includes: Select a 2x2 pixel region in the target image and obtain the RGB three-color gamut values of all pixels; Read the RGB three-color gamut values of 4 pixels in sequence, calculate the difference value of the RGB three-color gamut values of 4 pixels, and determine whether the 4 pixels are flat areas based on the difference value; When the four pixels are flat areas, the first interpolation algorithm is used for interpolation; when the four pixels are not flat areas, the second interpolation algorithm is used for interpolation. Iterate through all pixels in the target image until all pixels have been interpolated; Output the interpolated target image; When the four pixels form a flat region, the first interpolation algorithm is used for interpolation, including: When the difference between two of the three color gamuts is less than a preset value, while the difference between the remaining one is greater than a predetermined value, it is determined that the four pixels are of the same color system but different colors. Then, the color gamut with the largest difference value is subjected to 4-pixel to 16-pixel interpolation calculation.
2. The image interpolation method as described in claim 1, characterized in that, The second interpolation algorithm is a quadratic interpolation method.
3. The image interpolation method as described in claim 2, characterized in that, When four pixels are not flat areas, they are either at the boundary or in a complex area.
4. The image interpolation method as described in claim 1, characterized in that, The step of determining whether the four pixels are flat regions based on the difference value includes: If the difference between at least two of the three color gamuts is less than a preset value, then the four pixels are determined to be flat regions; otherwise, they are not flat regions.
5. The image interpolation method as described in claim 1, characterized in that, When the four pixels form a flat region, the first interpolation algorithm is used for interpolation, including: When the difference values of the three color gamuts are all less than the preset value, it is determined that the four pixels are the same color, and one of the four pixels is directly interpolated.
6. An apparatus, characterized in that, The apparatus includes a memory, a processor, and an image interpolation program stored in the memory and executable on the processor, wherein the image interpolation program, when executed by the processor, implements the steps of the image interpolation method as described in any one of claims 1 to 5.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the image interpolation method as described in any one of claims 1 to 5.