An image downscaling processing method and apparatus
By dividing the image into blocks and unifying pixel values, combined with a bilinear interpolation downsizing algorithm, image downsizing is performed in two steps, solving the problem of high computational resource consumption in existing technologies and achieving faster image downsizing speed.
Patent Information
- Application Number
- CN202111171297.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-08
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2041-10-08
AI Technical Summary
In existing technologies, bilinear interpolation algorithms consume a lot of computational resources and have high computational complexity during image downsizing, resulting in slow image downsizing speed.
The input image is divided into multiple image blocks of equal area. The pixel value of each image block is unified to a single pixel value. Then, the image is processed based on the bilinear interpolation reduction factor. The reduction operation is carried out in two steps: first, it is reduced by 2^M times, and then it is reduced by N/(2^M) times.
It reduces the consumption of computing resources, improves the speed and efficiency of image downsizing, and reduces computational complexity.
Smart Images

Figure CN113989114B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of image processing, in particular, to an image reduction processing method and device. BACKGROUND
[0002] Picture is the visual basis for human to perceive the world, and is an important means for human to acquire and express information. At present, more researches are on digital picture, which is an abstract picture generated by continuous function or discrete function and can be directly processed by computer. Image scaling is an important part of digital picture processing, and in practical application, image is often enlarged or reduced. Image is an indispensable part in the fields of image storage, image transmission, image video production and biological identity recognition.
[0003] There are many kinds of image scaling algorithms, and almost all of them are implemented by interpolation algorithm. In the commonly used image interpolation algorithm, the implementation of nearest neighbor interpolation enlargement algorithm is the simplest and most convenient, but it only copies the original pixel to its neighborhood, and the enlarged image will have obvious square or sawtooth, and cannot well preserve the edge information of the original image. Bilinear interpolation is a more practical enlargement method, which can well eliminate the sawtooth, and the enlarged image has good smoothness and high quality of the scaled image. However, compared with the nearest neighbor interpolation, it has large calculation amount and involves more multiplication and division operations in calculation.
[0004] In the traditional mode, when the image is reduced by N (N is any real number greater than 1) times by using the bilinear template, the side length of the template used is 2*N. When the signal is sampled downward, a relatively long filter is used to avoid high frequency aliasing, and the longer the filter is, the larger the calculation amount is, which increases the complexity of the operation. SUMMARY
[0005] The embodiment of the present application provides an image reduction processing method and device, so as to at least solve the problem of large occupation of calculation resources in the prior art bilinear interpolation.
[0006] According to one aspect of the present application, an image reduction processing method is provided, comprising: acquiring image information of an input image and a reduction multiple, wherein the image information of the input image comprises image width and image height; dividing the image into a plurality of image blocks with equal area according to the image information of the input image; unifying the values of all pixel points in each image block into one pixel point value to obtain a unified image; obtaining a bilinear interpolation reduction multiple according to the size of the image block and the reduction multiple; and performing bilinear interpolation reduction processing on the unified image according to the bilinear interpolation reduction multiple to obtain a target image.
[0007] Further, the step of unifying the values of all pixel points in each image block into a pixel point value comprises: taking an average value of the pixel values in each image block, and taking the average value as the value of a corresponding pixel point of the unified image block.
[0008] Further, the step of dividing the image into multiple image blocks with equal areas according to the image information of the input image comprises: dividing the image into multiple image blocks with a size of (2^M)*(2^M), wherein 2^M≤N<2^(M+1), M is an integer, and N is the reduction multiple of the input image.
[0009] Further, the step of obtaining the target image by performing bilinear interpolation reduction processing on the unified image according to the bilinear interpolation reduction multiple comprises: reducing the image that has been reduced by 2^M times by N / (2^M) times based on 2*2 bilinear interpolation to obtain the target image.
[0010] According to another aspect of the present application, an image reduction processing apparatus is also provided, comprising: an acquisition module configured to acquire image information of an input image and a reduction multiple, wherein the image information of the input image comprises an image width and an image height; a division module configured to divide the image into multiple image blocks with equal areas according to the image information of the input image; a unification module configured to unify the values of all pixel points in each image block into a pixel point value to obtain a unified image; an obtaining module configured to obtain a bilinear interpolation reduction multiple according to the size of the image block and the reduction multiple; and a bilinear module configured to obtain a target image by performing bilinear interpolation reduction processing on the unified image according to the bilinear interpolation reduction multiple.
[0011] Further, the unification module is configured to: take an average value of the pixel values in each image block, and take the average value as the value of a corresponding pixel point of the unified image block.
[0012] Further, the division module is configured to: divide the image into multiple image blocks with a size of (2^M)*(2^M), wherein 2^M≤N<2^(M+1), M is an integer, and N is the reduction multiple of the input image.
[0013] Further, the bilinear module is configured to: reduce the image that has been reduced by 2^M times by N / (2^M) times based on 2*2 bilinear interpolation to obtain the target image.
[0014] According to another aspect of the present application, a storage medium for storing a program is also provided, wherein the program is used to execute the above-mentioned method.
[0015] According to another aspect of the present application, there is also provided a processor for running a program for performing the above method.
[0016] In the embodiment of the present application, the image information of an input image and a reduction factor are acquired, the input image information includes image width and image height; the image is divided into a plurality of image blocks with equal area size according to the image information of the input image; the values of all pixel points in each image block are unified into one pixel point value to obtain a unified image; a reduction factor for the bilinear interpolation reduction is obtained according to the size of the image block and the reduction factor; and a target image is obtained by performing bilinear interpolation reduction on the unified image according to the bilinear interpolation reduction factor. The present application solves the problem of large occupation of computing resources in the prior art bilinear interpolation, thereby reducing the occupation of computing resources and improving the image reduction speed. BRIEF DESCRIPTION OF DRAWINGS
[0017] The accompanying drawings, which form a part of the present application, are intended to provide further understanding of the present application and are incorporated herein for a purpose of explanations. The illustrative embodiments of the present application, together with their description, are employed to explain the application and do not constitute improper limitations to the application. In the drawings:
[0018] Figure 1 is a flowchart of an image reduction processing method according to an embodiment of the present application. DETAILED DESCRIPTION
[0019] It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0020] It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a group of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described herein can be executed in an order different from that shown herein.
[0021] In the present embodiment, an image reduction processing method is provided, Figure 1 is a flowchart of an image reduction processing method according to an embodiment of the present application, as Figure 1 shown, the flow includes the following steps:
[0022] In step S102, the image information of an input image and a reduction factor are acquired, the input image information includes image width and image height;
[0023] In step S104, the image is divided into a plurality of image blocks with equal area size according to the image information of the input image;
[0024] For example, the image can be divided into a plurality of image blocks with a size of (2^M)*(2^M), where 2^M≤N<2^(M+1), M is an integer, and N is the reduction factor of the input image.
[0025] In step S106, the values of all pixel points in each image block are unified into a pixel point value, and a unified image is obtained.
[0026] For example, the average value of all pixel values in each image block can be obtained, and the average value is taken as the value of a pixel point corresponding to the unified image block.
[0027] In another optional embodiment, for each image block, all pixel values in the image block are obtained, a threshold value is obtained, the proportion of pixel values less than the threshold value in all pixels of the image is less than or equal to 20%, and the proportion of pixel values greater than or equal to the threshold value in all pixels of the image is greater than or equal to 80%, the average value of all pixel values greater than or equal to the threshold value in the image block is obtained, and the average value is taken as the value of a pixel point corresponding to the unified image block.
[0028] In step S108, the reduction factor of the bilinear interpolation is obtained according to the size of the image block and the reduction factor.
[0029] In step S110, the unified image is subjected to bilinear interpolation reduction processing according to the bilinear interpolation reduction factor, and a target image is obtained.
[0030] For example, the image that has been reduced by 2^M times can be reduced by N / (2^M) times based on the bilinear interpolation of 2*2 to obtain the target image.
[0031] The above steps solve the problem of large occupation of computing resources in the prior art bilinear interpolation, thereby reducing the occupation of computing resources and improving the image reduction speed.
[0032] In this embodiment, an algorithm is provided, in which a first reduction is performed first, and then a second reduction is performed. The first reduction uses the pixel average value method, which is relatively fast in calculation speed. The second reduction uses the existing scaling method, for example, bilinear interpolation. Compared with directly using the existing scaling method on the original image, this processing method occupies the least resources and is relatively efficient.
[0033] In the embodiment, an integer M is calculated first, so that: 2^M≤N<2^(M+1). M is the integer part of log(N), then the image is divided into several blocks of (2^M)*(2^M) size, and the average value of each block is used to replace the block, thus generating an image which is reduced by 2^M times. Finally, the image is reduced by N / (2^M) times by using a 2*2 bilinear template, to generate the target image. The two steps are as follows: the first step is to reduce the image by 2^M times, so only addition is needed, and the sum is right shifted by M bits; the second step is to use a 2*2 bilinear interpolation template, and each pixel only needs to perform 3 multiplication and addition operations, and no special template coefficient calculation is needed. The advantage is to reduce the amount of calculation and complexity.
[0034] The algorithm comprises the following steps: obtaining image information of an input image and a reduction multiple N, the image information comprising image width and image height; calculating an adjustment factor M according to the reduction multiple N, M being an integer; cutting the input image in the width direction and the height direction respectively and then multiplying to obtain P image blocks of the same size, each image block having a size of (2^M)*(2^M), 2^M≤N<2^(M+1); generating an image which is reduced by 2^M times based on the average value of each image block; and reducing the image which is reduced by 2^M times by N / (2^M) times based on a 2*2 bilinear template to obtain a target image.
[0035] In the case of meeting the above conditions, M can have many values. If M has a large value, the size of each image block is large, and the resource required for the reduction processing is small. If M has a small value, the size of each image block is small, and the resource required for the scaling processing is large. The quality of the image reduced by a large M value is lower than that of the image reduced by a small M value.
[0036] In an optional embodiment, all possible M values are listed, the currently available computing resources of a computing node used for image reduction are obtained, and the smallest M value that can be processed by the computing resources is selected from the M values according to the computing resources.
[0037] In an alternative embodiment, the different size images can be processed with different reduction factors in advance using the bilinear interpolation algorithm, and the calculation resources consumed and the time required for processing in various image reduction processing situations are recorded. In the above embodiment, the calculation resources currently available to the calculation node are obtained, and the calculation resources are used to search the pre-stored record for a plurality of image reduction situations that can be processed, wherein each reduction situation includes an original picture size and a reduction factor; if the original picture size in a reduction situation is between the size of the image to be reduced in the embodiment and (the size of the image to be reduced / N), the reduction factor corresponding to the original picture size in the reduction situation is obtained, and the value of M is obtained according to the reduction factor.
[0038] Suppose the reduction factor is Y, the reduction factor used in the above step in the embodiment is Y, the reduction factor of the first reduction in the above step is N / Y, and the pixel value in each image block is Z, wherein Z is the nearest N / Y 2 exponent, for example, N / Y is 7, and Z is 8, at this time M is 3, N / Y is 13, and Z is 16, at this time M is 4, wherein M is the exponent.
[0039] If the original picture size in each of a plurality of reduction situations is between the size of the image to be reduced and (the size of the image to be reduced / N), the processing time corresponding to each reduction situation is obtained, and the reduction factor corresponding to the original picture size with the least processing time is selected.
[0040] The bilinear interpolation algorithm used in the bilinear template is described below. It should be noted that the bilinear interpolation algorithm is an algorithm in the prior art, and only a brief introduction is given here without detailed description.
[0041] Suppose the source image size is m*n, and the target image is a*b. Then the side length ratios of the two images are m / a and n / b. Note that this ratio is usually not an integer, and a floating point type should be used when programming and storing. The (i,j)th pixel point (i row j column) of the target image can be mapped back to the source image through the side length ratio. The corresponding coordinates are (i*m / a, j*n / b).
[0042] Obviously, this corresponding coordinate is generally not an integer, and a non-integer coordinate cannot be used on discrete data such as an image. Bilinear interpolation calculates the value (gray value or RGB value) of the point by finding the four nearest pixel points to the corresponding coordinate. If your corresponding coordinate is (2.5, 4.5), then the four nearest pixels are (2, 4), (2, 5), (3, 4), and (3, 5).
[0043] If the image is a gray image, the gray value of the (i,j) point can be calculated by the following formula:
[0044] f(i,j) = w1*p1 + w2*p2 + w3*p3 + w4*p4; where pi (i = 1, 2, 3, 4) is the nearest four pixel points, and wi (i = 1, 2, 3, 4) is the corresponding weight of each point. The calculation of the weight is described in the prior art, and will not be repeated here.
[0045] In one example, the known red data points and the green points to be interpolated are known. If the value of the unknown function f at point P = (x, y) is to be obtained, and the values of the function f at Q11 = (x1, y1), Q12 = (x1, y2), Q21 = (x2, y1) and Q22 = (x2, y2) are known. First, linear interpolation is performed in the x direction to obtain R1 and R2, and then linear interpolation is performed in the y direction to obtain P. Thus, the desired result f(x, y) is obtained. The red points Q11, Q12, Q21 and Q22 are the known four pixel points. First step: linear interpolation in the x direction, inserting blue point R2 in Q12 and Q22, and inserting blue point R1 in Q11 and Q21; second step: linear interpolation in the y direction, calculating point P by interpolating R1 and R2 in the y direction according to the calculation of the first step.
[0046] The result of linear interpolation is independent of the order of interpolation. First performing interpolation in the y direction and then performing interpolation in the x direction, the result is the same. The result of bilinear interpolation is independent of which direction is selected first. If a coordinate system is selected such that the coordinates of the four known points are (0, 0), (0, 1), (1, 0) and (1, 1) respectively, then the interpolation formula can be simplified as:
[0047] f(x, y) = f(0, 0)(1-x)(1-y) + f(1, 0)x(1-y) + f(0, 1)(1-x)y + f(1, 1)xy.
[0048] The above is a simple introduction to bilinear interpolation in the prior art. There are also some improved algorithms in the prior art, which can be used in the present embodiment, and will not be repeated here.
[0049] An improved bilinear interpolation algorithm is provided in the present embodiment, which is as follows:
[0050] The bilinear interpolation algorithm is adopted, the interpolation coefficient and corresponding pixel point coordinate are calculated according to the reduction multiple, the interpolation calculation is performed on the image, and finally the reduced image is output. The bilinear interpolation algorithm is actually the most common linear interpolation, because the linear interpolation is decomposed into horizontal and vertical directions, so it is called bilinear interpolation. It calculates the gray value of the interpolation pixel point through the gray values of the four related pixel points around the pixel point to be interpolated by two-dimensional linear weighted average. The original four pixel points are a1, a2, a3, and a4, the point distance in the horizontal and vertical directions is 1 unit length, the coordinate positions are a1(x, y), a2(x+1, y), a3(x, y+1), and a4(x+1, y+1), the coordinate of the pixel point to be interpolated is P(x+dx, y+dy), and the gray value of the pixel point P to be interpolated calculated by the bilinear interpolation method of the embodiment is:
[0051] P(x+dx, y+dy) = (1-dx)(1-dy)a1+dx(1-dy)a2+(1-dx)dy a3+dxdya=a1+dx(a2-a1)+dy(a3-a1)+dxdy(a1-a2-a3+a4);
[0052] After the calculation formula is rewritten, the pixel point to be interpolated can be calculated by only four multiplications and simple addition and subtraction.
[0053] In the above embodiment, image edge enhancement can also be performed, the image edge position is calculated according to the information of adjacent points of the image, and the image edge information is enhanced and compensated. For example, when the numerical values of adjacent points differ by more than a threshold value, such as 45, it is considered that the image edge position is found, according to the reduction multiple, the threshold value can be adjusted in real time, for example, when the image is reduced by 1 / 2, the threshold value is set to 90; when the image is reduced by 1 / 2, the threshold value is set to 45; when the image is reduced by 1 / 3, the threshold value is set to 30, and so on. When the image edge position is found, the pixel point at the edge position is enlarged according to the reduction multiple, for example, when the image is reduced by 1 / 2, the pixel point is multiplied by 2 to enlarge, so that the image edge information can be enhanced again.
[0054] In the embodiment, an electronic device is provided, including a memory and a processor, the memory stores a computer program, and the processor is configured to run the computer program to execute the method in the above embodiment.
[0055] The above-described processes can be implemented on a processor, or can be stored in a memory (or referred to as a computer readable medium), which includes permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology to store information. The information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible by a computing device. According to the definition herein, computer readable medium does not include transitory media such as modulated data signals and carriers.
[0056] These computer programs can also be loaded into a computer or other programmable data processing device, so that a series of operation steps are performed on the computer or other programmable device to generate a computer implemented process, so that the instructions executed on the computer or other programmable device provide a process for implementing the flow Figure 1 The flow or multiple flows and / or the functions of the blocks Figure 1 The steps of the functions specified in one or more flows or one or more blocks can be implemented by different modules.
[0057] In this embodiment, such a device or system is provided. The device is called an image reduction processing device, which includes: an acquisition module for acquiring image information of an input image and a reduction multiple, the input image information including image width and image height; a division module for dividing the image into a plurality of image blocks with equal area size according to the image information of the input image; a uniform module for uniforming the values of all pixel points in each image block into a pixel point value to obtain a uniformed image; a obtaining module for obtaining a multiple of the bilinear interpolation reduction according to the size of the image block and the reduction multiple; a bilinear module for performing bilinear interpolation reduction processing on the uniformed image according to the multiple of the bilinear interpolation reduction to obtain a target image.
[0058] The system or device is used to realize the functions of the methods in the above embodiments. Each module in the system or device corresponds to each step in the method, which has been described in the method and will not be repeated here.
[0059] For example, the unifying module is configured to average the pixel values in each image block and take the average as the value of a corresponding pixel point of the unified image block.
[0060] For another example, the dividing module is configured to divide the image into a plurality of image blocks with a size of (2^M)*(2^M), where 2^M≤N<2^(M+1), M is an integer, and N is the reduction factor of the input image.
[0061] For another example, the bilinear module is configured to reduce the image that has been reduced by 2^M times by N / 2^M times based on 2*2 bilinear difference to obtain the target image.
[0062] The embodiment solves the problem of large occupation of computing resources in the prior art bilinear interpolation, thereby reducing the occupation of computing resources and improving the image reduction speed.
[0063] The above merely illustrates the embodiments of the present application and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the present application shall be included in the scope of the claims of the present application.
Claims
1. An image reduction processing method, characterized in that, include: Obtain the image information of the input image and the scaling factor N, wherein the input image information includes the image width and the image height; The image is divided into multiple image blocks of equal size based on the image information of the input image; wherein the image is divided into multiple image blocks of size (2^M)*(2^M), where 2^M≤N<2^(M+1), M is an integer, and N is the scaling factor of the input image; The values of all pixels in each image block are unified into a single pixel value to obtain a unified image. Specifically, for each image block, all pixel values in that block are obtained, and a threshold is calculated. The proportion of pixel values less than or equal to the threshold is less than or equal to 20% of the total pixels in the image, while the proportion of pixel values greater than or equal to the threshold is greater than or equal to 80%. The average value of all pixel values greater than or equal to the threshold in that image block is then taken as the unified pixel value for that image block. The reduction factor for bilinear interpolation is obtained based on the size of the image patch and the reduction factor. The unified image is reduced by bilinear interpolation according to the reduction factor to obtain the target image; wherein, based on the 2*2 bilinear difference, the image that has already been reduced by 2^M times is further reduced by N / (2^M) times to obtain the target image; Specifically, the process involves obtaining the currently available computing resources of a computing node, searching through pre-saved records for various image scaling scenarios that the computing resources can handle, where each scaling scenario includes the original image size and the scaling factor; if the original image size in a scaling scenario is between the size of the image to be scaled down and (size of the image to be scaled down / N), then the scaling factor corresponding to the original image size in that scaling scenario is obtained, and the value of M is obtained based on the scaling factor.
2. The method according to claim 1, characterized in that, Unifying the values of all pixels in each image block to a single pixel value includes: Take the average value of the pixel values in each image block, and use this average value as the value of a single pixel corresponding to that image block after unification.
3. A storage medium, characterized in that, Used to store a program for performing the method according to any one of claims 1 to 2.
4. A processor, characterized in that, Used to run a program, said program for performing the method of any one of claims 1 to 2.
Citation Information
Patent Citations
Image reduction method and device
CN106780336A
Image stepless scaling method, computer device and computer readable storage medium
CN108537729A