Image scaling method and device, equipment and medium
By accurately calculating the vertical and horizontal scaling ratios and combining them with preset sharpness adjustment parameters for linear interpolation, the image quality problem of traditional bilinear interpolation algorithms at high scaling ratios is solved, achieving high-precision pixel correspondence and optimizing edge sharpness and detail fidelity.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SOPHGO TECH LTD
- Filing Date
- 2025-11-26
- Publication Date
- 2026-04-17
AI Technical Summary
Traditional bilinear interpolation algorithms cause images to lose important feature information when scaled at high magnification, resulting in visual problems such as jagged edges and excessive sharpness.
By accurately calculating the vertical and horizontal scaling ratios, the pixel positions of the target image are mapped to the floating-point coordinate positions of the initial image, the mean value of the neighboring pixels is determined, and linear interpolation is performed in combination with preset sharpness adjustment parameters to optimize edge sharpness.
It improves the visual quality and detail retention of images, reduces image blurring or jagged edges, adapts to image scaling requirements with different aspect ratios, and ensures that image content is not distorted.
Smart Images

Figure CN121883244A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image scaling method, apparatus, device, and medium. Background Technology
[0002] With the widespread adoption of digital image applications, image scaling technology has become an important research direction in the field of image processing. When limited by factors such as network bandwidth and hardware performance, it is often necessary to downsample high-resolution images to reduce the data volume while preserving image clarity and detail as much as possible. Existing bilinear interpolation image scaling algorithms are widely used in various image scaling scenarios due to their computational simplicity, high efficiency, and good visual effects. However, traditional bilinear interpolation algorithms exhibit significant image quality defects at high scaling ratios, affecting the quality of the final output image.
[0003] Specifically, related techniques typically use only the two nearest neighbor pixels horizontally and vertically corresponding to the floating-point coordinates for weighted averaging. This results in some key pixels not being effectively sampled during high-magnification scaling, leading to the output image lacking important feature information and degrading its visual quality. Secondly, the weight calculation in these techniques relies entirely on the distance between the pixel and its floating-point coordinates. When the floating-point coordinate is extremely close to a neighboring pixel, that pixel's weight approaches its maximum, causing the features of other neighboring pixels to be ignored, resulting in jagged edges and excessive sharpness. To address these issues, this invention proposes an image scaling method aimed at improving the visual quality and detail retention of the scaled image. Summary of the Invention
[0004] This invention provides an image scaling method, apparatus, device, and medium to solve the technical problem of poor visual quality and detail retention of scaled images in related technologies.
[0005] Firstly, an image scaling method is provided, the method comprising: The height and width information of the initial image and the target image are obtained respectively, and the vertical scaling ratio is determined based on the height information, and the horizontal scaling ratio is determined based on the width information; The target pixel positions in the target image are mapped to the floating-point coordinate positions in the initial image based on the horizontal scaling ratio and the vertical scaling ratio, respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates; The average pixel value within a preset pixel position range in the initial image is determined based on the horizontal and vertical floating-point coordinates to obtain the average pixel value of the neighborhood; wherein, the preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio. The interpolation weight range is limited according to preset sharpness adjustment parameters, and the mean value of the neighboring pixels is linearly interpolated to obtain the target pixels of the target image, so as to scale the initial image.
[0006] Secondly, an image scaling device is provided, comprising: The acquisition module is used to acquire the height information and width information of the initial image and the target image respectively, and determine the vertical scaling ratio based on the height information and the horizontal scaling ratio based on the width information; The mapping module is used to map the target pixel position in the target image to the floating-point coordinate position in the initial image based on the horizontal scaling ratio and the vertical scaling ratio, respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates; The determining module is used to determine the average pixel value within a preset pixel position range in the initial image based on the horizontal floating-point coordinates and the vertical floating-point coordinates, thereby obtaining the average pixel value of the neighborhood; wherein, the preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio; The scaling module is used to limit the interpolation weight range according to a preset sharpness adjustment parameter, and to perform linear interpolation on the mean value of the neighboring pixels to obtain the target pixels of the target image, so as to scale the initial image.
[0007] Thirdly, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the image scaling method described above.
[0008] Fourthly, a computer-readable storage medium is provided, which stores a computer program that, when executed by a processor, implements the steps of the image scaling method described above.
[0009] The image scaling method, apparatus, computer device, and storage medium described above include the following steps: acquiring height and width information of an initial image and a target image respectively; determining a vertical scaling ratio based on the height information and a horizontal scaling ratio based on the width information; mapping the target pixel position in the target image to the floating-point coordinate position in the initial image based on the horizontal and vertical scaling ratios respectively, to obtain the corresponding horizontal and vertical floating-point coordinates; determining the average pixel value within a preset pixel position range in the initial image based on the horizontal and vertical floating-point coordinates, to obtain the average neighboring pixel value; wherein the preset pixel position range is determined based on the horizontal and vertical scaling ratios; limiting the interpolation weight range according to a preset sharpness adjustment parameter, and performing linear interpolation on the average neighboring pixel value to obtain the target pixel of the target image, thereby scaling the initial image. In this invention, by accurately calculating the vertical and horizontal scaling ratios and mapping the target pixel position in the target image to the floating-point coordinate position in the initial image, a high-precision pixel correspondence is achieved, which can effectively reduce image blurring or jaggedness caused by direct pixel mapping. Furthermore, the mean value of neighboring pixels is determined within a preset pixel location range, and linear interpolation is performed in conjunction with preset sharpness adjustment parameters. This allows the scaled image to maintain overall detail clarity while optimizing edge sharpness, thereby improving the image's visual effect and detail fidelity. In addition, this method handles aspect ratios independently, adapting to image scaling requirements with different aspect ratios and ensuring that image content remains undistorted. Therefore, it improves the visual quality and detail preservation of the scaled image. Attached Figure Description
[0010] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 This is a schematic diagram of an application environment for an image scaling method according to an embodiment of the present invention; Figure 2 This is a flowchart illustrating an image scaling method according to an embodiment of the present invention; Figure 3 yes Figure 2 A schematic diagram of a specific implementation method for step S30; Figure 4 This is a schematic diagram of the structure of an image scaling device in one embodiment of the present invention; Figure 5 This is a schematic diagram of the structure of a computer device according to an embodiment of the present invention; Figure 6 This is another structural schematic diagram of a computer device according to one embodiment of the present invention. Detailed Implementation
[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0013] The image scaling method provided in this embodiment of the invention can be applied to, for example... Figure 1 In this application environment, the client communicates with the server via a network. The server can obtain the height and width information of the initial image and the target image from the client, respectively, and determine the vertical scaling ratio based on the height information and the horizontal scaling ratio based on the width information. Based on the horizontal and vertical scaling ratios, the target pixel positions in the target image are mapped to floating-point coordinate positions in the initial image to obtain the corresponding horizontal and vertical floating-point coordinates. The average pixel value within a preset pixel position range in the initial image is determined based on the horizontal and vertical scaling ratios to obtain the average neighboring pixels. The preset pixel position range is determined based on the horizontal and vertical scaling ratios. The interpolation weight range is limited by a preset sharpness adjustment parameter, and the average neighboring pixels are linearly interpolated to obtain the target pixels of the target image, thereby scaling the initial image. In this invention, by accurately calculating the vertical and horizontal scaling ratios and mapping the target pixel positions in the target image to the floating-point coordinate positions in the initial image, a high-precision pixel correspondence is achieved, effectively reducing image blurring or jagged edges caused by direct pixel mapping. Furthermore, the mean value of neighboring pixels is determined within a preset pixel location range, and linear interpolation is performed in conjunction with preset sharpness adjustment parameters. This allows the scaled image to maintain overall detail clarity while optimizing edge sharpness, thereby improving the visual effect and detail fidelity of the image. In addition, this method handles aspect ratios independently, adapting to image scaling requirements with different aspect ratios and ensuring that the image content remains undistorted. Therefore, it improves the visual quality and detail retention of the scaled image. The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be implemented using a standalone server or a server cluster consisting of multiple servers. The invention will be described in detail below through specific embodiments.
[0014] Please see Figure 2 As shown, Figure 2A flowchart illustrating an image scaling method provided in an embodiment of the present invention is shown. The method includes the following steps: S10: Obtain the height and width information of the initial image and the target image respectively, and determine the vertical scaling ratio based on the height information and the horizontal scaling ratio based on the width information.
[0015] It should be noted that the initial image is the original image before scaling; the target image is the image to be generated after scaling, and its size is determined by system preset or user input.
[0016] For example, the height and width information of the initial image and the target image can be obtained separately, where the height information is the number of pixels in the vertical direction and the width information is the number of pixels in the horizontal direction. Further, a vertical scaling ratio can be determined based on the height information, and a horizontal scaling ratio can be determined based on the width information. The vertical scaling ratio is the ratio of the height information of the target image to the height information of the initial image, used to determine the scaling factor in the vertical direction; the horizontal scaling ratio is the ratio of the width information of the target image to the width information of the initial image, used to determine the scaling factor in the horizontal direction.
[0017] In some embodiments, the height information includes a first height of the initial image and a second height of the target image, and the width information includes a first width of the initial image and a second width of the target image. Determining the vertical scaling ratio based on the height information and determining the horizontal scaling ratio based on the width information includes: determining the ratio of the second height to the first height as the vertical scaling ratio; and determining the ratio of the second width to the first width as the horizontal scaling ratio.
[0018] It should be noted that the first height is the number of pixels in the initial image in the vertical direction, and the second height is the number of pixels in the target image in the vertical direction; the first width is the number of pixels in the initial image in the horizontal direction, and the second width is the number of pixels in the target image in the horizontal direction.
[0019] For example, the second height can be divided by the first height to obtain the vertical scaling ratio, which is used to determine the scaling factor in the vertical direction; the second width can be divided by the first width to obtain the horizontal scaling ratio, which is used to determine the scaling factor in the horizontal direction.
[0020] Specifically, this can be explained using the following formula: scalex=Wdst / Wsrc scaley=Hdst / Hsrc Where scalex is the horizontal scaling ratio, scaley is the vertical scaling ratio, Wdst is the second width, Wsrc is the first width, Hdst is the second height, and Hsrc is the first height.
[0021] Through the above embodiments, the vertical scaling ratio and the horizontal scaling ratio can be used as input parameters for subsequent pixel mapping and interpolation calculations to ensure that each pixel position in the target image can be accurately mapped to the corresponding position in the initial image during the scaling process, thereby maintaining the consistency of geometric structure and detail features in the scaling result.
[0022] S20: Map the target pixel position in the target image to the floating-point coordinate position in the initial image based on the horizontal scaling ratio and the vertical scaling ratio respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates.
[0023] It should be noted that the target pixel position refers to the coordinate position of a pixel in the target image. Floating-point coordinate position refers to the pixel position represented by non-integer real coordinates in the initial image coordinate system, used to accurately describe the corresponding position of a pixel in the target image within the initial image.
[0024] For example, the horizontal index value of the target pixel location can be divided by the horizontal scaling factor to obtain the horizontal floating-point coordinates; the vertical index value of the target pixel location can be divided by the vertical scaling factor to obtain the vertical floating-point coordinates. Furthermore, the combination of the horizontal and vertical floating-point coordinates is used to indicate the precise mapped position of the target pixel location in the initial image. This position may be located at the center point of a single pixel in the initial image, or it may be located between multiple pixels.
[0025] The above embodiments, by representing the position using floating-point coordinates, can preserve sub-pixel-level positional information, providing high-precision input conditions for subsequent interpolation operations based on neighboring pixels, thereby ensuring the restoration of details and smoothing of edges in the scaled image.
[0026] In some embodiments, mapping the target pixel position in the target image to the floating-point coordinate position in the initial image based on the horizontal scaling ratio and the vertical scaling ratio respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates, includes: obtaining the horizontal coordinate value and the vertical coordinate value of the target pixel position in the target image; adding 0.5 to the horizontal coordinate value to obtain the offset horizontal coordinate value; and adding 0.5 to the vertical coordinate value to obtain the offset vertical coordinate value; determining a first product of the offset horizontal coordinate value and the horizontal scaling ratio, and subtracting 0.5 from the first product to obtain the horizontal floating-point coordinate; and determining a second product of the offset vertical coordinate and the vertical scaling ratio, and subtracting 0.5 from the second product to obtain the vertical floating-point coordinate.
[0027] It should be noted that the horizontal and vertical coordinates of the target pixel position are both integers in the pixel grid of the target image. The horizontal coordinate represents the pixel position in the horizontal direction, and the vertical coordinate represents the pixel position in the vertical direction.
[0028] It should be understood that adding 0.5 to both the horizontal and vertical coordinate values is to shift the target pixel position from the upper left corner of the pixel grid to the pixel center, so that the mapping calculation is based on the pixel center and geometric distortion is reduced.
[0029] For example, the offset horizontal coordinate value can be multiplied by the horizontal scaling factor to obtain the first product, and then 0.5 can be subtracted to obtain the horizontal floating-point coordinate; similarly, the offset vertical coordinate value can be multiplied by the vertical scaling factor to obtain the second product, and then 0.5 can be subtracted to obtain the vertical floating-point coordinate. Specifically, this can be explained using the following formula: xsrc=(xdst+0.5)×scalex 0.5 ysrc=(ydst+0.5)×scaley 0.5 Where xdst and ydst represent the horizontal and vertical coordinates of the target pixel position, respectively; xsrc and ysrc represent the horizontal and vertical floating-point coordinates, respectively; scalex is the horizontal scaling ratio; and scaley is the vertical scaling ratio.
[0030] It should be understood that horizontal and vertical floating-point coordinates allow the representation of non-integer positions, thus accurately reflecting the sub-pixel position of the target pixel in the initial image coordinate system. This provides a high-precision mapping basis for subsequent neighbor pixel lookup and interpolation operations, thereby ensuring the smoothness and accuracy of the scaling results in terms of detail and edge transitions.
[0031] S30: Determine the average pixel value within a preset pixel position range in the initial image based on the horizontal floating-point coordinates and the vertical floating-point coordinates to obtain the average pixel value of the neighborhood.
[0032] The preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio.
[0033] It should be noted that the horizontal and vertical floating-point coordinates are used to indicate the precise location of a pixel in the target image within the initial image coordinate system. This location is usually not an integer pixel, but rather lies between multiple pixels. Therefore, to calculate the color or grayscale value corresponding to this location, a preset pixel location range can be selected in the initial image. This range is a rectangular or square neighborhood area centered on the horizontal and vertical floating-point coordinates and calculated using the horizontal and vertical scaling ratios. For example, when both the horizontal and vertical scaling ratios are 2, the preset pixel location range may contain 2 pixels horizontally and 2 pixels vertically. When the scaling ratio is large or small, the number of pixels in the range will be adjusted accordingly to ensure sufficient pixel information for interpolation calculations.
[0034] For example, within a preset pixel location range, the values of all pixels (such as RGB color values or grayscale values) can be arithmetically averaged to obtain the mean value of the neighboring pixels. The mean value of the neighboring pixels can comprehensively reflect the overall brightness and color trend of the pixels around the floating-point coordinate position, which can reduce sharp noise or jagged edges caused by single pixel sampling, and provide a smooth and representative base value for subsequent interpolation calculations, thereby improving the overall visual quality and detail reproduction of the scaled image.
[0035] In some embodiments, the preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio, including: determining a first integer part of the horizontal scaling ratio and a second integer part of the vertical scaling ratio; subtracting one from the first integer part to obtain the horizontal pixel range, and subtracting one from the second integer part to obtain the vertical pixel range; and determining the horizontal pixel range and the vertical pixel range as the preset pixel position range.
[0036] Specifically, the preset pixel position range can be obtained using the following formula: M=[scalex]-1; N=[scaley]-1; Where M is the horizontal pixel range; N is the vertical pixel range; M*N is used to represent the preset pixel position range; scalex is the horizontal scaling ratio and scaley is the vertical scaling ratio.
[0037] Among them, such as Figure 3 As shown, step S30, namely determining the average pixel value within a preset pixel position range in the initial image based on the horizontal and vertical floating-point coordinates to obtain the average neighboring pixel value, includes the following steps: S31: Determine the adjacent horizontal integer coordinates and adjacent vertical integer coordinates corresponding to the horizontal floating-point coordinates and the vertical floating-point coordinates in the initial image, respectively.
[0038] S32: Determine the coordinates of four target neighboring pixels in the initial image based on the adjacent horizontal integer coordinates and the adjacent vertical integer coordinates.
[0039] S33: Determine the arithmetic average of several pixel values within the preset pixel position range centered on the target neighborhood pixel coordinates to obtain the pixel mean.
[0040] S34: The average pixel value is determined as the average pixel value of the neighboring pixels corresponding to the coordinates of the neighboring pixels.
[0041] For example, the adjacent horizontal and vertical integer coordinates in the initial image can be determined separately for the horizontal and vertical floating-point coordinates.
[0042] Specifically, the adjacent horizontal integer coordinates and adjacent vertical integer coordinates can be obtained using the following formula: x1=[xsrc], y1=[ysrc]; x2 = x1 + 1, y2 = y1 + 1; Where x1 and x2 are adjacent horizontal integer coordinates; y1 and y2 are adjacent vertical integer coordinates.
[0043] It should be noted that, in order to ensure that the above coordinates are all within the valid range of the initial image and do not exceed the boundary, x2 <Wsrc,y2<Hsrc。
[0044] Furthermore, the coordinates of four target neighboring pixels in the initial image can be determined based on the aforementioned adjacent horizontal and vertical integer coordinates, namely, the target neighboring pixel coordinates are (x1, y1), (x2, y1), (x1, y2), and (x2, y2). The target neighboring pixel coordinates can be used to calculate the local pixel average value, thereby providing the basic values for interpolation.
[0045] Furthermore, the arithmetic mean of several pixel values within a preset pixel position range centered on the coordinates of the four target neighboring pixels can be determined to obtain the pixel mean.
[0046] Specifically, this can be explained using the following formula: Q 11 =(I(x1,y1) + I(x 1-1 ,y1) + I(x1,y 1-1 ) + I(x 1-1 ,y 1-1 ) + …) / (M*N) Q 21 =(I(x2,y1) + I(x 2+1 ,y1) + I(x2,y 1-1 ) + I(x 2+1,y 1-1 ) + …) / (M*N) Q 12 =(I(x1,y2) + I(x 1-1 ,y2) + I(x1,y 2+1 ) + I(x 1-1 ,y 2+1 ) + …) / (M*N) Q 22 =(I(x2,y2) + I(x 2+1 ,y2) + I(x2,y 2+1 ) + I(x 2+1 ,y 2+1 ) + …) / (M*N) Among them, Q 11 Let Q be the mean value of the pixel centered at (x1, y1). 12 Let Q be the mean value of the pixel centered at (x1, y2). 21 Let Q be the mean value of the pixel centered at (x2, y1). 22 Let M be the average pixel value centered at (x2, y2), and M*N be used to represent the preset pixel position range.
[0047] Therefore, the above pixel mean can be determined as the neighborhood pixel mean corresponding to the neighborhood pixel coordinates, so that the subsequent interpolation steps can generate the final pixel value of the target image based on these smooth neighborhood mean values, thereby achieving a smooth transition of image details and anti-aliasing effect during scaling.
[0048] In some embodiments, the adjacent horizontal integer coordinates include a first horizontal integer coordinate and a second horizontal integer coordinate; the adjacent vertical integer coordinates include a first vertical integer coordinate and a second vertical integer coordinate; the target neighbor pixel coordinates include a first neighbor pixel coordinate, a second neighbor pixel coordinate, a third neighbor pixel coordinate, and a fourth neighbor pixel coordinate; determining the four target neighbor pixel coordinates in the initial image based on the adjacent horizontal integer coordinates and the adjacent vertical integer coordinates includes: determining the first horizontal integer coordinate and the first vertical integer coordinate as the first neighbor pixel coordinates; determining the first horizontal integer coordinate and the second vertical integer coordinate as the second neighbor pixel coordinates; determining the second horizontal integer coordinate and the first vertical integer coordinate as the third neighbor pixel coordinates; and determining the second horizontal integer coordinate and the second vertical integer coordinate as the fourth neighbor pixel coordinates.
[0049] For example, based on adjacent horizontal and vertical integer coordinates, the coordinates of four target neighboring pixels in the initial image can be determined: the first neighboring pixel coordinate is obtained by combining the first horizontal and first vertical integer coordinates, and is located at the top left corner of the floating-point coordinates; the second neighboring pixel coordinate is obtained by combining the first horizontal and second vertical integer coordinates, and is located at the bottom left corner; the third neighboring pixel coordinate is obtained by combining the second horizontal and first vertical integer coordinates, and is located at the top right corner; the fourth neighboring pixel coordinate is obtained by combining the second horizontal and second vertical integer coordinates, and is located at the bottom right corner.
[0050] In this way, it is possible to accurately obtain the local information required by the target pixel during the scaling process, thereby achieving smooth image scaling and anti-aliasing effects.
[0051] S40: Limit the interpolation weight range according to the preset sharpness adjustment parameters, and perform linear interpolation on the mean value of the neighboring pixels to obtain the target pixels of the target image, so as to scale the initial image.
[0052] For example, the interpolation weights can first be limited according to preset sharpness adjustment parameters. The interpolation weight refers to the proportion of each neighboring pixel's contribution to the target pixel value when linearly interpolating the mean of neighboring pixels. By using preset sharpness adjustment parameters, the range of the weights can be controlled, thereby adjusting the sharpness of the image after scaling and avoiding excessive blurring or over-sharpening. For example, the interpolation weights can be limited to the range [E, 1-E], where E is a preset sharpness adjustment parameter, which is user-defined and not limited here.
[0053] Furthermore, linear interpolation can be performed on the calculated mean values of neighboring pixels. Specifically, the horizontal and vertical offsets of the floating-point coordinates can be weighted and combined with the mean values of neighboring pixels to obtain the target pixel value. For example, the mean values of the top-left, bottom-left, top-right, and bottom-right neighboring pixels can be linearly weighted according to their respective weights and summed to obtain the target pixel value.
[0054] Ultimately, through the above interpolation calculations, the target pixel value can accurately reflect the brightness and color information of the corresponding area in the initial image, achieving smooth scaling of the initial image while ensuring controllable sharpness and preserving image details as much as possible.
[0055] In some embodiments, the step of limiting the interpolation weight range according to a preset sharpness adjustment parameter and performing linear interpolation on the mean of the neighboring pixels to obtain the target pixel of the target image for scaling the initial image includes: determining a first distance between the horizontal floating-point coordinate and the corresponding integer part and a second distance between the vertical floating-point coordinate and the corresponding integer part, and limiting the first distance and the second distance according to the preset sharpness adjustment parameter to obtain horizontal interpolation weight and vertical interpolation weight; based on the horizontal interpolation weight, performing a weighted average of the two pixel means in any row of the mean of the neighboring pixels to obtain a first horizontal interpolation result and a second horizontal interpolation result; based on the vertical interpolation weight, performing a weighted average of the first horizontal interpolation result and the second horizontal interpolation result to obtain the target pixel for scaling the initial image.
[0056] For example, this can be explained using the following formula: dx=(xsrc x1)*(1-2E) + E;dy=(ysrc y1)*(1-2E) + E Where dx and dy are the horizontal and vertical interpolation weights, respectively, E is the preset sharpness adjustment parameter, and xsrc is the vertical interpolation weight. x1 represents the first distance, ysrc y1 is the second distance. Furthermore, R1=Q 11 ×(1 dx)+Q 21 ×dx R2=Q 12 ×(1 dx)+Q 22 ×dx Where R1 and R2 are the first and second horizontal interpolation results, respectively, and Q is the second horizontal interpolation result. 11 Let (x1, y1) be the mean value of the pixel centered at (x1, y1), and Q be the mean value of the pixel centered at (x1, y1). 12 Let Q be the mean value of the pixel centered at (x1, y2). 21 Let Q be the mean value of the pixel centered at (x2, y1). 22 Let be the mean pixel value centered at (x2, y2), and dx be the horizontal interpolation weight. Therefore, the target pixel can be obtained using the following formula: P=R1×(1 dy)+R2×dy Where P is the target pixel, R1 and R2 are the first and second horizontal interpolation results, respectively, and dy is the vertical interpolation weight.
[0057] As can be seen, the above scheme achieves high-precision pixel correspondence by accurately calculating the vertical and horizontal scaling ratios and mapping the target pixel positions in the target image to the floating-point coordinate positions in the initial image. This effectively reduces image blurring or jagged edges caused by direct pixel mapping. Furthermore, by determining the average value of neighboring pixels within a preset pixel position range and performing linear interpolation in conjunction with preset sharpness adjustment parameters, the scaled image maintains overall detail clarity while optimizing edge sharpness, thereby improving the image's visual effect and detail fidelity. In addition, this method handles vertical and horizontal aspect ratios independently, adapting to image scaling requirements with different aspect ratios and ensuring that image content remains undistorted. Therefore, it improves the visual quality and detail preservation of the scaled image.
[0058] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0059] In one embodiment, an image scaling device is provided, which corresponds one-to-one with the image scaling methods described in the above embodiments. For example... Figure 4 As shown, the image scaling device includes an acquisition module 101, a mapping module 102, a determination module 103, and a scaling module 104. Detailed descriptions of each functional module are as follows: The acquisition module 101 is used to acquire the height information and width information of the initial image and the target image respectively, and determine the vertical scaling ratio based on the height information and the horizontal scaling ratio based on the width information; The mapping module 102 is used to map the target pixel position in the target image to the floating-point coordinate position in the initial image based on the horizontal scaling ratio and the vertical scaling ratio, respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates; The determining module 103 is used to determine the average pixel value within a preset pixel position range in the initial image based on the horizontal floating-point coordinates and the vertical floating-point coordinates, thereby obtaining the average pixel value in the neighborhood; wherein, the preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio; The scaling module 104 is used to limit the interpolation weight range according to the preset sharpness adjustment parameters, and to perform linear interpolation on the mean value of the neighboring pixels to obtain the target pixels of the target image, so as to scale the initial image.
[0060] The acquisition module 101 is used to determine the ratio of the second height to the first height as the vertical scaling ratio; and to determine the ratio of the second width to the first width as the horizontal scaling ratio.
[0061] The mapping module 102 is used to obtain the horizontal and vertical coordinate values of the target pixel position in the target image; add 0.5 to the horizontal coordinate value to obtain the offset horizontal coordinate value; and add 0.5 to the vertical coordinate value to obtain the offset vertical coordinate value; determine a first product of the offset horizontal coordinate value and the horizontal scaling ratio, and subtract 0.5 from the first product to obtain the horizontal floating-point coordinate; and determine a second product of the offset vertical coordinate and the vertical scaling ratio, and subtract 0.5 from the second product to obtain the vertical floating-point coordinate.
[0062] The determining module 103 is used to determine the adjacent horizontal integer coordinates and adjacent vertical integer coordinates corresponding to the horizontal floating-point coordinates and the vertical floating-point coordinates in the initial image, respectively; determine the coordinates of four target neighboring pixels in the initial image based on the adjacent horizontal integer coordinates and adjacent vertical integer coordinates; determine the arithmetic average of several pixel values within the preset pixel position range centered on the target neighboring pixel coordinates to obtain the pixel mean; and determine the pixel mean as the neighboring pixel mean corresponding to the neighboring pixel coordinates.
[0063] The determining module 103 is used to determine the first horizontal integer coordinate and the first vertical integer coordinate as the first neighboring pixel coordinate; determine the first horizontal integer coordinate and the second vertical integer coordinate as the second neighboring pixel coordinate; determine the second horizontal integer coordinate and the first vertical integer coordinate as the third neighboring pixel coordinate; and determine the second horizontal integer coordinate and the second vertical integer coordinate as the fourth neighboring pixel coordinate.
[0064] The determining module 103 is used to determine a first integer part of the horizontal scaling ratio and a second integer part of the vertical scaling ratio respectively; subtract one from the first integer part to obtain a horizontal pixel range, and subtract one from the second integer part to obtain a vertical pixel range; and determine the horizontal pixel range and the vertical pixel range as the preset pixel position range.
[0065] The scaling module 104 is used to determine a first distance between the horizontal floating-point coordinate and its corresponding integer part and a second distance between the vertical floating-point coordinate and its corresponding integer part, and to limit the first distance and the second distance according to the preset sharpness adjustment parameter to obtain horizontal interpolation weights and vertical interpolation weights; based on the horizontal interpolation weights, to perform a weighted average of the two pixel means in any row of the neighboring pixel means to obtain a first horizontal interpolation result and a second horizontal interpolation result; based on the vertical interpolation weights, to perform a weighted average of the first horizontal interpolation result and the second horizontal interpolation result to obtain the target pixel, so as to scale the initial image.
[0066] This invention provides an image scaling device that achieves high-precision pixel correspondence by accurately calculating the vertical and horizontal scaling ratios and mapping the target pixel positions in the target image to the floating-point coordinate positions of the initial image. This effectively reduces image blurring or jagged edges caused by direct pixel mapping. Furthermore, by determining the average value of neighboring pixels within a preset pixel position range and performing linear interpolation in conjunction with preset sharpness adjustment parameters, the scaled image maintains overall detail clarity while optimizing edge sharpness, thereby improving the image's visual effect and detail fidelity. In addition, this method handles vertical and horizontal aspect ratios independently, adapting to image scaling requirements with different aspect ratios and ensuring no distortion of image content. Therefore, it improves the visual quality and detail retention of the scaled image.
[0067] For specific limitations regarding the image scaling device, please refer to the limitations of the image scaling method above, which will not be repeated here. Each module in the aforementioned image scaling device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of the processor in the computer device, or stored in software in the memory of the computer device, so that the processor can call and execute the operations corresponding to each module.
[0068] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 5 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with external clients via a network connection. When executed by the processor, the computer program implements the functions or steps of an image scaling method on the server side.
[0069] In one embodiment, a computer device is provided, which may be a client, and its internal structure diagram may be as follows: Figure 6As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface is used to communicate with an external server via a network connection. When executed by the processor, the computer program implements the client-side functions or steps of an image scaling method. In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to perform the following steps: The height and width information of the initial image and the target image are obtained respectively, and the vertical scaling ratio is determined based on the height information, and the horizontal scaling ratio is determined based on the width information; The target pixel positions in the target image are mapped to the floating-point coordinate positions in the initial image based on the horizontal scaling ratio and the vertical scaling ratio, respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates; The average pixel value within a preset pixel position range in the initial image is determined based on the horizontal and vertical floating-point coordinates to obtain the average pixel value of the neighborhood; wherein, the preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio. The interpolation weight range is limited according to preset sharpness adjustment parameters, and the mean value of the neighboring pixels is linearly interpolated to obtain the target pixels of the target image, so as to scale the initial image.
[0070] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor: The height and width information of the initial image and the target image are obtained respectively, and the vertical scaling ratio is determined based on the height information, and the horizontal scaling ratio is determined based on the width information; The target pixel positions in the target image are mapped to the floating-point coordinate positions in the initial image based on the horizontal scaling ratio and the vertical scaling ratio, respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates; The average pixel value within a preset pixel position range in the initial image is determined based on the horizontal and vertical floating-point coordinates to obtain the average pixel value of the neighborhood; wherein, the preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio. The interpolation weight range is limited according to preset sharpness adjustment parameters, and the mean value of the neighboring pixels is linearly interpolated to obtain the target pixels of the target image, so as to scale the initial image.
[0071] It should be noted that the functions or steps that can be implemented by the computer-readable storage medium or computer device described above can be referred to the relevant descriptions on the server side and client side in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.
[0072] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0073] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0074] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. An image scaling method, characterized in that, The method includes: The height and width information of the initial image and the target image are obtained respectively, and the vertical scaling ratio is determined based on the height information, and the horizontal scaling ratio is determined based on the width information; The target pixel positions in the target image are mapped to the floating-point coordinate positions in the initial image based on the horizontal scaling ratio and the vertical scaling ratio, respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates; The average pixel value within a preset pixel position range in the initial image is determined based on the horizontal and vertical floating-point coordinates to obtain the average pixel value of the neighborhood; wherein, the preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio. The interpolation weight range is limited according to preset sharpness adjustment parameters, and the mean value of the neighboring pixels is linearly interpolated to obtain the target pixels of the target image, so as to scale the initial image.
2. The method according to claim 1, characterized in that, The height information includes a first height of the initial image and a second height of the target image; the width information includes a first width of the initial image and a second width of the target image; determining the vertical scaling ratio based on the height information and determining the horizontal scaling ratio based on the width information includes: The ratio of the second height to the first height is determined as the vertical scaling ratio; and, The ratio of the second width to the first width is determined as the horizontal scaling ratio.
3. The method according to claim 1, characterized in that, The step of mapping the target pixel position in the target image to the floating-point coordinate position in the initial image based on the horizontal scaling ratio and the vertical scaling ratio, respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates, includes: Obtain the horizontal and vertical coordinates of the target pixel position in the target image; Add 0.5 to the horizontal coordinate value to obtain the offset horizontal coordinate value; and add 0.5 to the vertical coordinate value to obtain the offset vertical coordinate value; The first product of the offset horizontal coordinate value and the horizontal scaling ratio is determined, and the first product is subtracted by 0.5 to obtain the horizontal floating-point coordinate; and the second product of the offset vertical coordinate and the vertical scaling ratio is determined, and the second product is subtracted by 0.5 to obtain the vertical floating-point coordinate.
4. The method according to claim 1, characterized in that, The step of determining the average pixel value within a preset pixel position range in the initial image based on the horizontal and vertical floating-point coordinates to obtain the average pixel value in the neighborhood includes: Determine the adjacent horizontal integer coordinates and adjacent vertical integer coordinates corresponding to the horizontal floating-point coordinates and the vertical floating-point coordinates in the initial image, respectively. The coordinates of four target neighboring pixels in the initial image are determined based on the adjacent horizontal integer coordinates and the adjacent vertical integer coordinates. The arithmetic average of several pixel values within a preset pixel position range centered on the target neighborhood pixel coordinates is determined to obtain the pixel mean value; The average pixel value is determined as the average pixel value of the neighboring pixels corresponding to the coordinates of the neighboring pixels.
5. The method according to claim 4, characterized in that, The adjacent horizontal integer coordinates include a first horizontal integer coordinate and a second horizontal integer coordinate; the adjacent vertical integer coordinates include a first vertical integer coordinate and a second vertical integer coordinate; the target neighborhood pixel coordinates include a first neighborhood pixel coordinate, a second neighborhood pixel coordinate, a third neighborhood pixel coordinate, and a fourth neighborhood pixel coordinate; determining the four target neighborhood pixel coordinates in the initial image based on the adjacent horizontal integer coordinates and adjacent vertical integer coordinates includes: The first horizontal integer coordinate and the first vertical integer coordinate are determined as the first neighboring pixel coordinates; The first horizontal integer coordinate and the second vertical integer coordinate are determined as the second neighboring pixel coordinates; The second horizontal integer coordinate and the first vertical integer coordinate are determined as the third neighboring pixel coordinates; The second horizontal integer coordinate and the second vertical integer coordinate are determined as the fourth neighboring pixel coordinates.
6. The method according to claim 1, characterized in that, The preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio, including: Determine the first integer part of the horizontal scaling ratio and the second integer part of the vertical scaling ratio, respectively; Subtract one from the first integer part to obtain the horizontal pixel range, and subtract one from the second integer part to obtain the vertical pixel range; The horizontal pixel range and the vertical pixel range are determined as the preset pixel position range.
7. The method according to claim 1, characterized in that, The step of limiting the interpolation weight range according to a preset sharpness adjustment parameter and performing linear interpolation on the mean of the neighboring pixels to obtain the target pixels of the target image, in order to scale the initial image, includes: Determine the first distance between the horizontal floating-point coordinate and the corresponding integer part and the second distance between the vertical floating-point coordinate and the corresponding integer part, and limit the first distance and the second distance according to the preset sharpness adjustment parameter to obtain the horizontal interpolation weight and the vertical interpolation weight. Based on the horizontal interpolation weights, the weighted average of the two pixel means in any row of the neighboring pixel means is calculated to obtain the first horizontal interpolation result and the second horizontal interpolation result. Based on the vertical interpolation weights, the first horizontal interpolation result and the second horizontal interpolation result are weighted and averaged to obtain the target pixel, so as to scale the initial image.
8. An image scaling device, characterized in that, The image scaling device includes: The acquisition module is used to acquire the height information and width information of the initial image and the target image respectively, and determine the vertical scaling ratio based on the height information and the horizontal scaling ratio based on the width information; The mapping module is used to map the target pixel position in the target image to the floating-point coordinate position in the initial image based on the horizontal scaling ratio and the vertical scaling ratio, respectively, to obtain the corresponding horizontal floating-point coordinates and vertical floating-point coordinates; The determining module is used to determine the average pixel value within a preset pixel position range in the initial image based on the horizontal floating-point coordinates and the vertical floating-point coordinates, thereby obtaining the average pixel value of the neighborhood; wherein, the preset pixel position range is determined based on the horizontal scaling ratio and the vertical scaling ratio; The scaling module is used to limit the interpolation weight range according to a preset sharpness adjustment parameter, and to perform linear interpolation on the mean value of the neighboring pixels to obtain the target pixels of the target image, so as to scale the initial image.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the image scaling method as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the image scaling method as described in any one of claims 1 to 7.