Image zooming method and device and storage medium
By interpolation based on position weight and texture weight during image scaling, the problem of failure to effectively consider the position and edge information of the pixel point to be inserted in the prior art is solved, and a higher quality image scaling effect is achieved.
Patent Information
- Application Number
- CN202510552435.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-05-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art fails to effectively consider the position and edge information of the pixel points to be inserted during image scaling, resulting in poor image quality after scaling.
By determining the mapping position of the target pixel in the target image in the source image based on the image scaling parameters, obtaining multiple target neighborhood pixels, and interpolation is performed based on the position weight and texture weight in the texture rich area, the interpolation weight is dynamically adjusted to preserve image details and texture.
Better preserve image details and texture during image scaling, and improve the image quality after scaling.
Smart Images

Figure CN120070166A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of image processing technology, and in particular, relates to an image scaling method, device and storage medium. Background Art
[0002] Image scaling technology is widely used in various consumer electronics, medical image processing, security monitoring and other fields. Its core goal is to retain the details, texture and visual quality of the original image as much as possible while changing the image size.
[0003] In the related art, interpolation algorithms such as linear interpolation are usually used to calculate new interpolation pixels based on the coordinates of pixels in the source image and the neighboring pixels, thereby achieving image size enlargement or reduction. However, interpolation algorithms usually use a unified interpolation kernel, without considering the position of the interpolated pixel points and the changes in edge information, resulting in poor image quality after scaling. Summary of the invention
[0004] The present application aims to solve at least one of the technical problems existing in the prior art. To this end, the present application proposes an image scaling method, device and storage medium to improve the quality of the scaled image.
[0005] In a first aspect, the present application provides an image scaling method, comprising: Determine, according to the image scaling parameter, a mapping position corresponding to a target pixel in the target image in the source image; the target image is the image after scaling, and the source image is the image before scaling; Acquire a plurality of target neighborhood pixels of the mapping position in the source image; When the mapping position is in a texture-rich area, interpolation is performed based on position weights and texture weights of a plurality of target neighborhood pixels to obtain a pixel value of the target pixel.
[0006] According to the image scaling method of the present application, the mapping position corresponding to the target pixel in the target image in the source image is determined according to the image scaling parameters; the target image is the image after scaling, and the source image is the image before scaling; a plurality of target neighborhood pixels of the mapping position in the source image are obtained; when the mapping position is in a texture-rich area, interpolation is performed based on the position weights and texture weights of the plurality of target neighborhood pixels to obtain the pixel value of the target pixel. The embodiment of the present application identifies the surrounding target neighborhood pixels according to the mapping position of the target pixel in the source image, interpolates the pixels in the texture-rich area in combination with the position weights and texture weights of the neighborhood pixels, and dynamically adjusts the interpolation weights taking into account the texture characteristics and relative positions of the neighborhood pixels, thereby better preserving image details and textures during image scaling and improving the quality of the scaled image.
[0007] According to an embodiment of the present application, the image scaling parameter includes a scaling ratio parameter or the resolution of the target image.
[0008] In this embodiment, the image scaling parameter is set by the scaling ratio parameter or the resolution of the target image, which improves the flexibility of setting the image scaling parameter.
[0009] According to an embodiment of the present application, the obtaining of a plurality of target neighborhood pixels at the mapping position in the source image includes: Calculating the neighborhood weight of the neighborhood pixels within the target neighborhood range of the mapping position; the neighborhood weight characterizes the influence degree of the neighborhood pixels on the mapping position; Determining the m neighborhood pixels with the largest neighborhood weight as the target neighborhood pixels.
[0010] In this embodiment, by dynamically selecting the neighborhood pixels that have the greatest influence on interpolation according to the neighborhood distribution of the mapping position, the interpolation process can be made closer to the true structure of the source image, so that the details and textures of the image can be retained during both image enlargement and reduction operations, improving the quality of the scaled image.
[0011] According to an embodiment of the present application, the method further includes: Determining local feature indicators corresponding to the plurality of target neighborhood pixels; the local feature indicators include indicators for evaluating local spatial differences or for evaluating whether the local area contains image edges; Judging whether the mapping position is in a texture-rich area according to the local feature indicators.
[0012] In this embodiment, the local feature indicators include indicators for evaluating local spatial differences or for evaluating whether the local area contains image edges, which can reflect the texture complexity and edge information of the local area of the image. By calculating the local feature indicators, it is possible to accurately identify whether the mapping position is in a texture-rich area.
[0013] According to an embodiment of the present application, the judging whether the mapping position is in a texture-rich area according to the local feature indicators includes: When the local feature indicators corresponding to at least the target number of target neighborhood pixels are greater than or equal to a target threshold, determining that the mapping position is in a texture-rich area.
[0014] In this embodiment, when the local feature indicators corresponding to at least the target number of target neighborhood pixels are greater than or equal to the target threshold, it indicates that the texture complexity of these neighborhood pixels is relatively high and the spatial difference is relatively large. Therefore, it can be determined that the mapping position is in a texture-rich area, improving the accuracy of identifying the texture-rich area.
[0015] According to an embodiment of the present application, interpolating based on the position weights and texture weights of a plurality of the target neighborhood pixels to obtain the pixel value of the target pixel includes: Selecting p target neighborhood pixels from the target neighborhood pixels whose local feature index is greater than or equal to a target threshold; Calculating the texture weights of the p target neighborhood pixels according to the local feature index; Determining the neighborhood weights of the p target neighborhood pixels as the position weights of the p target neighborhood pixels; Interpolating according to the position weights and texture weights of the p target neighborhood pixels to obtain the pixel value of the target pixel.
[0016] In this embodiment, by selecting p target neighborhood pixels from the target neighborhood pixels whose local feature index is greater than or equal to the target threshold, the pixels participating in the interpolation have sufficient texture complexity and spatial difference. Calculating the texture weights according to the local feature indexes of these selected target neighborhood pixels can dynamically adjust the weight distribution according to the texture features of the pixels, making the interpolation result closer to the texture details of the original image. Determining the neighborhood weights of these target neighborhood pixels as the position weights further combines the spatial distribution information of the pixels, making the interpolation process have a reference basis in space. This interpolation method of weight fusion can better retain the texture details and edge information of the image, reduce the blurring and distortion problems in traditional interpolation algorithms, and improve the quality of the scaled image.
[0017] According to an embodiment of the present application, the method further includes: When the mapping position is not in a texture-rich area, performing linear interpolation using a plurality of the target neighborhood pixels to obtain the pixel value of the target pixel.
[0018] In this embodiment, by performing linear interpolation using the target neighborhood pixels when the mapping position is not in a texture-rich area to calculate the pixel value of the target pixel, the high efficiency and stability of linear interpolation in a smooth area are fully utilized, which can quickly generate a relatively smooth image effect, reduce the redundant calculation of complex algorithms in a simple area, and improve the efficiency of image scaling.
[0019] In a second aspect, the present application provides an image scaling device, including: A determination module, configured to determine the mapping position corresponding to a target pixel in a target image in a source image according to image scaling parameters; the target image is the scaled image, and the source image is the image before scaling; An acquisition module, configured to acquire a plurality of target neighborhood pixels at the mapping position in the source image; An interpolation module, configured to perform interpolation based on the position weights and texture weights of a plurality of the target neighborhood pixels to obtain the pixel value of the target pixel when the mapping position is in a texture-rich area.
[0020] According to the image scaling device of the present application, the mapping position corresponding to a target pixel in a source image in a target image is determined according to image scaling parameters; the target image is a scaled image, and the source image is an image before scaling; a plurality of target neighborhood pixels at the mapping position in the source image are obtained; when the mapping position is in a texture-rich area, interpolation is performed based on the position weights and texture weights of the plurality of target neighborhood pixels to obtain the pixel value of the target pixel. In the embodiments of the present application, by identifying the surrounding target neighborhood pixels according to the mapping position of the target pixel in the source image, for the pixels in the texture-rich area, interpolation is performed by combining the position weights and texture weights of the neighborhood pixels, taking into account the texture characteristics and relative positions of the neighborhood pixels, and dynamically adjusting the interpolation weights, so as to better retain the image details and texture during the image scaling process and improve the quality of the scaled image.
[0021] In a third aspect, the present application provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where when the processor executes the computer program, the image scaling method described in the first aspect above is implemented.
[0022] In a fourth aspect, the present application provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the image scaling method described in the first aspect above is implemented.
[0023] In a fifth aspect, the present application provides a chip, which includes a processor and a communication interface, the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the image scaling method described in the first aspect above.
[0024] In a sixth aspect, the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, the image scaling method described in the first aspect above is implemented.
[0025] One or more of the above technical solutions in the embodiments of the present application have at least one of the following technical effects: According to the image scaling method of the present application, the mapping position corresponding to the target pixel in the target image in the source image is determined according to the image scaling parameter; the target image is the scaled image, and the source image is the image before scaling; a plurality of target neighborhood pixels at the mapping position in the source image are obtained; when the mapping position is in a texture-rich area, interpolation is performed based on the position weights and texture weights of the plurality of target neighborhood pixels to obtain the pixel value of the target pixel. In the embodiments of the present application, by identifying the surrounding target neighborhood pixels according to the mapping position of the target pixel in the source image, for the pixels in the texture-rich area, interpolation is performed by combining the position weights and texture weights of the neighborhood pixels, considering the texture characteristics and relative positions of the neighborhood pixels, and dynamically adjusting the interpolation weights, so as to better retain the image details and texture during the image scaling process and improve the quality of the scaled image.
[0026] Further, in some embodiments, the image scaling parameter is set by the scaling ratio parameter or the resolution of the target image, which improves the flexibility of setting the image scaling parameter.
[0027] Further, in some embodiments, by dynamically selecting the neighborhood pixels that have the greatest influence on the interpolation according to the neighborhood distribution of the mapping position, the interpolation process can be made closer to the true structure of the source image, so that the details and texture of the image can be retained during both the image enlargement and reduction operations, and the quality of the scaled image is improved.
[0028] Further, in some embodiments, the local feature index includes an index for evaluating the local spatial difference or evaluating whether the local area contains an image edge, which can reflect the texture complexity and edge information of the local area of the image. By calculating the local feature index, it can be accurately identified whether the mapping position is a texture-rich area.
[0029] Furthermore, in some embodiments, when the local feature indices corresponding to at least the target number of target neighborhood pixels are greater than or equal to the target threshold, it indicates that the texture complexity of these neighborhood pixels is relatively high and the spatial difference is relatively large. Therefore, it can be determined that the mapping position is in a texture-rich area, which improves the accuracy of identifying the texture-rich area.
[0030] Further, in some embodiments, by screening out p target neighborhood pixels from the target neighborhood pixels whose local feature indicators are greater than or equal to the target threshold, the pixels participating in interpolation have sufficient texture complexity and spatial diversity. Calculating the texture weights based on the local feature indicators of these screened target neighborhood pixels can dynamically adjust the weight distribution according to the texture features of the pixels, making the interpolation result closer to the texture details of the original image. Determining the neighborhood weights of these target neighborhood pixels as position weights further combines the spatial distribution information of the pixels, providing a spatial reference basis for the interpolation process. This interpolation method with weight fusion can better retain the texture details and edge information of the image, reduce the blurring and distortion problems in traditional interpolation algorithms, and improve the quality of the scaled image.
[0031] Furthermore, in some embodiments, when the mapping position is not in a texture-rich area, linear interpolation is performed using the target neighborhood pixels to calculate the pixel value of the target pixel. This fully utilizes the efficiency and stability of linear interpolation in smooth areas, can quickly generate a relatively smooth image effect, reduces the redundant calculation of complex algorithms in simple areas, and improves the efficiency of image scaling.
[0032] Additional aspects and advantages of the present application will be given in part in the following description, become apparent in part from the following description, or be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The above and / or additional aspects and advantages of the present application will become apparent and be readily understood in the description of the embodiments in conjunction with the following drawings, where: Figure 1 is a schematic flowchart of an image scaling method provided by an embodiment of the present application; Figure 2 is a schematic diagram of a scene example provided by an embodiment of the present application; Figure 3 is a schematic diagram of an interpolation process provided by an embodiment of the present application; Figure 4 is a schematic diagram of a weight fusion interpolation process provided by an embodiment of the present application; Figure 5 is a schematic structural diagram of an image scaling device provided by an embodiment of the present application; Figure 6 is a schematic structural diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0034] Next, the technical solutions in the embodiments of the present application will be clearly described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art belong to the scope of protection of the present application.
[0035] The terms "first", "second", etc. in the specification of the present application are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally of the same category, and do not limit the number of objects. For example, the first object can be one or multiple. In addition, "and / or" in the specification means at least one of the connected objects, and the character " / " generally indicates an "or" relationship between the associated objects before and after.
[0036] Next, in conjunction with the accompanying drawings, the image scaling method, device, and storage medium provided by the embodiments of the present application will be described in detail through specific embodiments and their application scenarios.
[0037] Among them, the image scaling method can be applied to a terminal, and can be specifically executed by hardware or software in the terminal.
[0038] The terminal includes, but is not limited to, portable communication devices such as mobile phones or tablets having a touch-sensitive surface (e.g., a touch screen display and / or a touchpad). It should also be understood that in some embodiments, the terminal may not be a portable communication device, but a desktop computer having a touch-sensitive surface (e.g., a touch screen display and / or a touchpad).
[0039] In the following various embodiments, a terminal including a display and a touch-sensitive surface is described. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, a mouse, and a joystick.
[0040] The image scaling method provided by the embodiments of the present application, the execution subject of the image scaling method can be an electronic device or a functional module or functional entity in the electronic device that can implement the image scaling method. The electronic devices mentioned in the embodiments of the present application include, but are not limited to, mobile phones, tablets, computers, cameras, and wearable devices, etc. Hereinafter, the image scaling method provided by the embodiments of the present application will be described by taking an electronic device as the execution subject as an example.
[0041] As Figure 1 shown, the image scaling method includes: step 110, step 120, and step 130.
[0042] Step 110: Determine the corresponding mapping position of the target pixel in the target image in the source image according to the image scaling parameter; the target image is the scaled image, and the source image is the image before scaling.
[0043] In the embodiment of the present application, the source image is the original image used before the image scaling operation. The size (width and height) of the source image is fixed, and the arrangement and color information of the pixel points in the source image determine the content of the image. The source image can be any type of image. For example, the source image can be a multi-channel image, such as a color image, or a single-channel image, such as a grayscale image, an infrared image, etc.
[0044] The target image is the image obtained after the scaling process. The size of the target image is different from that of the source image and can be an enlarged image or a reduced image. The number and arrangement of pixels in the target image will change according to the scaling operation. For example, if the source image is reduced by half, both the width and height of the target image will be half of the source image, and the number of pixels will also be reduced accordingly. The pixel values of the target image need to be calculated from the source image through a certain algorithm to ensure the quality and recognizability of the image after scaling.
[0045] The image scaling parameter is a parameter used to control the image scaling operation, and the image scaling parameter determines how the source image is converted into the target image. For example, the image scaling parameter can include a scaling ratio parameter, and the scaling ratio parameter represents the proportional relationship between the target image and the source image in terms of size. For example, if the scaling ratio is 0.5, it means that both the width and height of the target image are half of the source image; if the scaling ratio is 2, it means that both the width and height of the target image are twice that of the source image. The image scaling parameter can also include the resolution of the target image. After obtaining the resolution of the target image, the scaling ratio parameter can be calculated based on the resolution of the source image and the resolution of the target image, or the resolution of the target image can be calculated based on the scaling ratio parameter. In this embodiment, setting the image scaling parameter through the scaling ratio parameter or the resolution of the target image improves the flexibility of setting the image scaling parameter.
[0046] In the embodiment of the present application, the target pixel is a pixel point in the target image. During the image scaling process, the value of the target pixel needs to be calculated from the source image through a certain algorithm. The position of the target pixel is known in the target image, and the coordinates of the target pixel can be determined by the size and pixel arrangement of the target image. For example, in a target image with a resolution of 1024×768, the position of the target pixel can be represented by the row number and column number. For example, (512, 384) represents a pixel point located at the center of the image.
[0047] The mapping position is the coordinate position corresponding to the target pixel in the source image. Since the sizes of the target image and the source image are different, the position of the target pixel needs to be converted to the source image through certain calculations, and the converted coordinate position is the mapping position. The coordinates of the mapping position can be the position of a pixel point in the source image or a non-integer coordinate point in the source image. For example, the mapping position of the target pixel in the source image may be (102, 76), or may be (102.5, 76.8).
[0048] After determining the image scaling parameters, the mapping position corresponding to the target pixel in the target image in the source image can be determined according to the image scaling parameters. For example, the coordinates of the target pixel can be determined, such as , where represents the column number of the target pixel, represents the row number of the target pixel. Assuming that the scaling ratio is (the scaling ratios in the horizontal and vertical directions are the same), then the mapping coordinates of the target pixel in the source image can be calculated by the following formula:
[0049]
[0050] Step 120: Obtain a plurality of target neighborhood pixels at the mapping position in the source image.
[0051] In the embodiments of the present application, the target neighborhood pixels are multiple pixel points adjacent to the mapping position of the target pixel in the source image. The target neighborhood pixels are distributed around the mapping position, providing sufficient information for interpolation calculation and better retaining the detail and texture information of the image.
[0052] In some embodiments, a neighborhood range can be determined, such as a rectangular area with a size of 3×3, 5×5 or other ranges. Centered on the mapping position, the pixel points within the rectangular range are determined, and the pixel points within the rectangular range are determined as the target neighborhood pixels. For example, if a 3×3 neighborhood is selected, the range of the neighborhood pixels can be expressed as: to . Where represents the integer part of represents the integer part of
[0053] In some embodiments, the obtaining of a plurality of target neighborhood pixels at the mapping position in the source image includes: Calculate the neighborhood weights of the neighborhood pixels within the target neighborhood range of the mapped position; the neighborhood weights characterize the influence degree of the neighborhood pixels on the mapped position. Determine the m neighborhood pixels with the largest neighborhood weights as the target neighborhood pixels.
[0054] In this embodiment, the most representative pixel points can be selected as the target neighborhood pixels according to the influence degree of each neighborhood pixel on the mapped position, rather than simply selecting all neighborhood pixels within a fixed range.
[0055] Specifically, the target neighborhood range can be a rectangular area centered on the mapped position with a size of 3×3, 5×5 or other ranges. The neighborhood weights of each neighborhood pixel within the target neighborhood range of the mapped position can be calculated. The neighborhood pixels closer to the mapped position usually have a greater influence on the target pixel, and the neighborhood weights can be calculated according to the spatial distance between the mapped position and the pixels within the target neighborhood range. For example, the reciprocal of the Euclidean distance can be used to represent the neighborhood weight, and the reciprocal of the Euclidean distance between the mapped position and the pixels within the target neighborhood range can be calculated. The smaller the Euclidean distance, the greater the neighborhood weight.
[0056] In this embodiment, there can be n pixels within the target neighborhood range. After calculating the neighborhood weights of these n pixels respectively, the m neighborhood pixels with the largest neighborhood weights can be selected and determined as the target neighborhood pixels. Among them, m is less than n.
[0057] In this embodiment, by dynamically selecting the neighborhood pixels that have the greatest influence on the interpolation according to the neighborhood distribution of the mapped position, the interpolation process can be made closer to the true structure of the source image, so that the details and textures of the image can be retained during both image magnification and reduction operations, improving the quality of the scaled image.
[0058] Step 130: When the mapped position is in a texture-rich area, perform interpolation based on the position weights and texture weights of multiple target neighborhood pixels to obtain the pixel value of the target pixel.
[0059] In the embodiments of the present application, a texture-rich area refers to an area in an image that contains a large amount of details, edges, and complex structures. A texture-rich area has a high visual complexity and has high requirements for the quality and detail retention of the image.
[0060] In some embodiments, it can be determined whether it is in a texture-rich area by analyzing the pixel values around the mapped position. For example, the variance or gradient of the pixel values around the mapped position can be calculated. If the variance or gradient is large, it is considered to be in a texture-rich area.
[0061] In some embodiments, it can also be determined whether it is in a texture-rich area according to the following method: Determine the local feature indicators corresponding to multiple target neighborhood pixels; the local feature indicators include indicators for evaluating local spatial variability or for evaluating whether the local area contains an image edge; Judge whether the mapping position is in a texture-rich area according to the local feature indicators.
[0062] In this embodiment, analysis can be carried out with the help of local feature indicators. The local feature indicators include indicators for evaluating local spatial variability or for evaluating whether the local area contains an image edge. For example, the variance or standard deviation of pixel values can be used as an indicator for measuring local spatial variability. If the pixel values in a region change greatly, it indicates that the region may contain rich texture information. The gradient magnitude can be used as an indicator for evaluating whether the local area contains an image edge. A region with a large gradient magnitude indicates the presence of an obvious edge, that is, the region is a texture-rich area. The local feature indicators can help quantify the texture characteristics of the local area of the image, thus providing a basis for identifying whether it is a texture-rich area.
[0063] Taking the local feature indicator including the variance of pixel values as an example, the variance of pixel values in the z×z neighborhood of the target pixel can be calculated to obtain the local feature indicator corresponding to the target pixel.
[0064] After determining the local feature indicators of the target neighborhood pixels, it can be judged whether the mapping position is in a texture-rich area according to the local feature indicators. One or more thresholds can be set to evaluate the local feature indicators. For example, if the local spatial variability indicator (such as variance) exceeds a certain threshold, or the local gradient magnitude exceeds a certain threshold, it can be considered that the mapping position is in a texture-rich area.
[0065] In this embodiment, the local feature indicators include indicators for evaluating local spatial variability or for evaluating whether the local area contains an image edge, which can reflect the texture complexity and edge information of the local area of the image. By calculating the local feature indicators, it can be accurately identified whether the mapping position is a texture-rich area.
[0066] In some embodiments, the judging whether the mapping position is in a texture-rich area according to the local feature indicators includes: When the local feature indicators corresponding to at least the target number of target neighborhood pixels are greater than or equal to the target threshold, determine that the mapping position is in a texture-rich area.
[0067] In this embodiment, the local feature indicators corresponding to each target neighborhood pixel can be calculated respectively , where represents the local feature indicator corresponding to the th target neighborhood pixel, , represents the number of target neighborhood pixels.
[0068] When the local feature indicators corresponding to at least the target number of the target neighborhood pixels are greater than or equal to the target threshold, it is determined that the mapping position is in a texture-rich area. The target number can be 1, 2 or other values, which can be set according to actual needs. Taking the target number as 1 as an example, for the local feature indicators , if at least one local feature indicator is greater than or equal to the target threshold, it can be considered that the mapping position is in a texture-rich area. If the local feature indicators are all less than the target threshold, it can be considered that the mapping position is not in a texture-rich area.
[0069] In this embodiment, when the local feature indicators corresponding to at least the target number of the target neighborhood pixels are greater than or equal to the target threshold, it indicates that the texture complexity of these neighborhood pixels is relatively high and the spatial difference is relatively large. Therefore, it can be determined that the mapping position is in a texture-rich area, improving the accuracy of identifying the texture-rich area.
[0070] In an embodiment of the present application, when the mapping position is in a texture-rich area, interpolation can be performed based on the position weights and texture weights of a plurality of the target neighborhood pixels to obtain the pixel value of the target pixel.
[0071] In some embodiments, the position weight of the target neighborhood pixel can be determined according to the spatial distance between the target neighborhood pixel and the mapping position. For example, the position weight can be calculated by the reciprocal of the Euclidean distance or other distance measurement methods.
[0072] In some embodiments, the texture weight of the target neighborhood pixel is a weight determined according to the texture similarity between the target neighborhood pixel and the mapping position. For example, the texture similarity can be calculated by analyzing the texture patterns, directions and intensities around the target neighborhood pixel and the mapping position. The higher the texture similarity of the target neighborhood pixel, the greater the texture weight.
[0073] In some embodiments, considering the position weight and texture weight, a weighted average or weighted interpolation method can be used to calculate the pixel value of the target pixel.
[0074] In some embodiments, the interpolation based on the position weights and texture weights of a plurality of the target neighborhood pixels to obtain the pixel value of the target pixel includes: screening out p target neighborhood pixels with local feature indicators greater than or equal to the target threshold from the target neighborhood pixels; calculating the texture weights of the p target neighborhood pixels according to the local feature indicators; determining the neighborhood weights of the p target neighborhood pixels as the position weights of the p target neighborhood pixels; Interpolate according to the position weights and texture weights of the p target neighborhood pixels to obtain the pixel value of the target pixel.
[0075] In this embodiment, p target neighborhood pixels with local feature indicators greater than or equal to the target threshold can be screened out from the target neighborhood pixels, where p is less than or equal to the number of target neighborhood pixels.
[0076] In this embodiment, the texture weight reflects the importance of the target neighborhood pixels in terms of texture characteristics. For example, target neighborhood pixels with higher local feature indicators contribute more to the texture information of the target pixel, so higher texture weights can be assigned. Specifically, the calculation of the texture weight can be based on the relative magnitudes of the local feature indicators. For example, through normalization processing, the local feature indicators are converted into weight values such that the range of the weight values is between 0 and 1.
[0077] The position weight reflects the spatial distance relationship between the target neighborhood pixels and the mapped position of the target pixel. Generally, the closer the neighborhood pixel is to the mapped position of the target pixel, the greater the position weight. In this embodiment, the neighborhood weight of the target neighborhood pixel can be used as the position weight, thus simplifying the calculation process.
[0078] The value of the target pixel can be calculated by the following formula:
[0079] where represents the pixel value of the target pixel, represents the th position weight of the target neighborhood pixel, represents the th texture weight of the target neighborhood pixel, represents the th pixel value of the target neighborhood pixel, represents the number of target neighborhood pixels.
[0080] In this embodiment, by screening out p target neighborhood pixels with local feature indicators greater than or equal to the target threshold from the target neighborhood pixels, the pixels participating in the interpolation have sufficient texture complexity and spatial diversity. The texture weights are calculated based on the local feature indicators of these screened target neighborhood pixels, enabling dynamic adjustment of weight allocation according to the texture features of the pixels, making the interpolation result closer to the texture details of the original image. Determining the neighborhood weights of these target neighborhood pixels as position weights further combines the spatial distribution information of the pixels, providing a spatial reference basis for the interpolation process. This interpolation method with weight fusion can better retain the texture details and edge information of the image, reduce the blurring and distortion problems in traditional interpolation algorithms, and improve the quality of the scaled image.
[0081] In some embodiments, when the mapping position is not in a texture-rich area, multiple target neighborhood pixels are used for linear interpolation to obtain the pixel value of the target pixel.
[0082] In this embodiment, when the mapping position is not in a texture-rich area, a relatively simple and efficient interpolation method, namely linear interpolation, can be adopted. This method is applicable to areas with simple textures or relatively smooth areas, and can quickly calculate the value of the target pixel while maintaining the basic visual quality of the image.
[0083] Linear interpolation is an interpolation method based on a linear function, which assumes that pixel values change linearly within the neighborhood. Specifically, linear interpolation estimates the value of the target pixel by calculating the distance weights between the target pixel and the target neighborhood pixels. The distance weights are inversely proportional to the Euclidean distance between the pixels, that is, the closer the target neighborhood pixels are to the target pixel, the greater their influence on the target pixel. For example, the reciprocal of the Euclidean distance, that is, the neighborhood weight, can be used as the distance weight, or a Gaussian function can be used to calculate the weight to smooth the change of the weight.
[0084] The pixel value of the target pixel can be calculated by the following formula:
[0085] where, represents the pixel value of the target pixel, represents the pixel value of the th target neighborhood pixel, represents the distance weight of the th target neighborhood pixel, represents the number of target neighborhood pixels.
[0086] In this embodiment, by using the target neighborhood pixels for linear interpolation to calculate the pixel value of the target pixel when the mapping position is not in a texture-rich area, the efficiency and stability of linear interpolation in smooth areas are fully utilized, a relatively smooth image effect can be quickly generated, the redundant calculation of complex algorithms in simple areas is reduced, and the efficiency of image scaling is improved.
[0087] According to the image scaling method of the present application, the mapping position corresponding to the target pixel in the target image in the source image is determined according to the image scaling parameter; the target image is the scaled image, and the source image is the image before scaling; a plurality of target neighborhood pixels at the mapping position in the source image are obtained; when the mapping position is in a texture-rich area, interpolation is performed based on the position weights and texture weights of the plurality of target neighborhood pixels to obtain the pixel value of the target pixel. In the embodiment of the present application, by identifying the surrounding target neighborhood pixels according to the mapping position of the target pixel in the source image, for the pixels in the texture-rich area, interpolation is performed by combining the position weights and texture weights of the neighborhood pixels, considering the texture characteristics and relative positions of the neighborhood pixels, and dynamically adjusting the interpolation weights, so as to better retain the image details and texture during the image scaling process and improve the quality of the scaled image.
[0088] The following introduces the image scaling method of the embodiment of the present application through a scenario example. As Figure 2 shown, the scenario example includes the following steps.
[0089] Input: the resolution or scaling factor of the source image and the target image.
[0090] The input can be a reduction or magnification factor parameter or the target image resolution, and two different parameter setting methods are supported.
[0091] The magnification factor of the scaling factor can be any magnification. For example, the accuracy of the scaling factor parameter supports 2 decimal places, and the highest scaling factor parameter supports 8 times magnification.
[0092] Calculate the corresponding relationship between the pixel coordinates of the target image and the n source image pixel coordinates, and store the corresponding relationship.
[0093] According to the input target image resolution or scaling factor, calculate the corresponding position of each pixel in the target image in the source image, so as to obtain the corresponding relationship between the target image pixels and the source image pixels.
[0094] Store the corresponding relationship between the target image pixels and the source image pixels for quick access during the interpolation process.
[0095] Among them, the n source image pixels are the n pixels with the largest neighborhood weights within the neighborhood range corresponding to the mapping position of the target image pixel in the source image, and n is less than or equal to 16. Among them, the neighborhood weight is the reciprocal of the Euclidean distance between the mapping position and the pixels within the neighborhood range, and the smaller the Euclidean distance, the larger the neighborhood weight.
[0096] According to the amount of storage capacity, different storage methods can be selected. For example, if the storage capacity is large, the pixel coordinates of each target image can be stored along with the corresponding n source image pixel coordinates. If the storage capacity is small, only the correspondence between each target image pixel coordinate and the mapping position can be retained, and the other n - 1 source image pixel coordinates can be calculated when traversing the target image pixel coordinates. It is also possible to store only one row and one column of coordinates, with the coordinate length being the same as the rows and columns of the target image, and calculate the n source image pixel coordinates when traversing the target image pixel coordinates.
[0097] Traverse the target image pixel coordinates and extract m pixels mapped to the source image.
[0098] For each pixel in the target image, find the m pixels in the source image related to it according to the previously calculated correspondence, where m is less than or equal to n.
[0099] Analyze whether the mapping position is in a texture-rich area according to metric A.
[0100] The above local feature metric (metric A) can be used to evaluate whether each mapping position is in a texture-rich area. As Figure 3 shown, the local feature metric of m source image pixels in the neighborhood can be calculated , if the local feature metric are all less than the target threshold , it is considered that the mapping position is not in a texture-rich area, and the m pixels of the source image can be used for interpolation using a linear interpolation scheme. If at least one of the local feature metrics is greater than or equal to the target threshold , it is considered that the mapping position is in a texture-rich area, and p pixels greater than or equal to the target threshold can be selected, where p is less than or equal to m, and weight fusion interpolation is performed using the p pixels in the source image.
[0101] Specifically, the process of performing weight fusion interpolation using p pixels in the source image is as Figure 4 shown, the neighborhood weights of p pixels can be used as position weights, texture weights are assigned to the p pixels according to metric A, and weight fusion interpolation is performed according to the position weights and texture weights.
[0102] In the image scaling method provided by the embodiments of the present application, the execution subject can be an image scaling device. In the embodiments of the present application, taking the image scaling device executing the image scaling method as an example, the image scaling device provided by the embodiments of the present application is described.
[0103] The embodiments of the present application also provide an image scaling device.
[0104] As Figure 5 shown, the image scaling device includes: A determination module 510, configured to determine a corresponding mapping position in a source image of a target pixel in a target image according to an image scaling parameter; the target image is a scaled image, and the source image is an image before scaling; An acquisition module 520, configured to acquire a plurality of target neighborhood pixels at the mapping position in the source image; An interpolation module 530, configured to, when the mapping position is in a texture-rich area, perform interpolation based on the position weights and texture weights of the plurality of target neighborhood pixels to obtain a pixel value of the target pixel.
[0105] According to the image scaling device of the present application, by determining a corresponding mapping position in a source image of a target pixel in a target image according to an image scaling parameter; the target image is a scaled image, and the source image is an image before scaling; acquiring a plurality of target neighborhood pixels at the mapping position in the source image; when the mapping position is in a texture-rich area, performing interpolation based on the position weights and texture weights of the plurality of target neighborhood pixels to obtain a pixel value of the target pixel. In the embodiment of the present application, by identifying surrounding target neighborhood pixels according to the mapping position of the target pixel in the source image, for pixels in a texture-rich area, interpolation is performed by combining the position weights and texture weights of the neighborhood pixels, considering the texture characteristics and relative positions of the neighborhood pixels, and dynamically adjusting the interpolation weights, so as to better retain image details and textures during the image scaling process and improve the quality of the scaled image.
[0106] In some embodiments, the acquisition module 520 is further configured to: Calculate neighborhood weights of neighborhood pixels within a target neighborhood range of the mapping position; the neighborhood weights represent the influence degree of the neighborhood pixels on the mapping position; Determine the m neighborhood pixels with the largest neighborhood weights as the target neighborhood pixels.
[0107] In some embodiments, the interpolation module 530 is further configured to: Determine local feature indicators corresponding to the plurality of target neighborhood pixels; the local feature indicators include indicators for evaluating local spatial differences or evaluating whether the local area contains an image edge; Judge whether the mapping position is in a texture-rich area according to the local feature indicators.
[0108] In some embodiments, the interpolation module 530 is further configured to: When local feature indicators corresponding to at least a target number of the target neighborhood pixels are greater than or equal to a target threshold, determine that the mapping position is in a texture-rich area.
[0109] In some embodiments, the interpolation module 530 is further configured to: Select p target neighborhood pixels from the target neighborhood pixels whose local feature index is greater than or equal to the target threshold; Calculate the texture weights of p target neighborhood pixels according to the local feature index; Determine the neighborhood weights of p target neighborhood pixels as the position weights of p target neighborhood pixels; Interpolate according to the position weights and texture weights of p target neighborhood pixels to obtain the pixel value of the target pixel.
[0110] In some embodiments, the interpolation module 530 is further configured to: In the case that the mapped position is not in a texture-rich area, perform linear interpolation using multiple target neighborhood pixels to obtain the pixel value of the target pixel.
[0111] The image scaling device in the embodiments of the present application may be an electronic device or a component in an electronic device, such as an integrated circuit or a chip. The electronic device may be a terminal or other devices other than the terminal. Exemplarily, the electronic device may be a mobile phone, a tablet computer, a laptop computer, a handheld computer, a vehicle-mounted electronic device, a Mobile Internet Device (MID), an augmented reality (AR) / virtual reality (VR) device, a robot, a wearable device, an ultra-mobile personal computer (UMPC), a netbook or a personal digital assistant (PDA), etc., and may also be a server, a Network Attached Storage (NAS), a personal computer (PC), a television (TV), a teller machine or a self-service machine, etc. The embodiments of the present application do not make specific limitations.
[0112] The image scaling device in the embodiments of the present application may be a device with an operating system. The operating system may be the Microsoft (Windows) operating system, the Android operating system, the IOS operating system, or other possible operating systems. The embodiments of the present application do not make specific limitations.
[0113] In some embodiments, such as Figure 6As shown in the figure, an embodiment of the present application further provides an electronic device 600, including a processor 601, a memory 602, and a computer program stored on the memory 602 and executable on the processor 601. When the program is executed by the processor 601, it implements each process of the above-mentioned embodiment of the image scaling method and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0114] It should be noted that the electronic device in the embodiment of the present application includes the above-mentioned mobile electronic device and non-mobile electronic device.
[0115] An embodiment of the present application further provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements each process of the above-mentioned embodiment of the image scaling method and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0116] Among them, the processor is the processor in the electronic device in the above-mentioned embodiment. The readable storage medium includes computer-readable storage media, such as computer read-only memory ROM, random access memory RAM, magnetic disk or optical disc, etc.
[0117] An embodiment of the present application further provides a computer program product, including a computer program, which implements the above-mentioned image scaling method when executed by a processor.
[0118] Among them, the processor is the processor in the electronic device in the above-mentioned embodiment. The readable storage medium includes computer-readable storage media, such as computer read-only memory ROM, random access memory RAM, magnetic disk or optical disc, etc.
[0119] Another embodiment of the present application provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement each process of the above-mentioned embodiment of the image scaling method and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0120] It should be understood that the chip mentioned in the embodiment of the present application can also be called a system-on-chip, system chip, chip system or system-on-chip, etc.
[0121] It should be noted that in this document, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements not only includes those elements but also other elements not explicitly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the existence of additional identical elements in the process, method, article or device comprising such element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in a reverse order according to the functions involved. For example, the described methods may be performed in an order different from that described, and various steps may be added, omitted, or combined. Additionally, the features described with reference to certain examples may be combined in other examples.
[0122] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-described method of the embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art can be embodied in the form of a computer software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions for causing a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present application.
[0123] The embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Under the inspiration of the present application, those of ordinary skill in the art can also make many forms without departing from the purpose and scope of the present application, and all of them fall within the protection scope of the present application.
[0124] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples", etc. means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
Claims
1. An image scaling method, characterized in that: include: Determine the mapping position corresponding to the target pixel in the target image in the source image according to the image scaling parameter; The target image is the image after scaling, and the source image is the image before scaling; Acquire a plurality of target neighborhood pixels of the mapping position in the source image; When the mapping position is in a texture-rich area, interpolation is performed based on position weights and texture weights of a plurality of target neighborhood pixels to obtain a pixel value of the target pixel.
2. The method according to claim 1, characterized in that The image scaling parameter includes a scaling factor parameter or a resolution of the target image.
3. The method according to claim 1, characterized in that The step of obtaining a plurality of target neighborhood pixels of the mapping position in the source image comprises: Calculating neighborhood weights of neighborhood pixels within a target neighborhood range of the mapping position; the neighborhood weights represent the degree of influence of the neighborhood pixels on the mapping position; The m neighborhood pixels with the largest neighborhood weights are determined as target neighborhood pixels.
4. The method according to claim 1, characterized in that: The method further comprises: Determine a plurality of local feature indices corresponding to the target neighborhood pixels; the local feature indices include indices for evaluating local spatial differences or evaluating whether a local area contains an image edge; It is determined whether the mapping position is in a texture-rich area according to the local feature index.
5. The method according to claim 4, characterized in that The determining, according to the local feature index, whether the mapping position is in a texture-rich area includes: When the local feature indexes corresponding to at least a target number of the target neighborhood pixels are greater than or equal to a target threshold, it is determined that the mapping position is in a texture-rich area.
6. The method according to claim 4, characterized in that The interpolation based on the position weights and texture weights of the plurality of target neighborhood pixels to obtain the pixel value of the target pixel comprises: Filter out p target neighborhood pixels whose local feature index is greater than or equal to a target threshold from the target neighborhood pixels; Calculate the texture weights of p target neighborhood pixels according to the local feature index; Determine the neighborhood weights of the p target neighborhood pixels as the position weights of the p target neighborhood pixels; Interpolation is performed according to the position weights and texture weights of the p target neighborhood pixels to obtain a pixel value of the target pixel.
7. The method according to claim 1, characterized in that The method further comprises: When the mapping position is not in a texture-rich area, a plurality of the target neighborhood pixels are used to perform linear interpolation to obtain a pixel value of the target pixel.
8. An image scaling device, characterized in that: include: A determination module, used to determine a mapping position corresponding to a target pixel in a target image in a source image according to an image scaling parameter; The target image is the image after scaling, and the source image is the image before scaling; An acquisition module, used for acquiring a plurality of target neighborhood pixels of the mapping position in the source image; The interpolation module is used to interpolate based on the position weights and texture weights of multiple target neighborhood pixels to obtain the pixel value of the target pixel when the mapping position is in a texture-rich area.
9. An electronic 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 program, the method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Image zooming method based on Newton second-order interpolation
CN110349090A
Image processing method and device, storage medium and electronic equipment
CN113962856A
Image sharpness enhancement method, device, storage medium and electronic device
CN119784661A
Image interpolation methods and related image interpolation devices thereof
US20190096031A1
Image scaling method and apparatus thereof
US20230169624A1
Cited By
Image data amplification processing method and device, electronic equipment and storage medium
CN121616452A
Magnification processing method and device of image data, electronic equipment and storage medium
CN121616452B