Methods, apparatus, electronic devices and computer-readable storage media for image optimization
By assigning weight values based on pixel differences during image downsampling to adjust image details, the problem of jagged or blurry image edges is solved, thus improving image quality.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WUHAN TCL CORP RES CO LTD
- Filing Date
- 2020-10-12
- Publication Date
- 2026-06-30
AI Technical Summary
Existing image downsampling methods result in jagged or blurred image edges, affecting image quality.
By determining the weight value of each pixel in the image, weights are assigned based on the differences in pixel values, and image details are adjusted in combination with the weight values to optimize downsampling processing and retain more details.
It improves the jagged or blurry edges of downsampled images, enhancing image quality to match human visual perception.
Smart Images

Figure CN114331858B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a method, apparatus, electronic device, and computer-readable storage medium for image optimization. Background Technology
[0002] With the continuous improvement of camera equipment, image resolution is getting higher and higher. Along with the increase in image resolution, there is often a need to downsample images in some application scenarios. For example, in image storage, in order to save storage space, it is generally necessary to downsample the original image before storing it.
[0003] Currently, image downsampling is commonly performed using methods such as nearest neighbor interpolation, bilinear interpolation, and bicubic interpolation. However, while these methods are fast and easy to use, the edges of the downsampled image often appear jagged or blurred, leading to a decrease in the final image quality. Summary of the Invention
[0004] This application provides an image optimization method, apparatus, electronic device, and computer-readable storage medium, which can solve the problem that downsampling processing can easily result in jagged or blurry edges in the image, leading to a decrease in the quality of the final image.
[0005] Firstly, an image optimization method is provided, including:
[0006] The first image to be processed is downsampled to obtain the second image;
[0007] Based on the pixel differences between the first image and the second image, determine the weight value corresponding to each pixel in the first image;
[0008] The target image corresponding to the second image is determined based on the pixel values of each pixel in the first image and the weight values corresponding to each pixel in the first image.
[0009] As an example, the weight value corresponding to a pixel is positively correlated with the pixel value of that pixel. That is, for pixels with large differences in pixel value, the larger the weight value, the greater the contribution of the pixel value determined by that weight value. This allows more detail areas to be preserved. After downsampling, further detail preservation processing is performed, which can improve the problem of jagged or blurry edges caused by downsampling. This makes the obtained target image more in line with the subjective perception of human vision.
[0010] Secondly, an image optimization apparatus is provided, comprising:
[0011] The downsampling processing module is used to downsample the first image to be processed, so as to obtain the second image.
[0012] The first determining module is used to determine the weight value corresponding to each pixel in the first image based on the pixel difference between the first image and the second image.
[0013] The second determining module is used to determine the target image corresponding to the second image based on the pixel values of each pixel in the first image and the weight values corresponding to each pixel in the first image.
[0014] Thirdly, an electronic device is provided, comprising 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 optimization method of the first aspect.
[0015] Fourthly, a computer-readable storage medium is provided, on which instructions are stored, which, when executed by a processor, implement the steps of the image optimization method described above.
[0016] Fifthly, a computer program product containing instructions is provided, which, when run on a computer, causes the computer to perform the steps of the image optimization method described in the first aspect.
[0017] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here.
[0018] The beneficial effects of the technical solutions provided in this application are:
[0019] The first image is downsampled to obtain the second image. To improve the jagged or blurry edges caused by downsampling, a weight value is determined for each pixel in the first image based on the pixel differences between the two images. The weight value is positively correlated with the pixel value. Then, based on the pixel values of the first image and the determined weight values, a target image corresponding to the downsampled second image is determined. Thus, for pixels with large pixel value differences, a larger weight value results in a greater contribution from the pixel value determined by that weight, allowing more detail to be preserved. Further detail preservation processing after downsampling improves the jagged or blurry edges caused by downsampling, resulting in a target image that better matches human visual perception. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a flowchart illustrating an image optimization method according to an exemplary embodiment;
[0022] Figure 2 This is a schematic diagram of an image according to an exemplary embodiment;
[0023] Figure 3 This is a schematic diagram of an image according to another exemplary embodiment;
[0024] Figure 4 This is a schematic diagram illustrating the structure of an image optimization apparatus according to an exemplary embodiment;
[0025] Figure 5 This is a set of comparison images illustrating an exemplary embodiment;
[0026] Figure 6 This is a schematic diagram of the structure of an electronic device according to another exemplary embodiment. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0028] It should be understood that "multiple" as mentioned in this application refers to two or more. In the description of this application, unless otherwise stated, " / " indicates "or," for example, A / B can mean A or B; "and / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, to facilitate a clear description of the technical solutions of this application, the terms "first," "second," etc., are used to distinguish identical or similar items with essentially the same function and effect. Those skilled in the art will understand that the terms "first," "second," etc., do not limit the quantity or execution order, and that "first," "second," etc., do not necessarily imply differences.
[0029] Before providing a detailed description of the image optimization method provided in the embodiments of this application, a brief introduction will be given to the execution subject and application scenarios involved in the embodiments of this application.
[0030] First, a brief introduction will be given to the execution subject involved in the embodiments of this application.
[0031] The image optimization method provided in this application embodiment can be executed by an electronic device. As an example, the electronic device can be a mobile phone, laptop, tablet, desktop computer, portable computer, etc. This application embodiment does not limit this.
[0032] Next, we will briefly introduce the application scenarios involved in the embodiments of this application.
[0033] The image optimization method provided in this application can be used in application scenarios such as image storage, image transmission, and image compression. For example, in the application scenario of image transmission, in order to reduce the bandwidth required for transmission, the method provided in this application can be used to process the image before transmission. This allows the image size to be reduced while improving the jagged or blurry edges caused by downsampling, thereby improving the quality of the final image.
[0034] In addition, during the process of image recognition through network models, some network models include downsampling layers. In some embodiments, the method provided in this application can also be applied to the downsampling layer of the network model, that is, the downsampling layer of the network model can use this method for image processing.
[0035] After introducing the execution subject and application scenarios involved in the embodiments of this application, the image optimization method provided by the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0036] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating an image optimization method according to an exemplary embodiment. The method can be executed by the aforementioned electronic device and may include some or all of the following:
[0037] Step 101: Downsample the first image to be processed to obtain the second image.
[0038] The first image to be processed can be acquired through a data acquisition process or obtained from another device. In some embodiments, the first image to be processed can be understood as the original image.
[0039] As an example, the electronic device can downsample the first image using a filter, such as a box filter. The electronic device can then downsample the first image to a specified size using this filter to obtain the second image. In some embodiments, the second image may also be referred to as a downsampled image.
[0040] The specified dimensions can be set by the user according to actual needs, or they can be set by the default of the electronic device. This application embodiment does not limit this.
[0041] Furthermore, downsampling the first image to be processed to obtain the second image may specifically include:
[0042] The first image to be processed is downsampled to obtain a downsampled image;
[0043] The downsampled image is smoothed to obtain a smoothed image, which is the second image.
[0044] In other words, in the process of obtaining the second image from the first image, downsampling can be performed first, followed by smoothing, to obtain the second image.
[0045] In one embodiment, the electronic device can smooth the downsampled image using a Gaussian filter. It's easy to understand that smoothing can suppress noise; for example, it can make some bright pixels appear smoother.
[0046] In one embodiment, the first image can be denoted as I, and the pixels in the first image can be denoted as I(i,j). Further, the second image can be denoted as... The pixels in the second image can be denoted as...
[0047] Step 102: Determine the weight value corresponding to each pixel in the first image based on the pixel difference between the first image and the second image.
[0048] In this embodiment, the weight value corresponding to each pixel in the first image can be determined based on the pixel difference between the pixel values in the first image and the pixel values in the second image. In one embodiment, its specific implementation may include the following sub-steps 1021-1022:
[0049] 1021: In the first image, determine the local region corresponding to each pixel in the second image. Each local region includes a target number of pixels, where the target number is the size ratio of the first image to the second image.
[0050] For example, assuming the size of the first image is 1024*1024 and the size of the second image is 256*256, then the target value is 4.
[0051] It should be understood that the local regions corresponding to each pixel in the second image are usually related to downsampling. For example, please refer to... Figure 2 Assuming the target value is 4, the first local region in the first image corresponds to the first pixel in the second image. The first local region in the first image includes pixels I(0,0), I(0,1), I(1,0), and I(1,1). The second local region in the first image corresponds to the second pixel in the second image. The second local region in the first image includes pixels I(0,2), I(0,3), I(1,2), and I(1,3), and so on. Thus, the local region corresponding to each pixel in the second image can be determined in the first image.
[0052] 1022: Determine the weight value corresponding to the first pixel based on the pixel value of the first pixel and the second pixel value. The first pixel is any pixel in the first image, and the second pixel value is the pixel value of the pixel in the second image that corresponds to the local area where the first pixel is located.
[0053] The weight value corresponding to a pixel is positively correlated with the pixel value of that pixel.
[0054] Pixel value is a value assigned by a computer when the original image is digitized. It represents the average brightness information of a small square in the original image, or the average reflectance (transmission) density information of that small square.
[0055] For example, assuming the first pixel in the first image is pixel I(0,0), it is easy to understand that in the second image, the pixel corresponding to the local region where the first pixel is located is pixel I(0,0). The electronic device can determine the pixel value of the first pixel point I(0,0) and the pixel point The pixel value is used to determine the weight value corresponding to the first pixel I(0,0).
[0056] For example, assuming the first pixel in the first image is pixel I(1,0), it is easy to understand that in the second image, the pixel corresponding to the local region where the first pixel is located is pixel I(1,0). The electronic device can determine the pixel value of the first pixel point I(1,0) and the pixel point The pixel value is used to determine the weight value corresponding to the first pixel point I(1,0).
[0057] For example, assuming the first pixel in the first image is pixel I(0,2), it is easy to understand that in the second image, the pixel corresponding to the local region where the first pixel is located is pixel I(0,2). The electronic device can determine the pixel value of the first pixel point I(0,2) and the pixel point The pixel values are used to determine the weight value corresponding to the first pixel point I(0,2).
[0058] In one embodiment, the specific implementation of determining the weight value corresponding to the first pixel based on the pixel value of the first pixel and the second pixel value may include:
[0059] Determine the maximum pixel value in the first image;
[0060] The pixel value of the first pixel, the maximum pixel value, and the second pixel value are input into formula (1) for calculation to obtain the weight value corresponding to the first pixel.
[0061] Formula (1) is:
[0062]
[0063] ω(i,j) represents the weight value corresponding to the first pixel, and I(i,j) represents the pixel value of the first pixel. This represents the second pixel value, max(I) represents the maximum pixel value, and λ is a specified parameter value. Additionally, ||||2 represents the modulo operation.
[0064] For example, for pixel I(0,0) in the first image, the weight value corresponding to pixel I(0,0) For pixel I(0,1) in the first image, the weight value corresponding to pixel I(0,1) For pixel I(1,0) in the first image, the weight value corresponding to pixel I(1,0) is For pixel I(1,1) in the first image, the weight value corresponding to pixel I(1,1) is
[0065] It is easy to understand that for the edge details of the first image, the richer the color, the greater the difference in pixel value. As can be seen from the above formula (1), the pixel with the greater difference in pixel value has a larger weight value. Thus, the contribution of the pixel value determined according to the weight value is also greater, so that more edge details can be preserved.
[0066] In addition, it is worth mentioning that since the noise in the first image is usually quite different from the surrounding area, a specified parameter value is introduced here to avoid the noise being over-amplified. In one embodiment, the specified parameter value ranges from [0.5,1], which can minimize the enhancement of noise while preserving the edge details of the first image.
[0067] In the application, the specified parameter value can be set by the user according to actual needs, or it can be set by default by the electronic device. For example, the specified parameter value can be 0.5. This application embodiment does not limit this.
[0068] Of course, the specific implementation of determining the weight value corresponding to the first pixel based on the pixel value of the first pixel and the second pixel value described above is merely exemplary. In another embodiment, the electronic device may also determine the weight value corresponding to the first pixel using other methods based on the pixel value of the first pixel and the second pixel value. For example, the electronic device may also not be certain about the maximum pixel value in the first image and may directly use the formula... The weight value corresponding to the first pixel is determined. Alternatively, the electronic device may not introduce a specified parameter value, and this application embodiment does not limit this.
[0069] It is easy to understand that, in the above manner, the electronic device can determine the weight value corresponding to each pixel in the first image.
[0070] Step 103: Determine the target image corresponding to the second image based on the pixel values of each pixel in the first image and the weight values corresponding to each pixel in the first image.
[0071] After determining the weight values of each pixel in the first image, the electronic device can determine a target image of the same size as the second image based on the pixel values and weight values of each pixel in the first image. As mentioned earlier, since pixels with greater differences in pixel values have larger weight values, the contribution of the pixel value determined by that weight value is also greater, thus allowing more detail areas to be preserved. Therefore, after downsampling, the areas with varying pixel values are also considered for further detail preservation processing, making the resulting target image more consistent with human visual perception.
[0072] In one embodiment, determining the target image corresponding to the second image based on the pixel values of each pixel in the first image and the weight values corresponding to each pixel in the first image may include the following sub-steps 1031-1032:
[0073] 1031: Based on each pixel in each local region and the weight value corresponding to each pixel in each local region, determine the third pixel corresponding to each local region, and obtain multiple third pixels.
[0074] As mentioned above, the local regions corresponding to each pixel in the second image can be determined in the first image, resulting in multiple local regions. Since each local region in these multiple local regions corresponds to a pixel in the second image, it can also be understood that the electronic device determines the third pixel corresponding to each pixel in the second image based on each pixel in each local region in the multiple local regions and the weight value corresponding to each pixel in each local region.
[0075] In one embodiment, determining the third pixel corresponding to each local region based on each pixel within each local region and the weight value corresponding to each pixel within each local region may include:
[0076] Determine the sum of the weight values corresponding to each pixel within the first local region, where the first local region is any one of multiple local regions;
[0077] The sum of the weight values corresponding to each pixel in the first local region, the pixel value of each pixel in the first local region, and the weight values corresponding to each pixel in the first local region are input and calculated using the following formula (2) to obtain the third pixel corresponding to the first local region.
[0078] Formula (2) is:
[0079]
[0080] O(s,k) represents the third pixel corresponding to the first local region, and N p Let I(s,k) represent the sum of the weight values of each pixel in the first local region, and let ω(s,k) represent any pixel in the first local region.
[0081] As an example, the sum of the weight values corresponding to each pixel in the first local region mentioned above can be determined by the following formula (3):
[0082]
[0083] Among them, Ω I (P) can be understood as the set of pixels included in the first local region of the first image.
[0084] For example, the first local region includes pixels I(0,0), I(0,1), I(1,0), and I(1,1). Following the steps described above, the weight value corresponding to pixel I(0,0) is determined to be ω(0,0), the weight value corresponding to pixel I(0,1) is ω(0,1), the weight value corresponding to pixel I(1,0) is ω(1,0), and the weight value corresponding to pixel I(1,1) is ω(1,1). Therefore, the sum of the weight values corresponding to each pixel within the first local region, N1, can be determined as N1 = ω(0,0) + ω(0,1) + ω(1,0) + ω(1,1). Then, the third pixel corresponding to the first local region can be determined using the above formula (2).
[0085] According to the above implementation method, the third pixel point corresponding to each local region in multiple local regions can be determined, thereby obtaining multiple third pixel points.
[0086] 1032: A target image corresponding to the second image is constructed based on multiple third pixels, and the target image has the same size as the second image.
[0087] As mentioned earlier, since these multiple local regions correspond to the local regions of each pixel in the second image, determining the third pixel corresponding to each of these multiple local regions is equivalent to determining the third pixel corresponding to each pixel in the second image. The electronic device determines the image formed by these third pixels as the final target image. For example, the target image is as follows: Figure 3 Image O in the image.
[0088] Further, please refer to Figure 4 ,Should Figure 4 Image (a) is the image without detail preservation processing. Figure 4 (b) is the image after detail preservation processing. As can be seen from the comparison, the image obtained by the method provided in the embodiments of this application has higher quality.
[0089] In this embodiment, a second image is obtained by downsampling the first image to be processed. To improve the jagged or blurry edges caused by downsampling, a weight value is determined for each pixel in the first image based on the pixel difference between the first and second images. The weight value is positively correlated with the pixel value. Then, a target image corresponding to the downsampled second image is determined based on the pixel values of the first image and the determined weight values. Thus, for pixels with large pixel value differences, a larger weight value results in a greater contribution from the pixel value determined by that weight, allowing more detail to be preserved. Further detail preservation processing after downsampling improves the jagged or blurry edges caused by downsampling, resulting in a target image that better matches human visual perception.
[0090] 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 this application.
[0091] Figure 5 This is a schematic diagram illustrating the structure of an image optimization apparatus according to an exemplary embodiment. The image optimization apparatus can be implemented by software, hardware, or a combination of both. The image optimization apparatus may include:
[0092] The downsampling processing module 510 is used to downsample the first image to be processed to obtain the second image;
[0093] The first determining module 520 is used to determine the weight value corresponding to each pixel in the first image based on the pixel difference between the first image and the second image.
[0094] The second determining module 530 is used to determine the target image corresponding to the second image based on the pixel values of each pixel in the first image and the weight values corresponding to each pixel in the first image.
[0095] In one embodiment of this application, in determining the weight values corresponding to each pixel in the first image based on the pixel differences between the first image and the second image, the first determining module 520 is specifically used for:
[0096] In the first image, the local region corresponding to each pixel in the second image is determined. Each local region includes a target number of pixels, and the target number is the size ratio of the first image to the second image.
[0097] The weight value corresponding to the first pixel is determined based on the pixel value of the first pixel and the second pixel value. The first pixel is any pixel in the first image, and the second pixel value is the pixel value of the pixel in the second image that corresponds to the local area where the first pixel is located.
[0098] Among them, the weight value corresponding to a pixel is positively correlated with the pixel value.
[0099] In one embodiment of this application, in determining the weight value corresponding to the first pixel based on the pixel value of the first pixel and the second pixel value, the first determining module 520 is specifically used for:
[0100] Determine the maximum pixel value in the first image;
[0101] The pixel value of the first pixel, the maximum pixel value, and the second pixel value are input into formula (1) for calculation to obtain the weight value corresponding to the first pixel.
[0102] Formula (1) is:
[0103]
[0104] ω(i,j) represents the weight value corresponding to the first pixel, and I(i,j) represents the pixel value of the first pixel. The value represents the second pixel value, max(I) represents the maximum pixel value, and λ is a specified parameter value.
[0105] In one embodiment of this application, in determining the target image corresponding to the second image based on the pixel values of each pixel in the first image and the weight values corresponding to each pixel in the first image, the second determining module 530 is specifically used for:
[0106] Based on each pixel in each local region and the weight value corresponding to each pixel in each local region, the third pixel corresponding to each local region is determined, resulting in multiple third pixel points;
[0107] A target image corresponding to the second image is constructed based on multiple third pixels, and the target image has the same size as the second image.
[0108] In one embodiment of this application, in determining the third pixel corresponding to each local region based on each pixel within each local region and the weight value corresponding to each pixel within each local region, the second determining module 530 is specifically used for:
[0109] Determine the sum of the weight values corresponding to each pixel within the first local region, where the first local region is any one of multiple local regions;
[0110] The sum of the weight values of each pixel in the first local region, the pixel value of each pixel in the first local region, and the weight values of each pixel in the first local region are input into formula (2) for calculation to obtain the third pixel corresponding to the first local region.
[0111] Formula (2) is:
[0112]
[0113] O(s,k) represents the third pixel corresponding to the first local region, and N p Let I(s,k) represent the sum of the weight values of each pixel in the first local region, and let ω(s,k) represent any pixel in the first local region.
[0114] In one embodiment of this application, regarding downsampling the first image to be processed to obtain the second image, the downsampling processing module 510 is specifically used for:
[0115] The first image to be processed is downsampled to obtain a downsampled image;
[0116] The downsampled image is smoothed to obtain a smoothed image, which is the second image.
[0117] In this embodiment, a second image is obtained by downsampling the first image to be processed. To improve the jagged or blurry edges caused by downsampling, a weight value is determined for each pixel in the first image based on the pixel difference between the first and second images. The weight value is positively correlated with the pixel value. Then, a target image corresponding to the downsampled second image is determined based on the pixel values of the first image and the determined weight values. Thus, for pixels with large pixel value differences, a larger weight value results in a greater contribution from the pixel value determined by that weight, allowing more detail to be preserved. Further detail preservation processing after downsampling improves the jagged or blurry edges caused by downsampling, resulting in a target image that better matches human visual perception.
[0118] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0119] 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 merely 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. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0120] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 6 As shown, the electronic device 6 of this embodiment includes: at least one processor 60 ( Figure 6 (Only one is shown in the image) , memory 61 and computer program 62 stored in memory 61 and executable on at least one processor 60, processor 60 executing computer program 62 to implement the steps in any of the above-described image optimization method embodiments.
[0121] Electronic device 6 can be a computing device such as a desktop computer, laptop, handheld computer, or cloud server. This electronic device may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art will understand that... Figure 6 This is merely an example of electronic device 6 and does not constitute a limitation on electronic device 6. It may include more or fewer components than shown, or combine certain components, or different components, such as input / output devices, network access devices, etc.
[0122] The processor 60 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0123] In some embodiments, memory 61 may be an internal storage unit of electronic device 6, such as a hard disk or memory of electronic device 6. In other embodiments, memory 61 may be an external storage device of electronic device 6, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., provided on electronic device 6. Furthermore, memory 61 may include both internal and external storage units of electronic device 6. Memory 61 is used to store operating system, application programs, bootloader, data, and other programs, such as program code of computer programs. Memory 61 may also be used to temporarily store data that has been output or will be output.
[0124] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application 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 this application, and should all be included within the protection scope of this application.
Claims
1. A method of image optimization, characterized by, include: The first image to be processed is downsampled to obtain the second image; In the first image, a local region corresponding to each pixel in the second image is determined. Each local region includes a target number of pixels, where the target number is the size ratio of the first image to the second image. The weight value corresponding to the first pixel is determined based on the difference between the pixel values of the first pixel and the second pixel. The first pixel is any pixel in the first image, and the second pixel is the pixel value of the pixel in the second image that corresponds to the local region where the first pixel is located. The weight value corresponding to the pixel is positively correlated with the difference between the pixel values of the first pixel and the second pixel. Based on the pixel values of each pixel in the first image and the weight values corresponding to each pixel in the first image, a target image corresponding to the second image is determined, wherein the target image has the same size as the second image.
2. The method of claim 1, wherein, Determining the weight value corresponding to the first pixel based on the pixel value of the first pixel and the second pixel value includes: Determine the maximum pixel value in the first image; The pixel value of the first pixel, the maximum pixel value, and the second pixel value are input into formula (1) for calculation to obtain the weight value corresponding to the first pixel. Wherein, formula (1) is: The This represents the weight value corresponding to the first pixel. This represents the pixel value of the first pixel. This represents the second pixel value, the Represents the maximum pixel value, the Specify the parameter value.
3. The method as described in claim 2, characterized in that, Determining the target image corresponding to the second image based on the pixel values of each pixel in the first image and the weight values corresponding to each pixel in the first image includes: Based on each pixel in each local region and the weight value corresponding to each pixel in each local region, the third pixel corresponding to each local region is determined, resulting in multiple third pixel points; The target image corresponding to the second image is constructed based on the plurality of third pixels.
4. The method as described in claim 3, characterized in that, The step of determining the third pixel point corresponding to each local region based on each pixel point within each local region and the weight value corresponding to each pixel point within each local region includes: Determine the sum of the weight values corresponding to each pixel within the first local region, where the first local region is any one of multiple local regions; The sum of the weight values corresponding to each pixel in the first local area, the pixel value of each pixel in the first local area, and the weight value corresponding to each pixel in the first local area are input into formula (2) for calculation to obtain the third pixel corresponding to the first local area. Formula (2) is as follows: The This represents the third pixel point corresponding to the first local region. This represents the sum of the weight values corresponding to each pixel within the first local region. This represents any pixel within the first local region. This represents the weight value corresponding to any pixel within the first local region.
5. The method according to any one of claims 1-4, characterized in that, The process of downsampling the first image to be processed to obtain the second image includes: The first image to be processed is downsampled to obtain a downsampled image; The downsampled image is smoothed to obtain a smoothed image, which is the second image.
6. An image optimization apparatus, characterized in that, include: The downsampling processing module is used to downsample the first image to be processed, so as to obtain the second image. A first determining module is configured to: determine, in the first image, a local region corresponding to each pixel in the second image, wherein each local region includes a target number of pixels, the target number being the size ratio of the first image to the second image; determine a weight value corresponding to the first pixel based on the pixel value difference between the first pixel value and the second pixel value, wherein the first pixel value is any pixel in the first image, and the second pixel value is the pixel value of the pixel in the second image corresponding to the local region where the first pixel value is located; wherein the weight value corresponding to the pixel value is positively correlated with the pixel value difference corresponding to the pixel value; The second determining module is used to determine a target image corresponding to the second image based on the pixel values of each pixel in the first image and the weight values corresponding to each pixel in the first image, wherein the target image has the same size as the second image.
7. An electronic device, characterized in that, The electronic device includes 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 method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed by a processor, implement the steps of the method as described in any one of claims 1 to 5.