Image zooming method and device, electronic equipment and computer readable storage medium
By determining the target row number and column number of the output image, the coordinate points in the input image are quickly located, which solves the problem of low image scaling calculation efficiency and achieves more efficient image scaling processing.
Patent Information
- Application Number
- CN202410775279.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-06-14
AI Technical Summary
In machine vision applications, the calculation time of image scaling operators is long, resulting in low efficiency of the image scaling process. How to improve the efficiency of image scaling calculations is a problem that needs to be solved.
By obtaining the scaling coefficient, determine the target row number and column number in the input image corresponding to each data row and column of the output image. Based on these target row numbers and column numbers, quickly determine the corresponding coordinate point of each coordinate point in the output image. Input the target coordinate point in the image and calculate the pixel value of each coordinate point in the output image. Rows and columns are used as the calculation granularity to reduce the number of calculations and thereby improve performance.
Reducing the number of scaling calculations from H*W to H+W improves the processing efficiency of image scaling, reduces calculation time, and improves processing performance.
Smart Images

Figure CN118657658A
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to an image scaling method, apparatus, electronic device, and computer-readable storage medium. Background Art
[0002] In the field of artificial intelligence and machine vision applications, the resize operator is frequently used to implement image scaling. The resize operator can adjust the size of the input image data to achieve image scaling. Summary of the invention
[0003] At least one embodiment of the present disclosure provides an image scaling method, comprising: obtaining a scaling factor; determining, based on the scaling factor, a target row number in an input image corresponding to each data row of an output image, and determining a target column number in the input image corresponding to each data column of the output image, so as to obtain a plurality of target row numbers corresponding to a plurality of data rows of the output image and a plurality of target column numbers corresponding to a plurality of data columns of the output image; determining, based on the plurality of target row numbers and the plurality of target column numbers, a target coordinate point in the input image corresponding to each coordinate point of the output image; and determining, based on the target coordinate point corresponding to each coordinate point of the output image, a pixel value of each coordinate point of the output image, so as to obtain pixel data of the output image.
[0004] For example, in the image scaling method provided by at least one example of the above-mentioned embodiments of the present disclosure, the calculation process of determining the multiple target row numbers and the multiple target column numbers based on the scaling factor is performed by a first processor; the calculation process of determining the pixel value of each coordinate point of the output image is performed by a second processor; the first processor supports the calculation of double-precision floating-point numbers, and the second processor supports the calculation of at least one type of data other than double-precision floating-point numbers.
[0005] For example, in the image scaling method provided by at least one example of the above-mentioned embodiments of the present disclosure, the target coordinate point in the input image corresponding to each coordinate point of the output image is determined based on the multiple target row numbers and the multiple target column numbers, including: the first processor converts the multiple target row numbers and the multiple target column numbers into integers to obtain the converted multiple target row numbers and the converted multiple target column numbers; the first processor copies the converted multiple target row numbers and the converted multiple target column numbers to the second processor; the second processor determines the target coordinate point in the input image corresponding to each coordinate point of the output image based on the converted multiple target row numbers and the converted multiple target column numbers.
[0006] For example, in the image scaling method provided by at least one example of the above embodiments of the present disclosure, the first processor is a central processing unit, and the second processor is a graphics processor.
[0007] For example, in the image scaling method provided by at least one example of the above-mentioned embodiments of the present disclosure, the scaling factor includes a row-direction scaling ratio and a column-direction scaling ratio; based on the scaling factor, determining the target row number in the input image corresponding to each data row of the output image includes: determining the target row number in the input image corresponding to each data row of the output image based on the column-direction scaling ratio. Based on the scaling factor, determining the target column number in the input image corresponding to each data column of the output image includes: determining the target column number in the input image corresponding to each data column of the output image based on the row-direction scaling ratio.
[0008] For example, in the image scaling method provided by at least one example of the above embodiments of the present disclosure, the output image includes a first coordinate point, and the first coordinate point corresponds to a first target coordinate point in the input image. Based on the target coordinate point corresponding to each coordinate point of the output image, determining the pixel value of each coordinate point of the output image includes: determining the pixel values of four reference points in the input image corresponding to the first target coordinate point; and determining the pixel value of the first coordinate point based on the pixel values of the four reference points.
[0009] For example, in the image scaling method provided by at least one example of the above-mentioned embodiments of the present disclosure, the target coordinate point in the input image corresponding to each coordinate point of the output image is determined based on the multiple target row numbers and the multiple target column numbers, including: for each coordinate point of the output image, the target row number corresponding to the row where the coordinate point is located and the target column number corresponding to the column where the coordinate point is located are used to determine the target coordinate point.
[0010] At least one embodiment of the present disclosure provides an image scaling device, including an acquisition unit, a first determination unit, a second determination unit and a third determination unit, wherein the acquisition unit is configured to acquire a scaling factor; the first determination unit is configured to determine, based on the scaling factor, a target row number in an input image corresponding to each data row of an output image, and to determine a target column number in the input image corresponding to each data column of the output image, so as to obtain a plurality of target row numbers corresponding to a plurality of data rows of the output image and a plurality of target column numbers corresponding to a plurality of data columns of the output image; the second determination unit is configured to determine, based on the plurality of target row numbers and the plurality of target column numbers, a target coordinate point in the input image corresponding to each coordinate point of the output image; and the third determination unit is configured to determine, based on the target coordinate point corresponding to each coordinate point of the output image, a pixel value of each coordinate point of the output image, so as to obtain pixel data of the output image.
[0011] At least one embodiment of the present disclosure provides an electronic device, comprising a processor; a memory storing one or more computer program modules; wherein the one or more computer program modules are configured to be executed by the processor to implement the image scaling method provided by any embodiment of the present disclosure.
[0012] At least one embodiment of the present disclosure provides a computer-readable storage medium storing non-transitory computer-readable instructions. When the non-transitory computer-readable instructions are executed by a computer, the image scaling method provided by any embodiment of the present disclosure can be implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly introduced below. Obviously, the drawings in the following description only relate to some embodiments of the present disclosure, but are not intended to limit the present disclosure.
[0014] Figure 1 A schematic diagram of image scaling is shown;
[0015] Figure 2 A flowchart of an image scaling method provided by at least one embodiment of the present disclosure is shown;
[0016] Figure 3 A schematic diagram showing a processing process provided by at least one embodiment of the present disclosure;
[0017] Figure 4 A schematic diagram of calculating a pixel value provided by at least one embodiment of the present disclosure is shown;
[0018] Figure 5 A schematic diagram showing another processing process provided by at least one embodiment of the present disclosure;
[0019] Figure 6 A schematic diagram showing another input image provided by at least one embodiment of the present disclosure is shown;
[0020] Figure 7 A schematic block diagram of an image scaling device provided by at least one embodiment of the present disclosure is shown;
[0021] Fig. 8A A schematic block diagram of an electronic device provided by at least one embodiment of the present disclosure is shown;
[0022] Figure 8B A schematic block diagram showing another electronic device provided by at least one embodiment of the present disclosure; and
[0023] Fig. 9A schematic diagram of a computer-readable storage medium provided by at least one embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings of the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0025] Unless otherwise defined, the technical terms or scientific terms used in the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, similar words such as "one", "one" or "the" do not indicate quantity restrictions, but indicate that there is at least one. Similar words such as "include" or "comprise" mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Similar words such as "connect" or "connected" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0026] When performing scaling calculations, the resize operator can be used to resize the coordinates of each point in the output image (the scaled image). x ,out y ) calculates the coordinates (in x , in y ), will (in x , in y ) position is output to the coordinate (out x ,out y ) point.
[0027] Figure 1 A schematic diagram of image scaling is shown.
[0028] like Figure 1As shown, the output image 120 is reduced by k times relative to the input image 110 (k is a value greater than 1), and for each point in the output image 120, the corresponding target coordinates in the input image 110 are calculated according to the scaling factor, the target coordinates are rounded to determine the target point group, and then the pixel values of the corresponding points in the output image 120 are determined according to the pixel values of the target point group in the input image, so as to achieve the mapping from the input image to the output image. For example, for point Q00 in the output image 120, the target coordinates in the input image corresponding to point Q00 are calculated to be point P11; for point Q01 in the output image 120, the target coordinates in the input image corresponding to point Q01 are calculated to be point P14.
[0029] In the above method, it is necessary to perform a calculation for each point of the output image until each point of the output image is traversed, which makes the scaling process take a long time. Since scaling operators are frequently used in machine vision applications, the long calculation time of the scaling operator will cause the entire processing process to be prolonged and the processing efficiency to be low. Therefore, how to improve the efficiency of image scaling calculation is a problem that needs to be solved.
[0030] At least one embodiment of the present disclosure provides an image scaling method, an image scaling device, an electronic device, and a computer-readable storage medium. The image scaling method includes: obtaining a scaling factor; based on the scaling factor, determining a target row number in an input image corresponding to each data row of the output image, and determining a target column number in the input image corresponding to each data column of the output image, so as to obtain a plurality of target row numbers corresponding to a plurality of data rows of the output image and a plurality of target column numbers corresponding to a plurality of data columns of the output image; based on the plurality of target row numbers and the plurality of target column numbers, determining a target coordinate point in the input image corresponding to each coordinate point of the output image; based on the target coordinate point corresponding to each coordinate point of the output image, determining a pixel value of each coordinate point of the output image, so as to obtain pixel data of the output image.
[0031] In the image scaling method, rows and columns are used as calculation granularity to calculate the target row number of the input image corresponding to each row of the output image and the target column number of the input image corresponding to each column of the output image during the image scaling process. Based on this, it is possible to quickly determine which coordinate point in the output image each coordinate point in the output image corresponds to, thereby reducing the number of calculations. Compared with a solution that performs one coordinate calculation for each coordinate point in the output image, the image scaling method of the embodiment of the present disclosure reduces the number of scaling calculations from H*W to H+W, thereby improving performance, wherein H is the number of rows of the output image and W is the number of columns of the output image.
[0032] Figure 2 A flowchart of an image scaling method provided by at least one embodiment of the present disclosure is shown.
[0033] like Figure 2 As shown, the method may include steps S210 to S240.
[0034] Step S210: Obtain a scaling factor.
[0035] Step S220: Based on the scaling factor, determine the target row number in the input image corresponding to each data row of the output image, and determine the target column number in the input image corresponding to each data column of the output image, so as to obtain multiple target row numbers corresponding to multiple data rows of the output image and multiple target column numbers corresponding to multiple data columns of the output image.
[0036] Step S230: Based on the multiple target row numbers and the multiple target column numbers, determine the target coordinate point in the input image corresponding to each coordinate point in the output image.
[0037] Step S240: determining the pixel value of each coordinate point of the output image based on the target coordinate point corresponding to each coordinate point of the output image to obtain pixel data of the output image.
[0038] For example, the input image can be represented by a matrix, and the output image can also be represented by a matrix.
[0039] For example, the scaling factor may be a scaling ratio, which may be determined based on the size of the output image and the size of the input image. The scaling factor may be pre-calculated and stored in a memory, and in step S110, the scaling factor is read from the memory.
[0040] For example, the multiple data points of the input image corresponding to the multiple data points of each row of the output image may be located in the same data row, and similarly, the multiple data points of the input image corresponding to the multiple data points of each column in the output image may be located in the same data column. Therefore, in step S220, for each data row of the output image, the target row number of the corresponding input image may be determined to indicate which data row in the input image each data row in the output image corresponds to, and for each data column of the output image, the target column number of the corresponding input image may be determined to indicate which data column in the input image each data column in the output image corresponds to. Since the scaling factor may be an integer or a non-integer, the target row number and the target column number may each be an integer or a non-integer. In addition, in other embodiments, the target row number and the target column number may also be represented by other characters, as long as they can characterize the position of the target row in the input image. For ease of description, in the following embodiments, "data row" may also be referred to as "row", "data column" may also be referred to as "column", and "data point" may also be referred to as "point".
[0041] For example, the scaling factor includes a row-wise scaling ratio and a column-wise scaling ratio. For example, the row-wise scaling ratio may be based on the row-wise size width of the input image. src (e.g. number of columns) and the row-wise size width of the output image dst Determine, for example, it can be the quotient of the two For example, the column-wise scaling ratio can be based on the column-wise size height of the input image. src (e.g. number of rows) and the row-wise size of the output image height dst Determine, for example, it can be the quotient of the two
[0042] For example, step S220 may further include: determining the target row number in the input image corresponding to each data row of the output image based on the column-wise scaling ratio; and determining the target column number in the input image corresponding to each data column of the output image based on the row-wise scaling ratio.
[0043] For example, the following formula (1) can be used to calculate the target column number in the input image corresponding to each column in the output image, out x Indicates the column number of a column in the output image, in x Indicates out x The target column number in the corresponding input image, the coordinates in the input image can be expressed by double-precision floating point numbers, and the target column number can be expressed as U+u, where U represents the integer part and u represents the decimal part. The following formula (2) can be used to calculate the target row number in the input image corresponding to each row in the output image, out y Indicates the row number of a row in the output image, in y Indicates out y The target row number in the corresponding input image, the target row number can be expressed as V+v, for example, wherein V represents the integer part and v represents the decimal part.
[0044]
[0045]
[0046] Figure 3 A schematic diagram of a processing process provided by at least one embodiment of the present disclosure is shown.
[0047] like Figure 3As shown, according to step S220, multiple data rows of the output image are obtained, which correspond to multiple target row numbers [y0, y1, y2, ..., ym] of the input image 310, where m is the total number of rows of the output image, and multiple data columns of the output image are obtained, which correspond to multiple target column numbers [x0, x1, x2, ..., xn] of the input image 310, where n is the total number of columns of the output image.
[0048] For example, in step S230, based on multiple target row numbers [y0, y1, y2, ..., ym] and multiple target column numbers [x0, x1, x2, ..., xn], the target coordinate point in the input image corresponding to each coordinate point in the output image is obtained.
[0049] For example, step S230 may further include: for each coordinate point of the output image, determine the corresponding target coordinate point by using the target row number corresponding to the row where the coordinate point is located and the target column number corresponding to the column where the coordinate point is located. For example, the output image includes a first coordinate point, the target row number of the input image corresponding to the row where the first coordinate point is located is y0, and the target column number of the input image corresponding to the column where the first coordinate point is located is x0, then the target coordinate point of the input image corresponding to the first coordinate point is (x0, y0). For another example, the output image includes a second coordinate point, the target row number of the input image corresponding to the row where the second coordinate point is located is y1, and the target column number of the input image corresponding to the column where the second coordinate point is located is x2, then the target coordinate point of the input image corresponding to the second coordinate point is (x2, y1). In this way, the target coordinates of the input image corresponding to each point in the output image can be obtained, and then the coordinate matrix 320 corresponding to the output image can be obtained.
[0050] For example, in step S240, in some embodiments, the pixel value of the target coordinate point in the input image can be obtained, and the pixel value of the target coordinate point in the input image can be used as the pixel value of the corresponding coordinate point of the output image, so that the pixel value corresponding to each point in the output image can be obtained, forming a pixel value matrix 330, and the pixel value matrix 330 can be used as the pixel data of the output image. For example, using the above example, the pixel value V00 of the target coordinate point (x0, y0) in the input image can be used as the pixel value of the first coordinate point in the output image, and the pixel value of the target coordinate point (x2, y1) in the input image can be used as the pixel value of the second coordinate point in the output image. Based on this, the pixel value of each coordinate point in the output image 330 can be obtained, and then the pixel data of the output image is obtained.
[0051] For example, taking the first coordinate point in the output image as an example, the first coordinate point corresponds to the first target coordinate point in the input image. In step S240, the pixel values of the four reference points corresponding to the first target coordinate point in the input image can be determined; based on the pixel values of the four reference points, the pixel value of the first coordinate point is determined.
[0052] For example, when the pixel value of the first target coordinate point is used as the pixel value of the first coordinate point, the coordinates of the first target coordinate point may not be an integer, and the input image may only record the pixel values of data points whose coordinates are integers (hereinafter also referred to as integer points). When the coordinates of the first target coordinate point are non-integer, the pixel value of the first target coordinate point can be calculated by interpolation calculation.
[0053] Figure 4 A schematic diagram of calculating pixel values provided by at least one embodiment of the present disclosure is shown.
[0054] like Figure 4 As shown, the horizontal position (i.e., X-axis coordinate) of the first target coordinate point P is U+u, and the vertical position (i.e., Y-axis coordinate) of the first target coordinate point P is V+v. The four intersections A, B, C, and D of the four lines X=U, X=U+1 and the horizontal lines Y=V and Y=V+1 are used as the four reference points of the first target coordinate point P. The pixel value of point P is obtained by performing three linear interpolations on the four points A, B, C, and D. That is, linear interpolation is performed on A, C and B, D along the Y-axis direction to obtain R1 and R2, and then linear interpolation is performed on R1 and R2 along the X-axis direction. The calculation formula is as follows (3):
[0055] f(P)=f(R1)*(1-u)+f(R2)*u
[0056] =(f(C)*(1-v)+f(A)*v)*(1-u)+(f(D)*(1-v)+f(B)*v)*u (3)
[0058] Among them, U = floor(U + u), V = floor(V + v), floor is a floor rounding function. U and V are obtained by rounding U + u and V + v respectively, and the four reference points A / B / C / D are determined according to the integers U and V. The decimal parts u and v are the offsets of point P relative to the four reference points, which serve as the weights of formula (3). The pixel value of point P can be calculated based on the pixel values of the four reference points and the weights u and v.
[0059] For example, in some other embodiments, in step S240, the pixel value of the integer point adjacent to the first target coordinate point may be used as the pixel value of the first coordinate point. Figure 4As shown, the pixel value of the integer point C adjacent to the first target coordinate point P is used as the pixel value of the first coordinate point corresponding to point P in the output image.
[0060] For example, image scaling may include image reduction and image enlargement. In the case of image reduction, each point in the output image corresponds to a point in the input image. In the case of image enlargement, multiple points in the output image may correspond to the same point in the input image, that is, multiple points in the output image are mapped to one point in the input image.
[0061] According to the image scaling method of the embodiment of the present disclosure, during the image scaling process, rows and columns are used as the calculation granularity to calculate the target row number of the input image corresponding to each row of the output image and the target column number of the input image corresponding to each column of the output image, based on which each coordinate point in the output image corresponds to which coordinate point in the output image, thereby reducing the number of calculations. Compared with the solution of performing one coordinate calculation for each coordinate point in the output image, the image scaling method of the embodiment of the present disclosure reduces the number of scaling calculations from H*W to H+W, thereby improving performance, where H is the number of rows of the output image and W is the number of columns of the output image.
[0062] For example, since the scaling multiple may not be an integer multiple, the scaling factor may have multiple decimal places (e.g., more than 6 decimal places). For the operation of calculating the target row number and the target column number based on the scaling factor, if a processor capable of processing double-precision floating point numbers (double) is used to perform this operation, higher precision can be achieved, thereby obtaining a more accurate result. However, some processors for performing image scaling processing (e.g., some graphics processors) cannot process double-precision floating point numbers and can only process data with lower precision, such as single-precision floating point numbers (float) or integers, resulting in reduced calculation accuracy. In order to solve this problem, the present disclosure provides the following embodiments.
[0063] For example, the image scaling method of the embodiment of the present disclosure can be jointly executed by a first processor and a second processor, the first processor supports double-precision floating point calculation, and the second processor supports the calculation of at least one data other than double-precision floating point numbers, for example, the second processor can support the calculation of single-precision floating point numbers (float) or integers. In addition, the first processor can also support the calculation of other types of data other than double-precision floating point numbers, such as single-precision floating point numbers or integers. For example, the first processor can be a central processing unit, and the second processor can be a graphics processor, but the present disclosure is not limited to this, and the first processor and the second processor can also be other types of processors.
[0064] For example, a double-precision floating point number (double) is a data type used by computers. It uses 64 bits (8 bytes) to store a floating point number and can be accurate to 12 decimal places. The first processor can process double-precision floating point numbers, that is, it can perform double-precision floating point operations. The second processor can process single-precision floating point numbers (float), integers and other types of data, but cannot process double-precision floating point numbers. Single-precision floating point numbers use 32 bits (4 bytes) to store a floating point number and can be accurate to 6 decimal places.
[0065] For example, the calculation process of determining multiple target row numbers and multiple target column numbers based on the scaling factor (such as step S220) can be executed by the first processor; the calculation process of determining the pixel value of each coordinate point of the output image (such as step S240) can be executed by the second processor.
[0066] For example, the calculation process of the target row number and the target column number in step S220 may involve data with multiple decimal places (for example, the number of digits after the decimal point is greater than or equal to 12 digits). In this case, accurate calculation can be achieved by using the first processor to perform the above step S220. The first processor can copy the calculation result to the second processor so that the second processor can perform subsequent processing. For example, the first processor can put the calculation result into a memory, and the second processor reads the calculation result from the memory.
[0067] For example, step S230 may include: the first processor converts multiple target row numbers and multiple target column numbers into integers to obtain multiple converted target row numbers and multiple converted target column numbers; the first processor copies the multiple converted target row numbers and the multiple converted target column numbers to the second processor; the second processor determines the target coordinate point in the input image corresponding to each coordinate point of the output image based on the multiple converted target row numbers and the multiple converted target column numbers.
[0068] Figure 5 A schematic diagram of another processing process provided by at least one embodiment of the present disclosure is shown.
[0069] like Figure 5As shown, after obtaining multiple target row numbers [y0, y1, y2, ..., ym] and multiple target column numbers [x0, x1, x2, ..., xn] according to step S220, if each target row number and each target column number is a double-precision floating point number, before copying the data to the second processor, the double-precision floating point number can be rounded down using a floor function (such as the floor function) to convert the double-precision floating point number into an integer, for example, the double-precision floating point numbers U+u and V+v are converted into U and V respectively. The converted multiple target row numbers and the converted multiple target column numbers are all integers, the converted multiple target row numbers are represented by the first vector [y0', y1', y2', ..., ym'], and the converted multiple target column numbers are represented by the second vector [x0', x1', x2', ..., xn']. Then the converted data is copied to the second processor, and the second processor traverses each point of the output image, and takes the corresponding values in the first vector and the second vector according to the row number and column number of the current point to form the coordinates, thereby obtaining the coordinate matrix 520 corresponding to the output image, and the coordinates in the coordinate matrix 520 are all integers. Then, the pixel value corresponding to each point of the output image is further calculated, so as to obtain the pixel value matrix 530 corresponding to the output image.
[0070] For example, after the second processor obtains the integer target row number and target column number transmitted by the first processor, the second processor can determine the first target coordinate point of the input image corresponding to the first coordinate point in the output image based on the target row number and the target column number, and determine the coordinates of the first target coordinate point to be integers U and V. In step S240, Figure 4 As shown, four reference points A / B / C / D can be determined based on integers U and V. For example, due to the different precisions of double data and float data, there are some errors between the integers (U and V) determined based on double data and the integers (U and V) determined based on float data, and the error may be magnified to the integer 1. For example, U+u determined based on double data is 2.0356…, and the integer U obtained by rounding down is 2; U+u determined based on float data is 1.8492…, and the integer U obtained by rounding down is 1. Therefore, compared with double data, the integer determined based on float data has a larger error, that is, the integer determined based on double data is more accurate. The first processor copies the integer determined based on the double data to the second processor, and the four reference points A / B / C / D determined by the second processor based on the integer are also more accurate, thereby making the calculated pixel value of the first coordinate point more accurate.
[0071] For example, in the process of calculating the pixel value of the first coordinate point based on the four reference points A / B / C / D, the decimal parts u and v are required. To meet this requirement, the second processor can execute the calculation of formulas (1) and (2) based on float data to obtain the decimal parts u and v, and use the pixel values of the four reference points A / B / C / D and the decimal parts u and v to perform the interpolation calculation of formula (3).
[0072] For example, in some other embodiments, after the first processor calculates and obtains a plurality of target row numbers and a plurality of target column numbers, the double-precision floating point number can be converted into a single-precision floating point number (float) to obtain a plurality of target row numbers and a plurality of target column numbers after conversion, and the plurality of target row numbers and the plurality of target column numbers after conversion are both single-precision floating point numbers. The converted single-precision floating point number is copied to the second processor, and the second processor can determine the first target coordinate point of the input image corresponding to the first coordinate point of the output image, and the first target coordinate point determined is a single-precision floating point number, and the single-precision floating point number is rounded down to obtain U and V, and the four reference points A / B / C / D corresponding to the first target coordinate point are determined based on the integers U and V, and the pixel value of the first coordinate point in the output image is calculated using the decimal parts u and v of the single-precision floating point number and the pixel values of the four reference points. For example, compared with the method of converting a double-precision floating point number into a single-precision floating point number and then converting the single-precision floating point number into an integer, the integer determined by directly converting the double-precision floating point number into an integer is more accurate.
[0073] For example, in some other embodiments, after the first processor calculates and obtains the double-precision data, it rounds the double-precision data to obtain an integer, and copies the integer and the first several decimal places of the double-precision floating point number (for example, the first 6 decimal places) to the second processor. The second processor determines four reference points based on the integer, and performs the calculation of formula (3) based on the pixel values of the four reference points and the copied decimal part to obtain the pixel value of the first data point.
[0074] For example, in some other embodiments, if the second processor (such as a graphics processor) supports calculation of double-precision floating-point numbers, the above steps S210 to S240 can all be executed by the graphics processor. In this embodiment, the target row number and the target column number obtained in step S220 are both double data, and in step S230, the coordinates of the first target coordinate point determined are double data, the first target coordinate point is rounded down to obtain integers U and V, four reference points A / B / C / D are determined based on the integers U and V, and the pixel value of the first coordinate point in the output image is calculated based on the pixel values of the four reference points and the decimal parts u and v of the double data.
[0075] Figure 6 A schematic diagram of another input image provided by at least one embodiment of the present disclosure is shown.
[0076] like Figure 6 As shown, the input image may include multiple data channels, for example, data channels 601, 602 and 603, each data channel includes a data matrix, each data matrix includes multiple rows and multiple columns, and therefore, the input image includes channel dimensions, row dimensions and column dimensions. Similarly, the output image may also include channel dimensions, row dimensions and column dimensions, and the number of channels of the output image may be the same as the number of channels of the input image. In some embodiments of the present disclosure, steps S210 to S240 may be performed for each channel.
[0077] For example, the image scaling method of the embodiment of the present disclosure is used as a resize operator in neural network calculations. That is to say, the image scaling method of the embodiment of the present disclosure can be implemented as a resize operator. During the neural network calculation process, the resize operator can be called at each node that needs to perform image scaling to perform image scaling processing using steps S210 to S240. Based on this approach, computing efficiency can be greatly improved and processing performance can be improved.
[0078] For example, the Resize operator can have three modes, BILINEAR (bilinear assignment method) / CUBIC (cubic convolution interpolation method) / NEAREST (nearest neighbor assignment method), and the coordinate mapping method of each mode is different. Taking BILINEAR as an example, if the coordinate scaling calculation is performed on the output image point by point, there will be repeated calculations in the same row and column, and the coordinate calculation will occupy more registers. The embodiment of the present disclosure improves the resize operator. Taking the BILINEAR mode as an example, the row number and column number are scaled and calculated, and the calculation results are accessed row by row and column by column to obtain the corresponding coordinates. The number of scaling calculations is reduced from H*W to H+W, which improves processing efficiency.
[0079] The image scaling method of at least one embodiment of the present disclosure proposes moving the resize coordinate scaling calculation to the central processing unit for execution, which can obtain calculation results of data types not supported by the graphics processor, improve accuracy, reduce the use of registers of the graphics processor, and improve performance.
[0080] Figure 7 A schematic block diagram of an image scaling device 700 provided by at least one embodiment of the present disclosure is shown.
[0081] For example, Figure 7As shown, the image scaling device 700 includes an acquisition unit 710, a first determination unit 720, a second determination unit 730, and a third determination unit 740. These components are interconnected via a bus system and / or other forms of connection mechanisms (not shown). For example, these modules can be implemented by hardware (e.g., circuit) modules, software modules, or any combination of the two. The following embodiments are the same and will not be repeated here. For example, these units can be implemented by a central processing unit (CPU), a graphics processing unit (GPU), a tensor processing unit (TPU), a field programmable gate array (FPGA), or other forms of processing units with data processing capabilities and / or instruction execution capabilities, as well as corresponding computer instructions. It should be noted that Figure 7 The components and structure of the image scaling device 700 shown are merely exemplary and non-limiting. The image scaling device 700 may also have other components and structures as required.
[0082] The acquisition unit 710 is configured to acquire the scaling factor. The acquisition unit 710 may, for example, execute Figure 2 Described step S210.
[0083] The first determination unit 720 is configured to determine, based on the scaling factor, a target row number in the input image corresponding to each data row of the output image, and a target column number in the input image corresponding to each data column of the output image, so as to obtain a plurality of target row numbers corresponding to a plurality of data rows of the output image and a plurality of target column numbers corresponding to a plurality of data columns of the output image. The first determination unit 720 may, for example, execute Figure 2 Described step S220.
[0084] The second determining unit 730 is configured to determine the target coordinate point in the input image corresponding to each coordinate point of the output image based on the multiple target row numbers and the multiple target column numbers. The second determining unit 730 may, for example, perform Figure 2 Described step S230.
[0085] The third determination unit 740 is configured to determine the pixel value of each coordinate point of the output image based on the target coordinate point corresponding to each coordinate point of the output image to obtain pixel data of the output image. The third determination unit 740 may, for example, perform Figure 2 Described step S240.
[0086] For example, the acquisition unit 710, the first determination unit 720, the second determination unit 730, and the third determination unit 740 may be hardware, software, firmware, or any feasible combination thereof. For example, the acquisition unit 710, the first determination unit 720, the second determination unit 730, and the third determination unit 740 may be a dedicated or general circuit, chip, or device, or may be a combination of a processor and a memory. The embodiments of the present disclosure do not limit the specific implementation forms of the above-mentioned units.
[0087] For example, the acquisition unit 710, the first determination unit 720, the second determination unit 730, and the third determination unit 740 may include codes and programs stored in a memory; the processor may execute the codes and programs to implement some or all functions of the acquisition unit 710, the first determination unit 720, the second determination unit 730, and the third determination unit 740 as described above. For example, the acquisition unit 710, the first determination unit 720, the second determination unit 730, and the third determination unit 740 may be dedicated hardware devices to implement some or all functions of the acquisition unit 710, the first determination unit 720, the second determination unit 730, and the third determination unit 740 as described above. For example, the acquisition unit 710, the first determination unit 720, the second determination unit 730, and the third determination unit 740 may be a circuit board or a combination of multiple circuit boards to implement the functions described above. In the embodiment of the present disclosure, the circuit board or the combination of multiple circuit boards may include: (1) one or more processors; (2) one or more non-transitory memories connected to the processor; and (3) firmware stored in the memory that can be executed by the processor.
[0088] It should be noted that in the embodiment of the present disclosure, each unit of the image scaling device 700 corresponds to each step of the aforementioned image scaling method. For the specific functions of the image scaling device 700, reference may be made to the relevant description of the image scaling method, which will not be repeated here. Figure 7 The components and structures of the image zoom device 700 shown are only exemplary and non-restrictive. The image zoom device 700 may also include other components and structures as needed. The image zoom device 700 may include more or fewer circuits or units, and the connection relationship between the various circuits or units is not limited and can be determined according to actual needs. The specific configuration of each circuit or unit is not limited and can be composed of analog devices according to circuit principles, or can be composed of digital chips, or can be composed in other applicable ways.
[0089] For example, in the image scaling device provided by at least one example of the above embodiments of the present disclosure, the first determination unit can be used for the first processor, that is, the first processor includes the first determination unit; the third determination unit can be used for the second processor, that is, the second processor includes the third determination unit; the first processor supports the calculation of double-precision floating-point numbers, and the second processor supports the calculation of at least one type of data other than double-precision floating-point numbers.
[0090] For example, in the image scaling device provided by at least one example of the above-mentioned embodiments of the present disclosure, the first processor converts the multiple target row numbers and the multiple target column numbers into integers to obtain the converted multiple target row numbers and the converted multiple target column numbers; the first processor copies the converted multiple target row numbers and the converted multiple target column numbers to the second processor; the second processor determines the target coordinate point in the input image corresponding to each coordinate point of the output image based on the converted multiple target row numbers and the converted multiple target column numbers.
[0091] For example, in the image scaling device provided by at least one example of the above embodiments of the present disclosure, the first processor is a central processing unit, and the second processor is a graphics processor.
[0092] For example, in the image scaling device provided by at least one example of the above embodiments of the present disclosure, the scaling factor includes a row direction scaling ratio and a column direction scaling ratio; the first determination unit is further configured to: determine the target row number in the input image corresponding to each data row of the output image based on the column direction scaling ratio; determine the target column number in the input image corresponding to each data column of the output image based on the row direction scaling ratio.
[0093] For example, in the image scaling device provided by at least one example of the above embodiments of the present disclosure, the output image includes a first coordinate point, and the first coordinate point corresponds to a first target coordinate point in the input image. The fourth processing unit is further configured to: determine the pixel values of four reference points in the input image corresponding to the first target coordinate point; and determine the pixel value of the first coordinate point based on the pixel values of the four reference points.
[0094] For example, in the image scaling device provided by at least one example of the above embodiments of the present disclosure, the second processing unit is further configured to: for each coordinate point of the output image, determine the target coordinate point by using the target row number corresponding to the row where the coordinate point is located and the target column number corresponding to the column where the coordinate point is located.
[0095] At least one embodiment of the present disclosure also provides an electronic device, which includes a processor and a memory, and the memory stores one or more computer program modules. The one or more computer program modules are configured to be executed by the processor to implement the above-mentioned image scaling method. During the image scaling process, the electronic device uses rows and columns as calculation granularity to calculate the target row number of the input image corresponding to each row of the output image and the target column number of the input image corresponding to each column of the output image. Based on this, it can quickly determine which coordinate point in the output image corresponds to each coordinate point in the output image, thereby reducing the number of calculations and improving processing efficiency.
[0096] Fig. 8A A schematic block diagram of an electronic device provided in some embodiments of the present disclosure. Fig. 8A As shown, the electronic device 800 includes a processor 810 and a memory 820. The memory 820 stores non-transitory computer-readable instructions (e.g., one or more computer program modules). The processor 810 is used to run non-transitory computer-readable instructions, and the non-transitory computer-readable instructions are executed by the processor 810 to execute one or more steps in the image scaling method described above. The memory 820 and the processor 810 can be interconnected via a bus system and / or other forms of connection mechanisms (not shown). For the specific implementation of each step of the image scaling method and the related explanation content, please refer to the above-mentioned embodiment of the image scaling method, and the repetition will not be repeated here.
[0097] It should be noted that Fig. 8A The components of the electronic device 800 shown are merely exemplary and non-limiting. The electronic device 800 may also have other components according to actual application requirements.
[0098] For example, the processor 810 and the memory 820 may communicate with each other directly or indirectly.
[0099] For example, the processor 810 and the memory 820 may communicate via a network. The network may include a wireless network, a wired network, and / or any combination of a wireless network and a wired network. The processor 810 and the memory 820 may also communicate with each other via a system bus, which is not limited in the present disclosure.
[0100] For example, the processor 810 and the memory 820 may be arranged on a server side (or a cloud side).
[0101] For example, the processor 810 can control other components in the electronic device 800 to perform desired functions. For example, the processor 810 can be a central processing unit (CPU), a graphics processing unit (GPU), or other forms of processing units with data processing capabilities and / or program execution capabilities. For example, the central processing unit (CPU) can be an X86 or ARM architecture, etc. The processor 810 can be a general-purpose processor or a special-purpose processor, and can control other components in the electronic device 800 to perform desired functions.
[0102] For example, the memory 820 may include any combination of one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, erasable programmable read-only memory (EPROM), portable compact disk read-only memory (CD-ROM), USB memory, flash memory, etc. One or more computer program modules may be stored on the computer-readable storage medium, and the processor 810 may run one or more computer program modules to implement various functions of the electronic device 800. Various applications and various data, as well as various data used and / or generated by the application, etc. may also be stored in the computer-readable storage medium.
[0103] It should be noted that, in the embodiment of the present disclosure, the specific functions and technical effects of the electronic device 800 can refer to the above description of the image scaling method, which will not be repeated here.
[0104] Figure 8B This is a schematic block diagram of another electronic device provided in some embodiments of the present disclosure. The electronic device 900 is suitable for implementing the image scaling method provided in the embodiments of the present disclosure. The electronic device 900 may be a terminal device, etc. It should be noted that: Figure 8B The electronic device 900 shown is merely an example and does not impose any limitation on the functions and scope of use of the embodiments of the present disclosure.
[0105] like Figure 8BAs shown, the electronic device 900 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 910, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 920 or a program loaded from a storage device 980 into a random access memory (RAM) 930. In the RAM 930, various programs and data required for the operation of the electronic device 900 are also stored. The processing device 910, the ROM 920, and the RAM 930 are connected to each other via a bus 940. An input / output (I / O) interface 950 is also connected to the bus 940.
[0106] Typically, the following devices may be connected to the I / O interface 950: an input device 960 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 970 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 980 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 990. The communication device 990 may allow the electronic device 900 to communicate with other electronic devices wirelessly or by wire to exchange data. Although Figure 8B The electronic device 900 is shown to have various devices, but it should be understood that it is not required to implement or possess all of the devices shown, and the electronic device 900 may alternatively implement or possess more or fewer devices.
[0107] For example, according to an embodiment of the present disclosure, the above-mentioned image scaling method can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the above-mentioned image scaling method. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 990, or installed from a storage device 980, or installed from a ROM 920. When the computer program is executed by the processing device 910, the functions defined in the image scaling method provided in the embodiment of the present disclosure can be implemented.
[0108] At least one embodiment of the present disclosure further provides a computer-readable storage medium, which stores non-transitory computer-readable instructions, and when the non-transitory computer-readable instructions are executed by a computer, the above-mentioned image scaling method can be implemented. Using the computer-readable storage medium, in the image scaling process, rows and columns are used as calculation granularity to calculate the target row number of the input image corresponding to each row of the output image and the target column number of the input image corresponding to each column of the output image, based on which each coordinate point in the output image corresponds to which coordinate point in the output image, which reduces the number of calculations and improves processing efficiency.
[0109] Fig. 9A schematic diagram of a storage medium provided in some embodiments of the present disclosure. Fig. 9 As shown, the storage medium 1000 stores non-transitory computer-readable instructions 1010. For example, when the non-transitory computer-readable instructions 1010 are executed by a computer, one or more steps in the image scaling method described above are performed.
[0110] For example, the storage medium 1000 may be applied to the electronic device 800. Fig. 8A The memory 820 in the electronic device 800 is shown. For example, the relevant description of the storage medium 1000 can refer to Fig. 8A The corresponding description of the memory 820 in the electronic device 800 is shown and will not be repeated here.
[0111] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0112] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0113] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
[0114] There are a few points to note about this disclosure:
[0115] (1) The drawings of the embodiments of the present disclosure only relate to the structures involved in the embodiments of the present disclosure, and other structures may refer to the general design.
[0116] (2) In the absence of conflict, the embodiments of the present disclosure and the features therein may be combined with each other to obtain new embodiments.
[0117] The above description is only a specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. The protection scope of the present disclosure shall be based on the protection scope of the claims.
Claims
1. An image scaling method, include: Get the zoom factor; Based on the scaling factor, determining a target row number in the input image corresponding to each data row of the output image, and determining a target column number in the input image corresponding to each data column of the output image, so as to obtain a plurality of target row numbers corresponding to a plurality of data rows of the output image and a plurality of target column numbers corresponding to a plurality of data columns of the output image; Determine, based on the multiple target row numbers and the multiple target column numbers, a target coordinate point in the input image corresponding to each coordinate point in the output image; Based on the target coordinate point corresponding to each coordinate point of the output image, the pixel value of each coordinate point of the output image is determined to obtain pixel data of the output image.
2. The image scaling method according to claim 1, in, The calculation process of determining the plurality of target row numbers and the plurality of target column numbers based on the scaling factor is performed by a first processor; The calculation process of determining the pixel value of each coordinate point of the output image is performed by the second processor; The first processor supports calculation of double-precision floating-point numbers, and the second processor supports calculation of at least one type of data other than double-precision floating-point numbers.
3. The image scaling method according to claim 2, in, Determining a target coordinate point in the input image corresponding to each coordinate point of the output image based on the multiple target row numbers and the multiple target column numbers includes: The first processor converts the plurality of target row numbers and the plurality of target column numbers into integers to obtain a plurality of converted target row numbers and a plurality of converted target column numbers; The first processor copies the converted multiple target row numbers and the converted multiple target column numbers to the second processor; The second processor determines a target coordinate point in the input image corresponding to each coordinate point of the output image based on the multiple target row numbers after the conversion and the multiple target column numbers after the conversion.
4. The image scaling method according to claim 2 or 3, in, The first processor is a central processing unit, and the second processor is a graphics processing unit.
5. The image scaling method according to claim 1, in, The scaling factor includes the row-wise scaling ratio and the column-wise scaling ratio; Determining, based on the scaling factor, a target row number in the input image corresponding to each data row of the output image, including: determining, based on the column direction scaling ratio, a target row number in the input image corresponding to each data row of the output image; Determining a target column number in the input image corresponding to each data column of the output image based on the scaling factor includes: determining a target column number in the input image corresponding to each data column of the output image based on the row direction scaling ratio.
6. The image scaling method according to claim 1, in, The output image includes a first coordinate point, and the first coordinate point corresponds to a first target coordinate point in the input image; Determining a pixel value of each coordinate point of the output image based on a target coordinate point corresponding to each coordinate point of the output image includes: Determine pixel values of four reference points in the input image corresponding to the first target coordinate point; Based on the pixel values of the four reference points, the pixel value of the first coordinate point is determined.
7. The image scaling method according to claim 1, in, Determining a target coordinate point in the input image corresponding to each coordinate point of the output image based on the multiple target row numbers and the multiple target column numbers includes: For each coordinate point of the output image, the target row number corresponding to the row where the coordinate point is located and the target column number corresponding to the column where the coordinate point is located are used to determine the target coordinate point.
8. An image scaling device, include: an acquisition unit configured to acquire a scaling factor; a first determining unit configured to determine, based on the scaling factor, a target row number in the input image corresponding to each data row of the output image, and a target column number in the input image corresponding to each data column of the output image, so as to obtain a plurality of target row numbers corresponding to a plurality of data rows of the output image and a plurality of target column numbers corresponding to a plurality of data columns of the output image; a second determining unit, configured to determine a target coordinate point in the input image corresponding to each coordinate point of the output image based on the multiple target row numbers and the multiple target column numbers; The third determining unit is configured to determine the pixel value of each coordinate point of the output image based on the target coordinate point corresponding to each coordinate point of the output image to obtain pixel data of the output image.
9. An electronic device, include: processor; A memory storing one or more computer program modules; The one or more computer program modules are configured to be executed by the processor to implement the image scaling method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing non-transitory computer-readable instructions, which, when executed by a computer, can implement the image scaling method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Image interpolation method and device, equipment and medium
CN112508790A
Image zooming method and device, electronic equipment and storage medium
CN112508793A
Image magnification method and device, electronic equipment and readable storage medium
CN116263936A
Image interpolation method and device, electronic equipment and storage medium
CN116843555A
Method and device for transforming an object image
US20030151614A1
Cited By
Image processing method and apparatus, and computer-readable storage medium
WO2026157062A1
