Image processing method and electronic equipment
By dynamically determining the scaling order, the image loss and computing power waste caused by fixed scaling order are solved according to the resolution ratio of the input and output images, and efficient and high-quality image scaling processing is achieved.
Patent Information
- Application Number
- CN202311444415.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-01
- Publication Date
- 2025-05-13
AI Technical Summary
In the image resolution scaling process, in the prior art, the fixed scaling order is too low, and the computing power is wasted when the calculation order is too high.
By dynamically determining the scaling order, flexibly selecting the scaling order based on the resolution ratio of the input and output images, reducing computing power waste and image loss.
It realizes the reduction of computing power waste and image loss during image processing, and improves the efficiency and quality of image scaling.
Smart Images

Figure CN119991406A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of image processing technology, and in particular to an image processing method and electronic device. Background Art
[0002] In video or picture display, in order to adapt to different display devices, it is usually necessary to enlarge or reduce the display content such as video or picture, that is, a processor such as ARM or CPU needs to use a scaling algorithm to enlarge or reduce the image.
[0003] In the resolution scaling process of an image, a fixed scaling order is usually used to process the image. For example, a first-order algorithm is used when speed is important, and a second-order algorithm is used when image quality is important. In this fixed scaling order method, if the fixed scaling order is too low but the reduction factor is too high, image loss will occur. If the fixed scaling order is too high but the reduction factor is not large, computing power will be wasted. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide an image processing method and an electronic device, which can dynamically determine the scaling order according to the input resolution and the output resolution, so as to reduce the waste of computing power and image loss during the image processing process.
[0005] In a first aspect, a technical solution adopted in an embodiment of the present application is: to provide an image processing method, comprising: obtaining an input resolution of an input image and an output resolution of an output image; obtaining a resolution ratio according to the input resolution and the output resolution; obtaining a scaling order according to the resolution ratio; and scaling the input image according to the scaling order to obtain the output image.
[0006] In some embodiments, the zoom order is obtained according to the resolution ratio, including: if the resolution ratio is less than 1, the zoom order is a preset order; if the resolution ratio is less than or equal to M, and the resolution ratio is greater than (M-1), the zoom order is M, where M is an integer greater than 1.
[0007] In some embodiments, the input image is scaled according to the scaling order to obtain the output image, including: if the resolution ratio is less than 1, the input image is enlarged according to the scaling order to obtain the output image; if the resolution ratio is greater than 1, the input image is reduced according to the scaling order to obtain the output image.
[0008] In some embodiments, the input resolution includes an input vertical resolution and an input horizontal resolution, the output resolution includes an output vertical resolution and an output horizontal resolution, and obtaining a resolution ratio based on the input resolution and the output resolution includes: obtaining a vertical ratio based on the input vertical resolution and the output vertical resolution; obtaining a horizontal ratio based on the input horizontal resolution and the output horizontal resolution; obtaining the resolution ratio based on the vertical ratio and the horizontal ratio.
[0009] In some embodiments, the vertical ratio is calculated by the following formula:
[0010] N1=Ri 1 / Ro1;
[0011] The horizontal ratio is calculated by the following formula:
[0012] N2=Ri 2 / Ro2;
[0013] Among them, N1 is the vertical ratio, N2 is the horizontal ratio, Ri 1 is the input vertical resolution, Ro1 is the output vertical resolution, Ri2 is the input horizontal resolution, and Ro2 is the output horizontal resolution.
[0014] In some embodiments, the resolution ratio is obtained according to the vertical ratio and the horizontal ratio; a maximum ratio is determined according to the vertical ratio and the horizontal ratio, and the maximum ratio is used as the resolution ratio.
[0015] In some embodiments, the resolution ratio is obtained based on the input resolution and the output resolution, including: if the input resolution is equal to the output resolution, using the input image as the output image; if the input resolution is not equal to the output resolution, obtaining the resolution ratio based on the input resolution and the output resolution.
[0016] In some embodiments, obtaining the zoom order according to the resolution ratio includes: obtaining a correspondence table, wherein the correspondence table stores a correspondence between the resolution ratio and the zoom order; and obtaining the zoom order according to the resolution ratio and the correspondence table.
[0017] In a second aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the image processing method as described in any one of the embodiments of the first aspect.
[0018] In a third aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the image processing method as described in any one of the embodiments of the first aspect above.
[0019] In a fourth aspect, an embodiment of the present application further provides a computer program product, wherein the computer program product comprises a computer program stored on a computer-readable storage medium, wherein the computer program comprises program instructions, and when the program instructions are executed by a computer, the computer executes the image processing method as described in any one of the embodiments of the first aspect above.
[0020] Compared with the prior art, the beneficial effects of the present application are as follows: Different from the prior art, the embodiments of the present application provide an image processing method and an electronic device, the image processing method comprising: obtaining an input resolution of an input image and an output resolution of an output image; obtaining a resolution ratio according to the input resolution and the output resolution; obtaining a scaling order according to the resolution ratio; performing scaling processing on the input image according to the scaling order to obtain an output image. The image processing method can dynamically determine the scaling order according to the input resolution and the output resolution, so that the problem of computing power waste and image loss can be reduced during the image processing process. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements / modules and steps with the same reference numerals in the drawings are represented as similar elements / modules and steps. Unless otherwise specified, the figures in the drawings do not constitute proportional limitations.
[0022] Figure 1 This is a schematic diagram of pixel interpolation in an image processing process provided by an embodiment of the present application;
[0023] Figure 2 This is another schematic diagram of pixel interpolation in an image processing process provided by an embodiment of the present application;
[0024] Figure 3 It is a flowchart of an image processing method provided in an embodiment of the present application;
[0025] Figure 4 This is a method provided by the embodiment of the present application. Figure 3 A schematic diagram of the process of step S20 in FIG.
[0026] Figure 5 It is a partial flow chart of an image processing method provided in an embodiment of the present application;
[0027] Figure 6 This is a method provided by the embodiment of the present application. Figure 3 A schematic diagram of the process of step S30 in FIG.
[0028] Figure 7 This is another schematic diagram of pixel interpolation in an image processing process provided by an embodiment of the present application;
[0029] Figure 8 This is a method provided by the embodiment of the present application. Figure 3 A schematic diagram of the process of step S40 in FIG.
[0030] Fig. 9 It is a structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] The present application is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present application, but do not limit the present application in any form. It should be noted that, for those of ordinary skill in the art, several variations and improvements can also be made without departing from the concept of the present application. These all belong to the protection scope of the present application.
[0032] For ease of understanding of the present application, the present application is described in more detail below in conjunction with the accompanying drawings and specific embodiments. Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as those generally understood by those skilled in the art of the present application. The terms used in the specification of the present application are only for the purpose of describing specific embodiments and are not used to limit the present application. The term "and / or" used in this specification includes any and all combinations of one or more related listed items.
[0033] It should be noted that, if there is no conflict, the various features in the embodiments of the present application can be combined with each other, all within the scope of protection of the present application. In addition, although the functional module division is performed in the device schematic, in some cases, the module division can be different from that in the device. In addition, the words "first", "second", etc. used herein do not limit the data and execution order, but only distinguish the same items or similar items with basically the same functions and effects.
[0034] The scaling order refers to the number of pixels in the horizontal and vertical directions of the input image that are required to participate in the calculation of one pixel in the output image during the image scaling process. It can be divided into 1st order, 2nd order, 4th order, or even higher orders. Take 2nd order as an example, please refer to Figure 1, the pixel (u, v) in the output image is generated based on the four pixel operations of the input image: pixel (i, j), pixel (i+1, j), pixel (i, j+1) and pixel (i+1, j+1). That is, one pixel of the output image requires the values of two pixels in the horizontal direction of the input image and the values of two pixels in the vertical direction of the input image to be interpolated and calculated.
[0035] At present, in image processing methods, a fixed order method is usually used for scaling. For example, a fixed low-order method can be used when processing speed is important, and a fixed high-order method can be used when image quality is important. The higher the scaling order, the higher the number of interpolated pixels required for calculation. When the image resolution is reduced, more original image information is retained. The lower the scaling order, the fewer interpolated pixels are calculated, but when the image resolution is reduced, more original image information is lost.
[0036] For example, when the scaling order is fixed at 2, when the ratio of the input horizontal resolution width to the output horizontal resolution width is greater than 2, according to the interpolation principle, it will cause the loss of original pixels, and the same is true for the vertical direction.
[0037] Specifically, if the resolution width of the input image is 8x8 and the resolution width of the output image is 2x2, then when using a fixed order of 2, refer to Figure 2 , the first pixel S1 in the output image only needs to be calculated based on the first pixel A1 in the horizontal direction, the second pixel A2 in the horizontal direction, the first pixel B1 in the vertical direction, and the second pixel B2 in the vertical direction of the input image; the second pixel S2 in the output image only needs to be calculated based on the third pixel A5 in the horizontal direction, the sixth pixel A6 in the horizontal direction, the fifth pixel B5 in the vertical direction, and the sixth pixel B6 in the vertical direction of the input image; and so on, the third pixel S3 in the output image and the fourth pixel S4 in the output image are calculated. It can be seen that when the image is output in a fixed 2-order manner, the reduced image only contains the image information in the dotted box in the input image, and loses a lot of pixel information of the original input image, and the output image will show some blurring such as jagged edges.
[0038] It can be seen that when a fixed low-order method is used, if the reduction factor is too high, it will cause image loss. When a fixed high-order method is used, if the reduction factor is not large, it will lead to a waste of computing power.
[0039] Based on this, the present application proposes an image processing method, in which the input resolution of the input image and the output resolution of the output image are used to flexibly select the scaling order to reduce the waste of computing power and image loss in the image reduction process.
[0040] In the first aspect, the present application provides an image processing method, see Figure 3 ,include:
[0041] Step S10: Obtain the input resolution of the input image and the output resolution of the output image.
[0042] The input resolution includes the image resolution of the input image in the horizontal direction and the image resolution of the input image in the vertical direction, that is, the input horizontal direction resolution and the input vertical direction resolution.
[0043] The output resolution includes the image resolution of the output image in the horizontal direction and the image resolution of the output image in the vertical direction, that is, the output horizontal direction resolution and the output vertical direction resolution.
[0044] The input resolution and the output resolution can be input into the electronic device through an input unit, so that the electronic device obtains the input resolution and the output resolution. The input unit can be a keyboard, a touch screen, or other device.
[0045] Step S20: Obtain a resolution ratio according to the input resolution and the output resolution.
[0046] After obtaining the input resolution and the output resolution, the resolution ratio can be calculated, and then the scaling order can be obtained according to the resolution ratio.
[0047] Step S30: Obtain the scaling order according to the resolution ratio.
[0048] After the resolution ratio is obtained, the scaling order can be calculated according to the resolution ratio.
[0049] Specifically, in some embodiments, a corresponding table may be obtained, and the zoom order may be obtained according to the resolution ratio and the corresponding table. The corresponding table stores the corresponding relationship between the resolution ratio and the zoom order, that is, the corresponding table stores the zoom order under different resolution ratios, so that the zoom order may be obtained according to the resolution ratio and the corresponding table. In practical applications, the corresponding table may be established in advance to save calculation time in the image processing process.
[0050] Step S40: scaling the input image according to the scaling order to obtain an output image.
[0051] After obtaining the scaling order, the number of pixels required in the input image corresponding to a pixel in the output image is obtained. Then, the input image can be scaled, such as by using neighboring interpolation, linear interpolation, cubic interpolation, Lanczos algorithm interpolation and other interpolation methods to achieve scaling to obtain the output image. The specific process of interpolating the input image according to the pixel value can refer to the existing technology and will not be repeated here.
[0052] In this embodiment, the zoom order is dynamically selected by using the resolution ratio obtained by the input resolution and the output resolution, which can reduce the loss of original image information and the waste of processor computing power.
[0053] In some of these examples, see Figure 4 , step S20 comprises:
[0054] Step S21: Obtain a vertical ratio according to the input vertical resolution and the output vertical resolution.
[0055] Specifically, the vertical ratio can be calculated by the following formula:
[0056] N1=Ri 1 / Ro1;
[0057] Among them, N1 is the vertical ratio, Ri 1 is the input vertical resolution, and Ro1 is the output vertical resolution.
[0058] Step S22: Obtain a horizontal ratio according to the input horizontal resolution and the output horizontal resolution.
[0059] Specifically, the horizontal ratio is calculated by the following formula:
[0060] N2=Ri 2 / Ro2;
[0061] Among them, N2 is the horizontal ratio, Ri2 is the input horizontal resolution, and Ro2 is the output horizontal resolution.
[0062] Step S23: Obtain a resolution ratio according to the vertical ratio and the horizontal ratio.
[0063] After obtaining the vertical ratio and the horizontal ratio, a comparison is performed to obtain the maximum ratio, and the maximum ratio is used as the resolution ratio.
[0064] In this embodiment, by selecting the maximum value of the vertical ratio and the horizontal ratio as the resolution ratio, the image processing effect can be improved when the zoom order is selected later.
[0065] In some of these examples, see Figure 5 , step S20 comprises:
[0066] Step S201: if the input resolution is equal to the output resolution, the input image is used as the output image;
[0067] Step S202: If the input resolution is not equal to the output resolution, a resolution ratio is obtained according to the input resolution and the output resolution.
[0068] In this embodiment, when the input resolution is equal to the output resolution, the input image does not need to be scaled and can be directly output as the output image. The resolution ratio is calculated only when the input resolution is not equal to the output resolution. In this way, the amount of calculation can be reduced when the image does not need to be scaled.
[0069] In some of these examples, see Figure 6 , step S30 comprises:
[0070] Step S31: If the resolution ratio is less than 1, the scaling order is a preset order.
[0071] If the resolution ratio is less than 1, that is, the input resolution is less than the output resolution, it is a scenario where the image is enlarged. In the scenario of enlargement, the scaling order can be fixed to a preset order, such as 2. In practical applications, the value of the preset order can also be other values. It is understandable that the higher the preset order, the more calculations are required during the enlargement process. Using 2 can reduce computing power and retain the information of the original input image in the scenario of enlargement.
[0072] Step S32: If the resolution ratio is less than or equal to M, and the resolution ratio is greater than (M-1), the scaling order is M, where M is an integer greater than 1.
[0073] When the resolution ratio is less than or equal to M, and the resolution ratio is greater than (M-1), that is, the input resolution is greater than the output resolution, it is a scene of image reduction. Among them, when A<1, it is a magnification scene, and the second-order algorithm is used. When A≤2 and A>1, the second-order algorithm is used, when A≤3 and A>2, the third-order algorithm is used, and so on.
[0074] For details, please refer to Figure 7 If the input resolution of the input image is 8x8 and the output resolution of the output image is 2x2, the resolution ratio is 4, and the scaling order is 4. At this time, when the 4th-order algorithm is used, each pixel in the input image can be involved in the calculation, so that the original image information can be retained to a certain extent.
[0075] It can be seen that in the scenario of reduction processing, dynamically determining the scaling order in the above manner can reduce computing power and retain the original image information in the scenario of reduction processing.
[0076] In some of these examples, see Figure 8 , step S40 comprises:
[0077] Step S41: if the resolution ratio is less than 1, the input image is enlarged according to the zoom order to obtain an output image;
[0078] Step S42: If the resolution ratio is greater than 1, the input image is scaled down according to the scaling order to obtain an output image.
[0079] In this embodiment, whether to enlarge or reduce the image is determined by the resolution ratio, which can improve the accuracy of image scaling and display effect.
[0080] In a second aspect, the present application also provides an electronic device, see Fig. 9 , which shows that it is possible to execute Figures 3 to 6 , Figure 8 The hardware structure of the electronic device of the image processing method.
[0081] The electronic device 100 includes: at least one processor 110; and a memory 120 connected to the at least one processor 110 for communication. Fig. 9 The memory 120 stores instructions that can be executed by at least one processor 110, and the instructions are executed by at least one processor 110 so that at least one processor 110 can perform the above Figures 3 to 6 , Figure 8 The processor 110 and the memory 120 may be connected via a bus or other means. Fig. 9 The example of connecting through bus is taken in the following.
[0082] The memory 120 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions / modules corresponding to the image processing method in the embodiment of the present application. The processor 110 executes various functional applications and data processing of the server by running the non-volatile software programs, instructions and modules stored in the memory 120, that is, implements the image processing method in the above method embodiment.
[0083] The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required by at least one function; the data storage area may store data created according to the use of the image processing device, etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 120 may optionally include a memory remotely arranged relative to the processor 110, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0084] One or more modules are stored in the memory 120, and when executed by one or more processors 110, perform the image processing method in any of the above method embodiments, for example, perform the above described image processing method. Figures 3 to 6 , Figure 8 The image processing method steps.
[0085] The above product can execute the image processing method provided in the embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in this embodiment, please refer to the image processing method provided in the embodiment of the present application.
[0086] The present application also provides a non-volatile computer-readable storage medium, which stores computer-executable instructions. The computer-executable instructions are executed by one or more processors, for example, to execute the above-described Figures 3 to 6 , Figure 8 The image processing method steps.
[0087] The present application also provides a computer program product, including a computer program stored on a non-volatile computer-readable storage medium, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes the image processing method in any of the above method embodiments, for example, executing the above described Figures 3 to 6 , Figure 8 The steps of the image processing method.
[0088] It should be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0089] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions to use at least one computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.
[0090] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Under the concept of the present application, the technical features in the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other changes in different aspects of the present application as described above, which are not provided in detail for the sake of simplicity. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features can be replaced by equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.
Claims
1. An image processing method, characterized in that: include: Get the input resolution of the input image and the output resolution of the output image; Obtaining a resolution ratio according to the input resolution and the output resolution; According to the resolution ratio, a scaling order is obtained; The input image is scaled according to the scaling order to obtain the output image.
2. The image processing method according to claim 1, characterized in that: The obtaining the scaling order according to the resolution ratio includes: If the resolution ratio is less than 1, the scaling order is a preset order; If the resolution ratio is less than or equal to M, and the resolution ratio is greater than (M-1), then the scaling order is M, where M is an integer greater than 1.
3. The image processing method according to claim 1 or 2, characterized in that: The step of performing scaling processing on the input image according to the scaling order to obtain the output image comprises: If the resolution ratio is less than 1, the input image is enlarged according to the zoom order to obtain the output image; If the resolution ratio is greater than 1, the input image is scaled down according to the scaling order to obtain the output image.
4. The image processing method according to claim 1 or 2, characterized in that: The input resolution includes an input vertical resolution and an input horizontal resolution, the output resolution includes an output vertical resolution and an output horizontal resolution, and obtaining a resolution ratio according to the input resolution and the output resolution includes: Obtaining a vertical ratio according to the input vertical resolution and the output vertical resolution; Obtaining a horizontal ratio according to the input horizontal resolution and the output horizontal resolution; The resolution ratio is obtained according to the vertical ratio and the horizontal ratio.
5. The image processing method according to claim 4, characterized in that: The vertical ratio is calculated by the following formula: N1=Ri 1 / Ro1; The horizontal ratio is calculated by the following formula: N2=Ri 2 / Ro2; Among them, N1 is the vertical ratio, N2 is the horizontal ratio, Ri 1 is the input vertical resolution, Ro1 is the output vertical resolution, Ri2 is the input horizontal resolution, and Ro2 is the output horizontal resolution.
6. The image processing method according to claim 5, characterized in that: Obtaining the resolution ratio according to the vertical ratio and the horizontal ratio; A maximum ratio is determined according to the vertical ratio and the horizontal ratio, and the maximum ratio is used as the resolution ratio.
7. The image processing method according to claim 1 or 2, characterized in that: The obtaining of a resolution ratio according to the input resolution and the output resolution includes: If the input resolution is equal to the output resolution, the input image is used as the output image; If the input resolution is not equal to the output resolution, the resolution ratio is obtained according to the input resolution and the output resolution.
8. The image processing method according to claim 1, wherein obtaining the scaling order according to the resolution ratio comprises: Obtaining a correspondence table, wherein the correspondence table stores a correspondence between a resolution ratio and a zoom order; The scaling order is obtained according to the resolution ratio and the corresponding table.
9. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the method according to any one of claims 1 to 8.