Color image compression method and system for improving Web performance
Through adaptive edge detection and color sampling, quantization and error diffusion methods, the distortion and color reduction distortion problems of text areas in traditional image compression algorithms are solved, and efficient image compression effect is achieved.
Patent Information
- Application Number
- CN202510074979.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-17
- Publication Date
- 2025-05-27
AI Technical Summary
While improving the compression rate, traditional image compression algorithms often lead to distortion of text areas, color restoration distortion and edge blur, especially when dealing with complex images.
By taking into account the block statistical characteristics of the grayscale map of the color image to be processed for edge detection, color sampling is performed using different sampling densities and area type weights, a color list is generated, and error diffusion is performed based on the adaptive error diffusion coefficient to ensure the visual information fidelity and color reduction of the edge area.
It realizes the high compression rate and high visual quality of the image in a limited computing space, especially the clarity and color reduction of text and complex content areas, solving the distortion and blur problems present in traditional methods.
Smart Images

Figure CN120050435A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and particularly to a color image compression method and system for improving Web performance. Background Art
[0002] With the development of Web technology, the proportion of pictures displayed on Web interfaces is increasing, and the size of pictures seriously affects the performance of Web display. The primary contradiction in image compression is the balance between text clarity and compression ratio. Traditional compression algorithms often severely damage text clarity while increasing the compression ratio. Especially when processing text areas, there are often over-response problems, resulting in obvious distortion in the text areas of the compressed images. At the same time, traditional fixed palette techniques often lead to serious color reproduction distortion and edge blurring problems when processing complex images. Summary of the Invention
[0003] To overcome the problems of distortion in the text areas, color reproduction distortion, and edge blurring of the compressed images, the present invention provides a color image compression method and system for improving Web performance.
[0004] On the one hand, the present invention provides a color image compression method for improving Web performance, including:
[0005] Performing edge detection on the grayscale image corresponding to the color image to be processed in consideration of the block statistical characteristics of the grayscale image corresponding to the color image to be processed, and determining the edge area and non-edge area of the color image to be processed;
[0006] Performing color sampling on the edge area and the non-edge area respectively with different sampling densities to obtain the occurrence frequencies of each color in the color image to be processed and generate a color list of the color image to be processed;
[0007] Performing color quantization on each pixel of the color image to be processed based on the occurrence frequencies of each color in the color list and the regional type weights to obtain a quantized image;
[0008] Performing error diffusion on the quantized image based on an adaptive error diffusion coefficient to obtain a compressed image corresponding to the color image to be processed;
[0009] Wherein, the sampling density and regional type weight corresponding to the edge area are both greater than the corresponding amounts of the non-edge area, and the adaptive error diffusion coefficient is determined based on the regional type where the current pixel is located.
[0010] Optionally, the block statistical feature includes the standard deviation of the grayscale value of the block. Before performing edge detection on the grayscale image corresponding to the color image to be processed considering the block grayscale statistical features of the grayscale image corresponding to the color image to be processed, it includes:
[0011] Perform block division on the grayscale image corresponding to the color image to be processed;
[0012] For each divided block, determine the edge detection threshold of the block based on the standard deviation of the grayscale value of the block.
[0013] Optionally, when performing edge detection on the grayscale image corresponding to the color image to be processed considering the block statistical features of the grayscale image corresponding to the color image to be processed to determine the edge region and non-edge region of the color image to be processed, it includes:
[0014] Calculate the gradient intensity of each pixel point in the grayscale image corresponding to the color image to be processed based on the Sobel operator;
[0015] If the gradient intensity of the current pixel point is greater than or equal to the corresponding edge detection threshold, determine that the current pixel point belongs to the edge region;
[0016] If the gradient intensity of the current pixel point is less than the corresponding edge detection threshold, determine that the current pixel point belongs to the non-edge region;
[0017] Among them, the Sobel operator calculates the gradient intensity of each pixel point based on a 5×5 convolution kernel to increase edge detection in the diagonal direction.
[0018] Optionally, when performing color sampling on the edge region and the non-edge region at different sampling densities to obtain the occurrence frequencies of each color in the color image to be processed and generate the color list of the color image to be processed, it includes:
[0019] Perform color sampling on each pixel point in the edge region, and weight the corresponding sampled colors based on the region type weight corresponding to the edge region to obtain the sampled colors of the edge region;
[0020] Perform color sampling on the pixel points in the non-edge region using a checkerboard sampling method to obtain the sampled colors of the non-edge region;
[0021] Count the occurrence frequencies of each color in the sampled colors of the edge region and the sampled colors of the non-edge region, and sort them based on the occurrence frequencies of each color to form the color list of the color image to be processed.
[0022] Optionally, when performing color quantization on each pixel of the color image to be processed based on the occurrence frequencies of each color in the color list and the region type weight to obtain a quantized image, it includes:
[0023] Select multiple colors with the highest occurrence frequencies in the color list as the initial clustering centers;
[0024] Based on the multi-dimensional non-linear features and color occurrence frequencies of each pixel point in the to-be-processed color image, determine the distances between the colors of each pixel point in the to-be-processed color image and the current clustering centers, and reassign the clustering centers for each pixel point based on the distances and update the clustering centers;
[0025] Repeat the process of reassigning and updating the clustering centers until a termination condition is reached to obtain the quantized image;
[0026] Wherein, the termination condition includes that the moving distance between two adjacent clustering centers is less than a preset threshold.
[0027] Optionally, the to-be-processed color image is an image in RGBA format. Based on the multi-dimensional non-linear features and color occurrence frequencies of each pixel point in the to-be-processed color image, determining the distances between the colors of each pixel point in the to-be-processed color image and the current clustering centers includes:
[0028] Based on the lightness, chroma, and hue of each pixel point in the to-be-processed color image, perform weighted fusion on the color errors of each pixel point in each color channel of the to-be-processed color image to obtain the initial distances between each pixel point and the current clustering centers;
[0029] Based on the color occurrence frequency of each pixel point, correct the corresponding initial distance to obtain the distances between each pixel point and the current clustering centers;
[0030] Wherein, the color error is the square of the difference between the color components of each pixel point in each color channel and the color components of the current clustering centers in each color channel.
[0031] Optionally, the error diffusion of the quantized image based on the adaptive error diffusion coefficient to obtain a compressed image corresponding to the to-be-processed color image includes:
[0032] For each pixel point in the non-edge region, detect whether there are edge pixel points around the pixel point. If so, divide the pixel point into a texture region; use the region other than the texture region in the non-edge region as a smooth region;
[0033] Perform error diffusion on the edge region, texture region, and smooth region in the quantized image based on different diffusion intensities and the adaptive error diffusion coefficient;
[0034] Among them, the diffusion intensity of the edge region is less than that of the smooth region, and the diffusion intensity of the texture region is determined based on the texture complexity.
[0035] Optionally, the range corresponding to the error diffusion of each pixel point includes: the pixel points in the up, down, left, right directions and the diagonal directions that are the nearest neighbor and the second nearest neighbor to the current pixel point;
[0036] The adaptive error diffusion coefficient has an inverse correlation with the distance between the current pixel point and the corresponding diffusion point.
[0037] Optionally, both the color image to be processed and the corresponding compressed image are PNG format images.
[0038] On the other hand, the present invention also provides a color image compression system for improving Web performance, including:
[0039] An edge detection module, configured to perform edge detection on the grayscale image corresponding to the color image to be processed by considering the block statistical features of the grayscale image corresponding to the color image to be processed, and determine the edge region and the non-edge region of the color image to be processed;
[0040] A color sampling module, configured to perform color sampling on the edge region and the non-edge region respectively with different sampling densities, obtain the occurrence frequencies of each color in the color image to be processed, and generate a color list of the color image to be processed;
[0041] A color quantization module, configured to perform color quantization on each pixel of the color image to be processed based on the occurrence frequencies of each color in the color list and the region type weights, to obtain a quantized image;
[0042] An error diffusion module, configured to perform error diffusion on the quantized image based on the adaptive error diffusion coefficient, to obtain a compressed image corresponding to the color image to be processed;
[0043] Among them, the sampling density and the region type weight corresponding to the edge region are both greater than the corresponding amounts of the non-edge region, and the adaptive error diffusion coefficient is determined based on the region type where the current pixel point is located.
[0044] On the other hand, the present invention also provides an electronic device, including: at least one processor and a memory; the memory and the processor are connected by a bus;
[0045] The memory is configured to store one or more programs;
[0046] When the one or more programs are executed by the at least one processor, the color image compression method for improving Web performance described in any one of the above is implemented.
[0047] On the other hand, the present invention also provides a readable storage medium with an execution program stored thereon. When the execution program is executed, the color image compression method for improving Web performance described in any one of the above is implemented.
[0048] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0049] The present invention provides a color image compression method and system for improving Web performance. By considering the block statistical features of the grayscale image corresponding to the color image to be processed, edge detection is performed on the grayscale image corresponding to the color image to be processed, realizing adaptive edge extraction based on block statistical features and improving the edge detection accuracy of different detail blocks. By performing color sampling on the edge area and the non-edge area at different sampling densities respectively, the high fidelity of visual information in the edge area is ensured, and the clarity of text in the edge area is guaranteed.
[0050] By performing color quantization on each pixel of the color image to be processed based on the occurrence frequency of each color in the color list and the region type weight, and performing error diffusion on the quantized image based on an adaptive error diffusion coefficient, a dynamic color clustering process based on edge perception is realized. By taking edge information as an important reference factor for clustering weights, the color restoration degree of the edge area is guaranteed, and the optimal color allocation is achieved within a limited computing space, avoiding the problem of edge blurring. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 It is a schematic flowchart of a color image compression method for improving Web performance according to the present invention;
[0052] Figure 2 It is a schematic diagram of an error diffusion direction according to the present invention;
[0053] Figure 3 It is a schematic flowchart of a color image compression method for improving Web performance according to the present invention;
[0054] Figure 4 It is a schematic structural diagram of an electronic device according to the present invention. DETAILED DESCRIPTION OF THE INVENTION
[0055] The following further describes in detail the specific embodiments of the present invention with reference to the accompanying drawings.
[0056] Embodiment 1:
[0057] A color image compression method for improving Web performance provided by the present invention, as shown in Figure 1 shown, includes:
[0058] Step S110: Edge-detect the grayscale image corresponding to the color image to be processed in consideration of the block statistical features of the grayscale image, and determine the edge region and non-edge region of the color image to be processed;
[0059] Step S120: Perform color sampling on the edge region and the non-edge region respectively with different sampling densities to obtain the occurrence frequencies of each color in the color image to be processed and generate a color list of the color image to be processed;
[0060] Step S130: Quantize the pixels of the color image to be processed based on the occurrence frequencies of each color in the color list and the region type weights to obtain a quantized image;
[0061] Step S140: Perform error diffusion on the quantized image based on an adaptive error diffusion coefficient to obtain a compressed image corresponding to the color image to be processed;
[0062] Among them, the sampling density and region type weight corresponding to the edge region are both greater than the corresponding values of the non-edge region, and the adaptive error diffusion coefficient is determined based on the region type where the current pixel is located.
[0063] In this exemplary embodiment, before edge detection, the color image to be processed can be grayscale processed to obtain the corresponding grayscale image. The block statistical features refer to the block grayscale statistical features of the grayscale image corresponding to the color image to be processed. For example, the grayscale average value or standard deviation of any block of the grayscale image corresponding to the color image to be processed. The region type weight refers to different weights configured for different region types. For example, the region type weight of the edge region is 2, and the region type weight of the non-edge region is 1. The region types can include the edge region and the non-edge region, and the non-edge region can be further divided into a texture region, a smooth region, etc. Different sampling densities, region type weights, and adaptive error diffusion coefficients, etc., can be configured for different region types to achieve different compression processing for different region types. In terms of the edge perception mechanism of the present invention, accurate edge extraction is achieved through block statistical features; the high fidelity of key visual information is ensured through the adaptive sampling mechanism of the edge region, which is crucial for maintaining text clarity. In terms of intelligent palette generation, a breakthrough edge-aware color clustering system is realized. By using the edge information as an important reference factor for clustering weights, the system can achieve optimal color allocation within a limited space. This intelligent allocation mechanism ensures that key regions obtain more color resources, thus guaranteeing high visual restoration. In terms of error diffusion, the system realizes an unprecedented adaptive control mechanism. By analyzing image features in real time, the system can dynamically adjust the intensity and direction of error diffusion to ensure the final image compression effect.
[0064] Exemplarily, both the color image to be processed and the corresponding compressed image are PNG - format images. If the input image is a true - color image, it can be first converted to the RGBA format. Specifically, first, initialize the RGBA buffer. In the pre - processing stage of image compression, the system first converts the input 24 - bit true - color image (resolution 1024x768) to the 32 - bit RGBA color space. This conversion process is achieved by creating an RGBA buffer of the same size as the source image, where each pixel occupies 4 bytes (8 bits for R, G, B each, and 8 bits for the Alpha channel). For example, an image data with a pixel value of #87CEEB (sky blue) is mapped to RGBA(135, 206, 235, 255), where 255 represents completely opaque. This standardized color - space conversion ensures the accuracy and consistency of subsequent processing.
[0065] In some embodiments, before performing edge detection on the grayscale image corresponding to the color image to be processed by considering the block - grayscale statistical features of the grayscale image corresponding to the color image to be processed in step S110, it includes:
[0066] Perform block division on the grayscale image corresponding to the color image to be processed;
[0067] For each divided block, determine the edge - detection threshold of the block based on the standard deviation of the grayscale values of the block.
[0068] In this exemplary embodiment, perform block division on the grayscale image corresponding to the color image to be processed. For example, divide the grayscale image into 16×16 local blocks, calculate the average value and standard deviation of the grayscale values of each local block, and dynamically adjust the edge - detection threshold of the block based on this standard deviation. This method enables obtaining the best edge - detection effect in regions with different levels of detail. In this example, when determining the edge - detection threshold, the traditional fixed - threshold method is abandoned, and instead, an adaptive - threshold strategy based on the statistical features of the image is adopted.
[0069] In an exemplary embodiment, in step S110, performing edge detection on the grayscale image corresponding to the color image to be processed by considering the block statistical features of the grayscale image corresponding to the color image to be processed, and determining the edge region and non - edge region of the color image to be processed, includes:
[0070] Calculate the gradient intensity of each pixel point in the grayscale image corresponding to the color image to be processed based on the Sobel operator;
[0071] If the gradient intensity of the current pixel point is greater than or equal to the corresponding edge - detection threshold, determine that the current pixel point belongs to the edge region;
[0072] If the gradient intensity of the current pixel point is less than the corresponding edge - detection threshold, determine that the current pixel point belongs to the non - edge region;
[0073] Among them, the Sobel operator calculates the gradient intensity of each pixel point based on a 5×5 convolution kernel to enhance edge detection in the diagonal direction.
[0074] In this exemplary embodiment, first, the color picture is converted into a grayscale picture to generate the grayscale value of each pixel. Edge detection is achieved by traversing the corresponding grayscale picture of the color image to be processed. Specifically, for the pixel at the coordinate (x, y) in the RGBA buffer of the image, an improved Sobel operator is used for gradient calculation. The traditional Sobel operator uses a 3×3 convolution kernel, that is, a 3×3 matrix composed of [-1, 0, 1]; while the improved Sobel operator in this example uses a 5×5 convolution kernel, that is, a 5×5 matrix composed of [-2, -1, 0, 1, 2], so that more accurate edge information can be obtained. For each pixel point (x, y) in the image, the gradients in the horizontal and vertical directions are calculated respectively as follows:
[0075]
[0076] Among them, G x (x, y) is the gradient of the pixel point (x, y) in the horizontal direction, and G y (x, y) is the gradient of the pixel point (x, y) in the vertical direction, and W x (i, j), W y (i, j) are the weight matrices of the improved Sobel operator in the horizontal and vertical directions respectively, (i, j) is the element position of the weight matrix, and I(x + i, y + j) is the pixel value at the position (x + i, y + j) of the corresponding grayscale picture of the color image to be processed; finally, the gradient intensity G(x, y) of the pixel point (x, y) is:
[0077]
[0078] The edge detection threshold can be a preset value (such as 30) or dynamically adjusted based on the statistical features of the block. By comparing the gradient intensity of the current pixel with its edge detection threshold, when the gradient intensity is greater than or equal to the edge detection threshold, the pixel is marked as an edge point. By traversing each pixel of the grayscale image corresponding to the color image to be processed, all edge points are determined, and the area corresponding to the edge points is used as the edge area, and the remaining areas are non-edge areas. This step generates edge detection result data (isEdge), and the edge detection result of each pixel can be displayed by marking true or false. In this example, the accuracy of edge detection is improved through multi-level technology. First, in terms of the improvement of the Sobel operator, the traditional 3x3 matrix is extended to a 5x5 matrix, and the weight coefficient in the diagonal direction is increased, significantly improving the detection ability for 45-degree angle edges. At the same time, by introducing second-order derivative information (i.e., the change of the change rate of grayscale values) in edge calculation, the system can more accurately identify subtle grayscale changes. In the determination of the edge detection threshold, an adaptive threshold strategy based on the statistical features of the image is adopted to further improve the accuracy of edge detection.
[0079] In an exemplary embodiment, the step of performing color sampling on the edge region and the non-edge region at different sampling densities respectively to obtain the occurrence frequencies of each color in the color image to be processed and generate the color list of the color image to be processed includes:
[0080] Perform color sampling on each pixel in the edge region, and weight the sampled color corresponding to the region type weight corresponding to the edge region to obtain the sampled color of the edge region;
[0081] Use a checkerboard sampling method to perform color sampling on the pixels in the non-edge region to obtain the sampled color of the non-edge region;
[0082] Count the occurrence frequencies of each color in the sampled color of the edge region and the sampled color of the non-edge region, and sort based on the occurrence frequencies of each color to form the color list of the color image to be processed.
[0083] In the present exemplary embodiment, for each pixel color value in the RGBA image, an adaptive color sampling strategy is performed in combination with the isEdge array generated by the edge detection marker. Specifically, a full-pixel sampling strategy is adopted in the edge region, that is, the sampling density is 100%, and the color information of each sampling point in the edge region is given a weighting coefficient of 2.0. For example, the sampling weight of the pixel RGB(0, 0, 0) at the edge position (100, 100) is 2.0. In contrast, a checkerboard sampling pattern is adopted in the non-edge region, that is, the sampling density is 50%, and the color value in the non-edge region remains unchanged, that is, the weight is 1.0. For example, the weight of RGB(135, 206, 235) at the sampling point (200, 200) is 1.0. The occurrence frequency of each sampled color is counted to generate a color list of color values and corresponding occurrence frequencies, that is, the colorList color list is generated. Intelligent color sampling, dense sampling in the edge region and sparse sampling in the non-edge region, collect color frequency information, establish an initial color table, and prepare for subsequent color quantization. This adaptive sampling strategy significantly reduces the computational overhead while maintaining edge details.
[0084] In an exemplary embodiment, the color quantization of each pixel of the to-be-processed color image based on the occurrence frequencies of the colors in the color list and the region type weights in step S130 to obtain a quantized image includes:
[0085] Select multiple colors with the highest occurrence frequencies in the color list as the initial clustering centers;
[0086] Based on the multi-dimensional non-linear features and color occurrence frequencies of each pixel point in the to-be-processed color image, determine the distance between the color of each pixel point in the to-be-processed color image and the current clustering centers, and reassign the clustering centers for each pixel point based on the distance and update the clustering centers;
[0087] Repeat the process of reassigning and updating the clustering centers until a termination condition is reached to obtain the quantized image;
[0088] Wherein, the termination condition includes that the moving distance between adjacent clustering centers is less than a preset threshold.
[0089] In this exemplary embodiment, color quantization and palette generation are performed in this part. Specifically, K-means clustering is performed on colorList to quantize the image colors. The K colors with the highest occurrence frequencies are used as the initial clustering centers. Considering multi-dimensional non-linear features and color occurrence frequencies, the distances between the color values of each pixel point and each clustering center are calculated. The multi-dimensional non-linear features include non-linear characteristics in three dimensions: lightness, chroma, and hue; the color occurrence frequency is used to statistically calculate the frequency weight of each color. The calculation formula for the frequency weight of each color is: w = the number of colors in the cluster / the total number of colors. Colors with higher frequencies are more likely to be retained in the final palette. The higher the weight, the higher the possibility of being retained in the palette. Based on the calculated distances, the clustering centers of each pixel point are re-assigned and the clustering centers are updated; the process of re-assigning and updating the clustering centers is repeated until a termination condition is reached, such as the moving distance between adjacent clustering centers being less than a preset threshold, to obtain the quantized image. At this time, the colors corresponding to each clustering center are used as the palette. In some other examples, different quantization weights can also be configured for edge pixels and non-edge pixels. For example, the quantization weight of edge pixels is 2.0, and the quantization weight of non-edge pixels is 1.0. The above clustering process is iteratively optimized to generate an array of clusters color clusters, which includes the central color and the associated color set, and a palette palette is constructed therefrom. In this example, the first clustering center is selected as the color with the highest occurrence frequency in the image. During the selection process, the edge information weight and the weight corresponding to the color occurrence frequency are added to ensure that the colors in the edge region are fully represented and the color representativeness of the palette; during the iterative intelligent optimization process, by introducing an early stopping mechanism, when the moving distance of the clustering center is less than the preset threshold, the process is ended in advance to achieve an adaptive learning rate, and the update step size is gradually reduced as the number of iterations increases.
[0090] Exemplarily, the color image to be processed is an image in RGBA format. Based on the multi-dimensional non-linear features and color occurrence frequencies of each pixel point in the color image to be processed, determining the distances between the colors of each pixel point in the color image to be processed and the current clustering centers includes:
[0091] Based on the lightness, chroma, and hue of each pixel point in the color image to be processed, the color errors of each pixel point in each color channel in the color image to be processed are weighted and fused to obtain the initial distance between each pixel point and the current clustering centers;
[0092] Based on the color occurrence frequency of each pixel point, the corresponding initial distance is corrected to obtain the distance between each pixel point and the current clustering centers;
[0093] Wherein, the color error is the square of the difference between the color components of each pixel point in each color channel and the color components of the current clustering centers in each color channel.
[0094] In this exemplary embodiment, the RGB color space can be converted to the LAB space, and the distance between the color value of each pixel and the cluster center is calculated based on the improved CIEDE2000 color difference formula. A hue weight coefficient is introduced, and a higher weight is assigned to the yellow region. When calculating the color difference, the non-linear characteristics of the three dimensions of lightness, chroma, and hue are considered. The color distance calculation formula for each pixel is as follows:
[0095]
[0096] In the formula, E(x,y) represents the distance between the color of the pixel (x,y) and the cluster center, which is the calculated color difference (or color variation). It represents the difference between two colors. The larger the value, the more obvious the color difference. This formula is used to quantify the visual color difference in many color comparisons, significantly improving performance and practicality while maintaining reasonable perceptual accuracy, and is particularly suitable for image compression applications in the Web environment; R r 、G r 、B r 、A r are the values of the red (R), green (G), blue (B), and transparency (Alpha, A) components of the color corresponding to the cluster center, respectively, representing the four components of the cluster center color in the RGBA color space; R p 、G p 、B p 、A pThey are the values of the red (R), green (G), blue (B), and alpha (A) components of the current pixel, representing the four components of the current pixel in the RGBA color space respectively; w(x, y) is the frequency weight corresponding to the color occurrence frequency of the pixel point (x, y), and 0.299, 0.587, 0.114, and 0.1 are the weighting coefficients for each color component, reflecting the sensitivity of the human eye to different colors. The commonly used weighting coefficients are derived from the luminance perception model. 0.299 is used to indicate that the human eye is more sensitive to red (R), so a higher weight is assigned to the red component. 0.587 is used to indicate that green (G) has a great impact on visual perception, and a higher weight is assigned to it. 0.114 is used to indicate that blue (B) has a smaller impact on vision, so a lower weight is assigned. 0.1 is used to indicate that the weight of the alpha channel (A) is lower, which is mainly used to represent the transparency of the pixel, so a smaller weight is assigned. This formula calculates the color difference between the current pixel and the clustering center, and through weight weighting, makes the calculation of the color difference more in line with the visual perception of the human eye. This example takes into account the perceptual differences of the human eye in different hue regions and the color occurrence frequency, improving the color fidelity of the quantized image. In color clustering, the color list is quantized into a specified number of color clusters. A color cluster represents a set of similar colors, and a color cluster contains a center color and a color list belonging to this color cluster. The number of color clusters determines the image quality. The higher the number of color clusters, the better the image quality. When reconstructing the image, it is not necessary to retain all the colors, only the representative colors of each cluster need to be retained. In this way, all the colors in the original image are represented by fewer colors, thereby compressing the size of the PNG based on the PNG file format. A color palette is created based on the color clusters, and the original colors in the image are represented based on the color palette when reconstructing the image.
[0097] In one exemplary embodiment, the error diffusion of the quantized image based on the adaptive error diffusion coefficient in step S140 to obtain a compressed image corresponding to the to-be-processed color image includes:
[0098] For each pixel point in the non-edge region, detect whether there are edge pixel points around the pixel point. If so, divide the pixel point into a texture region; use the region in the non-edge region except the texture region as a smooth region;
[0099] Perform error diffusion on the edge region, texture region, and smooth region in the quantized image based on different diffusion intensities and the adaptive error diffusion coefficient;
[0100] Among them, the diffusion intensity of the edge region is less than that of the smooth region, and the diffusion intensity of the texture region is determined based on the texture complexity.
[0101] In the present exemplary embodiment, the non-edge regions are divided into texture regions and smooth regions based on the edge detection results, and the diffusion intensity is adaptively controlled for different region types, and the diffusion intensity is dynamically adjusted according to the local features of the image. Specifically, the diffusion intensity of the edge region is less than that of the smooth region, and the diffusion intensity of the texture region is between the edge region and the smooth region, and can be determined based on the texture complexity. For example, in the edge region, the diffusion intensity is reduced to 50% of the standard value to avoid edge blurring; in the smooth region, 100% diffusion intensity is maintained to ensure natural color transition; in the texture region, the diffusion intensity can be linearly adjusted according to the texture complexity. The adaptive error diffusion coefficient decreases as the distance between the current pixel point and the corresponding diffusion point increases, that is, the adaptive error diffusion coefficient has an inverse correlation with the distance between the current pixel point and the corresponding diffusion point. The error diffusion process can be as follows: according to the size of the original image, that is, the color image to be processed, a target image data space is created; each pixel point of the original image is traversed to obtain the color value pixel of the current pixel point in the error buffer errors, the closest color newPixel is found in the color palette, the error quantError of the four channels is calculated for newPixel and the original color, and then the error diffusion coefficient errorFactor is determined according to the result of edge detection isEdge. If it is an edge point, the error coefficient is 0.5, otherwise it is 1.0; the error of the current pixel point is diffused to its adjacent pixels. According to the quantization error quantError, the error diffusion coefficient errorFactor, and the pixel position (x, y) of the current original image, the error is diffused to the adjacent pixels. Exemplarily, the range of error diffusion corresponding to each pixel point includes: the pixels in the up, down, left, right directions and the diagonal directions that are the nearest neighbor and the next nearest neighbor of the current pixel point; for example, the direction distribution diagram of error diffusion is as shown in Figure 2 shown. Taking the current pixel point X0 as the origin, the horizontal direction as the X axis, and the vertical direction as the Y axis, D1, D2, D3, D4 are the error diffusion coefficients, and the positions where they are located form the error diffusion range of the current pixel point, and each position point is a diffusion point. For example, D1 = 9 / 256, D2 = 7 / 256, D3 = 5 / 256, D4 = 3 / 256. The diffusion error of the diffusion point can be calculated by the following formula:
[0102] E x+dx,y+dy = E(x,y)·w dx,dy ·f
[0103] In the formula, E x+dx,y+dy is the diffusion error at (x + dx, y + dy), E(x,y) is the quantization error of the pixel point (x,y), w dx,dyis the error diffusion coefficient at the (dx, dy) position in the error diffusion direction distribution map, and f is the edge factor (e.g., 0.5 at the edge and 1.0 at non-edge areas). Traverse each pixel point to complete error diffusion, and finally write the image data space to a.png file. In this example, the diffusion direction is optimized. Specifically, the 4 diffusion directions of the traditional Floyd-Steinberg algorithm are extended to a 16-direction diffusion mode, as Figure 2 shown. Taking the current pixel point to be diffused as the origin, the specific diffusion directions include four basic directions, and the corresponding diffusion point coordinates are: (1, 0), (-1, 0), (0, 1), (0, -1). The four diagonal directions correspond to the diffusion point coordinates: (1, 1), (-1, 1), (1, -1), (-1, -1). The four extended point directions correspond to the diffusion point coordinates: (2, 0), (-2, 0), (0, 2), (0, -2). The four far corner point directions correspond to the diffusion point coordinates: (2, 1), (-2, 1), (2, -1), (-2, -1). Each direction is equipped with an adaptive diffusion coefficient D1 to D4 to ensure uniform diffusion of errors.
[0104] Through the channel independent processing mechanism, the present invention calculates and diffuses errors for the four RGBA channels respectively. Specifically, different weight coefficients are used for the three RGB channels to reflect the sensitivity differences of the human eye to each color channel; an independent diffusion matrix is used for the Alpha channel to ensure the accurate retention of transparency information. Such multi-level improvements ensure that the system can retain the visual quality and detail information of the image to the greatest extent while maintaining a high compression ratio. The application error diffusion result reconstructs the image through a color palette to generate the final compressed image. In terms of error diffusion, the system implements an unprecedented adaptive control mechanism. By analyzing the image features in real time, the system can dynamically adjust the intensity and direction of error diffusion. In the edge area, the diffusion intensity is automatically reduced to avoid blurring of details; in the smooth area, the system maintains an appropriate diffusion intensity to ensure the smoothness of color transition. More importantly, the system realizes independent error calculation for the four RGBA channels, and this fine control ensures that there is no crosstalk between channels during the compression process.
[0105] Refer to Figure 3 , which is the specific implementation manner of the color image compression method for improving Web performance of the present invention. The specific process is as follows:
[0106] (1) Input the original image (the color image to be processed), and initialize the RGBA buffer to convert the original image to the RGBA color space.
[0107] (2) Perform edge detection on the image data in the RGBA buffer: Calculate the gradient intensity based on the improved Sobel operator to generate an edge map.
[0108] (3) Intelligent color sampling: dense sampling in edge areas, sparse sampling in non-edge areas, and color frequency statistics to generate a color list.
[0109] (4) Color quantization: The K-means clustering algorithm is used to cluster the colors of each pixel and generate a color palette.
[0110] (5) Error diffusion: Error diffusion processing and error buffer update are performed on edge areas and non-edge areas based on different diffusion intensities and error diffusion coefficients.
[0111] (6) Image reconstruction and output compressed image.
[0112] In the development of image compression technology, the industry has been facing severe technical bottlenecks, that is, high-quality compression effects often require huge computational costs. The contradiction between algorithm complexity and compression effect has always been a core problem that has plagued the industry. There are currently three major technical routes in the field of image compression, each of which has its own unique technical characteristics and application scenarios. Transform domain-based compression technologies, such as DCT transform (JPEG) and wavelet transform (JPEG2000), can effectively remove high-frequency components that are not sensitive to the human eye by converting images to the frequency domain for processing. However, this type of algorithm performs poorly when processing areas with dense high-frequency information. Palette-based compression technologies, including uniform quantization (GIF) and median split quantization, achieve compression by simplifying the color space, but often have difficulty in accurately restoring complex color transitions. Dithering technologies based on error diffusion, such as the Floyd-Steinberg algorithm and the Stucki algorithm, can improve visual effects to a certain extent, but often cause distortion when processing edge areas.
[0113] Based on an in-depth analysis of existing compression technology solutions, it is found that various solutions have defects. First of all, the transform-domain compression technology shows obvious deficiencies in dealing with high-frequency information. The fundamental reason is that there is an essential mismatch between the basic principle of the Fourier transform and the text edge features in the image. When performing DCT transformation on the image, the sharp features of the text edge will generate a large number of high-frequency components in the frequency domain. And during the quantization process, these high-frequency components are often over-compressed or discarded, ultimately resulting in obvious ringing effects and blurring in the reconstructed image. This kind of distortion not only affects the visual effect, but more seriously affects the readability of the text. The limitations of traditional palette technology cannot be ignored either. The global palette method adopts a unified color quantization strategy, completely ignoring the feature differences in different regions of the image. This simplistic processing method leads to two serious problems: one is local color distortion, because the global palette cannot specifically protect the subtle color changes in the local area; the other is the obvious stratification phenomenon in the color transition area, which is because the discrete colors in the palette cannot smoothly represent continuous color gradients. The root cause of these problems is that traditional methods do not consider the spatial correlation and local features of the image. As for the classic error diffusion technology, its main problem lies in its "blindness". Traditional algorithms such as Floyd-Steinberg adopt fixed diffusion coefficients and patterns when dealing with error diffusion, completely ignoring the structural features of the image. This mechanical processing method leads to excessive diffusion in the edge area, causing important edge details to be distorted or lost. Especially in high-contrast areas, this simple error diffusion often produces visible noise and artifacts, seriously affecting the image quality.
[0114] To address the above problems, the present invention successfully ensures the clarity of the text area while maintaining a high compression ratio through an intelligent edge detection and adaptive processing mechanism. Through an innovative adaptive palette generation algorithm, even with a limited palette capacity, excellent color restoration effects can be achieved, and a good balance between color restoration and palette size is achieved. Through multi-level algorithm optimization, the perfect unity of high efficiency and high quality is realized, and the balance between computational efficiency and compression quality is solved. This multi-level optimization strategy of the present invention has achieved a qualitative leap in the field of image compression, and is particularly suitable for processing images containing complex contents such as text and graphics. Through in-depth innovation at the algorithm level, a breakthrough improvement in compression quality and efficiency has been successfully achieved, opening up a new development direction for image compression technology.
[0115] Embodiment 2:
[0116] Based on the same inventive concept, the present invention also provides a color image compression system for improving Web performance, and the system includes:
[0117] An edge detection module, configured to perform edge detection on the grayscale image corresponding to the color image to be processed by considering the block statistical features of the grayscale image, and determine the edge region and non-edge region of the color image to be processed;
[0118] A color sampling module, configured to perform color sampling on the edge region and the non-edge region respectively with different sampling densities, obtain the occurrence frequencies of each color in the color image to be processed, and generate a color list of the color image to be processed;
[0119] A color quantization module, configured to perform color quantization on each pixel of the color image to be processed based on the occurrence frequencies of the colors in the color list and the region type weights, to obtain a quantized image;
[0120] An error diffusion module, configured to perform error diffusion on the quantized image based on an adaptive error diffusion coefficient, to obtain a compressed image corresponding to the color image to be processed;
[0121] Wherein, the sampling density and region type weight corresponding to the edge region are both greater than the corresponding amounts of the non-edge region, and the adaptive error diffusion coefficient is determined based on the region type where the current pixel is located.
[0122] In a possible implementation manner, the block statistical features include the standard deviation of the grayscale values of the blocks, and the edge detection module includes a threshold determination sub-module, and the threshold determination sub-module is configured to:
[0123] Perform block division on the grayscale image corresponding to the color image to be processed;
[0124] For each divided block, determine the edge detection threshold of the block based on the standard deviation of the grayscale values of the block.
[0125] In a possible implementation manner, the edge detection module further includes an edge detection sub-module, and the edge detection sub-module is configured to:
[0126] Calculate the gradient intensity of each pixel point in the grayscale image corresponding to the color image to be processed based on the Sobel operator;
[0127] If the gradient intensity of the current pixel point is greater than or equal to the corresponding edge detection threshold, determine that the current pixel point belongs to the edge region;
[0128] If the gradient intensity of the current pixel point is less than the corresponding edge detection threshold, determine that the current pixel point belongs to the non-edge region;
[0129] Wherein, the Sobel operator calculates the gradient intensity of each pixel point based on a 5×5 convolution kernel to enhance the edge detection in the diagonal direction.
[0130] In a possible implementation, the color sampling module includes:
[0131] An edge sampling sub-module, configured to perform color sampling on each pixel point in the edge region, and weight the corresponding sampled colors based on the region type weight corresponding to the edge region to obtain the sampled color of the edge region;
[0132] A non-edge sampling sub-module, configured to perform color sampling on the pixel points in the non-edge region by using a checkerboard sampling method to obtain the sampled color of the non-edge region;
[0133] A statistics sub-module, configured to count the occurrence frequency of each color in the sampled color of the edge region and the sampled color of the non-edge region, and sort based on the occurrence frequency of each color to form a color list of the to-be-processed color image.
[0134] In a possible implementation, the color quantization module includes:
[0135] A clustering center screening sub-module, configured to screen out multiple colors with the highest occurrence frequency in the color list as initial clustering centers;
[0136] A distance calculation sub-module, configured to determine the distance between the color of each pixel point in the to-be-processed color image and the current clustering centers based on the multi-dimensional non-linear features and color occurrence frequency of each pixel point in the to-be-processed color image, and reassign the clustering centers for each pixel point based on the distance and update the clustering centers;
[0137] An iteration sub-module, configured to repeat the process of reassigning and updating the clustering centers until a termination condition is reached to obtain the quantized image;
[0138] Wherein, the termination condition includes that the moving distance between adjacent clustering centers is less than a preset threshold.
[0139] In a possible implementation, the to-be-processed color image is an image in RGBA format, and the distance calculation sub-module is specifically configured to:
[0140] Perform weighted fusion on the color errors of each pixel point in each color channel of the to-be-processed color image based on the lightness, chroma, and hue of each pixel point in the to-be-processed color image to obtain an initial distance between each pixel point and the current clustering centers;
[0141] Correct the corresponding initial distance based on the color occurrence frequency of each pixel point to obtain the distance between each pixel point and the current clustering centers;
[0142] Wherein, the color error is the square of the difference between the color components of each pixel point in each color channel and the color components of the current cluster centers in each color channel.
[0143] In a possible implementation manner, the error diffusion module is specifically configured to:
[0144] For each pixel point in the non-edge region, detect whether there are edge pixel points around the pixel point. If so, divide the pixel point into a texture region; use the region in the non-edge region except the texture region as a smooth region;
[0145] Perform error diffusion on the edge region, texture region, and smooth region in the quantization image based on different diffusion intensities and an adaptive error diffusion coefficient;
[0146] Wherein, the diffusion intensity of the edge region is less than that of the smooth region, and the diffusion intensity of the texture region is determined based on the texture complexity.
[0147] In a possible implementation manner, the range of error diffusion corresponding to each pixel point includes: the pixel points in the up, down, left, right directions and diagonal directions that are the nearest neighbor and the next nearest neighbor to the current pixel point;
[0148] The adaptive error diffusion coefficient has an inverse correlation with the distance between the current pixel point and the corresponding diffusion point.
[0149] In a possible implementation manner, both the to-be-processed color image and the corresponding compressed image are PNG format images.
[0150] Embodiment 3
[0151] As Figure 4 shown, the present invention further provides an electronic device, which may be a computer device, a single-chip microcomputer device, a smart mobile device, etc. The electronic device in this embodiment may include a processor, a memory, a transceiver component, etc. The memory, the processor, and the transceiver component are connected through a bus; the memory can be used to store an execution program, and an exemplary execution program may include instructions; the processor is used to execute the instructions stored in the memory. The memory can also be used to store data, and the data can be called and / or modified when the instructions are executed.
[0152] The processor may be a Central Processing Unit (CPU), or may also 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. It is the computing core and control core of the terminal, and is suitable for implementing one or more instructions. Specifically, it is suitable for loading and executing one or more instructions in the storage medium to implement the corresponding method flow or corresponding function, so as to implement the steps of a color image compression method for improving Web performance in the above embodiments.
[0153] Embodiment 4
[0154] Based on the same inventive concept, the present invention also provides a readable storage medium, specifically an electronic device-readable storage medium (Memory). The electronic device-readable storage medium is a memory device in the electronic device, used to store programs and data. It can be understood that the storage medium here can include both the built-in storage medium in the electronic device and, of course, the extended storage medium supported by the electronic device. The storage medium provides a storage space, and this storage space stores the operating system of the terminal. And, one or more instructions suitable for being loaded and executed by the processor are also stored in this storage space. These instructions can be one or more executable programs (including program codes). It should be noted that the storage medium here can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory. By the processor loading and executing one or more instructions stored in the storage medium, the steps of a color image compression method for improving Web performance in the above embodiments can be implemented.
[0155] Those skilled in the art should understand that the embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program codes.
[0156] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and combinations of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing devices to produce a machine, such that the instructions executed by the processors of the computer or other programmable data processing devices produce means for implementing the functions specified in the flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or means for implementing the functions specified in multiple blocks.
[0157] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufactured article including instruction means that implement the functions specified in the flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or means for implementing the functions specified in multiple blocks.
[0158] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in the flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or means for implementing the functions specified in multiple blocks.
[0159] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit its protection scope. Although the present invention has been described in detail with reference to the above embodiments, those of ordinary skill in the art should understand that after reading the present invention, various changes, modifications, or equivalent replacements can still be made to the specific implementation manners of the application. However, these changes, modifications, or equivalent replacements are all within the protection scope of the claims pending for approval of the application.
Claims
1. A color image compression method for improving Web performance, characterized in that: include: Considering the block statistical characteristics of the grayscale image corresponding to the color image to be processed, edge detection is performed on the grayscale image corresponding to the color image to be processed to determine the edge area and non-edge area of the color image to be processed; Performing color sampling on the edge area and the non-edge area at different sampling densities, respectively, to obtain the occurrence frequency of each color in the color image to be processed and generate a color list of the color image to be processed; Performing color quantization on each pixel of the color image to be processed based on the occurrence frequency of each color in the color list and the area type weight to obtain a quantized image; Performing error diffusion on the quantized image based on an adaptive error diffusion coefficient to obtain a compressed image corresponding to the color image to be processed; The sampling density and the area type weight corresponding to the edge area are greater than those of the non-edge area, and the adaptive error diffusion coefficient is determined based on the area type where the current pixel point is located.
2. The method according to claim 1, characterized in that The block statistical feature includes a gray value standard deviation of the block. Before edge detection is performed on the gray image corresponding to the color image to be processed by considering the block gray statistical feature of the gray image corresponding to the color image to be processed, the method includes: Dividing the grayscale image corresponding to the color image to be processed into blocks; For each divided block, an edge detection threshold of the block is determined based on a standard deviation of the grayscale value of the block.
3. The method according to claim 2, characterized in that The step of performing edge detection on the grayscale image corresponding to the color image to be processed by considering the block statistical features of the grayscale image corresponding to the color image to be processed, and determining the edge area and non-edge area of the color image to be processed includes: Calculate the gradient intensity of each pixel in the grayscale image corresponding to the color image to be processed based on the Sobel operator; If the gradient intensity of the current pixel is greater than or equal to the corresponding edge detection threshold, it is determined that the current pixel belongs to the edge area; If the gradient intensity of the current pixel is less than the corresponding edge detection threshold, it is determined that the current pixel belongs to the non-edge area; The Sobel operator calculates the gradient strength of each pixel based on a 5×5 convolution kernel to increase edge detection in the diagonal direction.
4. The method according to claim 1, characterized in that The color sampling of the edge area and the non-edge area at different sampling densities is performed to obtain the occurrence frequency of each color in the color image to be processed and generate a color list of the color image to be processed, including: Performing color sampling on each pixel in the edge area, and weighting the corresponding sampled colors based on the area type weight corresponding to the edge area, to obtain the sampled colors of the edge area; Performing color sampling on pixel points in the non-edge area by adopting a chessboard sampling method to obtain a sampled color of the non-edge area; The occurrence frequency of each color in the sampled colors of the edge area and the sampled colors of the non-edge area is counted, and the colors are sorted based on the occurrence frequency of each color to form a color list of the color image to be processed.
5. The method according to claim 4, characterized in that The step of performing color quantization on each pixel of the color image to be processed based on the occurrence frequency of each color in the color list and the area type weight to obtain a quantized image includes: Filter out multiple colors with the highest frequency of occurrence in the color list as initial cluster centers; Based on the multi-dimensional nonlinear characteristics and color occurrence frequency of each pixel in the color image to be processed, determine the distance between the color of each pixel in the color image to be processed and the current cluster centers, and redistribute the cluster centers of each pixel based on the distance and update the cluster centers; Repeating the process of reallocating and updating the cluster centers until a termination condition is reached to obtain the quantized image; The termination condition includes that the moving distance between two adjacent cluster centers is less than a preset threshold.
6. The method according to claim 5, characterized in that The color image to be processed is an image in RGBA format, and based on the multi-dimensional nonlinear characteristics and color occurrence frequency of each pixel in the color image to be processed, determining the distance between the color of each pixel in the color image to be processed and each current cluster center includes: Based on the brightness, chromaticity and hue of each pixel in the color image to be processed, weighted fusion is performed on the color error of each pixel in the color image to be processed in each color channel to obtain the initial distance between each pixel and each current cluster center; Based on the color frequency of each pixel, the corresponding initial distance is corrected to obtain the distance between each pixel and the current cluster center; The color error is the square of the difference between the color component of each pixel in each color channel and the color component of each current cluster center in each color channel.
7. The method according to claim 1, characterized in that The step of performing error diffusion on the quantized image based on an adaptive error diffusion coefficient to obtain a compressed image corresponding to the color image to be processed includes: For each pixel point in the non-edge area, detect whether there are edge pixels around the pixel point, and if so, divide the pixel point into a texture area; and regard the area in the non-edge area except the texture area as a smooth area; Performing error diffusion on edge areas, texture areas and smooth areas in the quantized image based on different diffusion intensities and adaptive error diffusion coefficients; The diffusion intensity of the edge area is smaller than that of the smooth area, and the diffusion intensity of the texture area is determined based on texture complexity.
8. The method according to claim 7, characterized in that The error diffusion range corresponding to each pixel point includes: the pixels in the upper, lower, left, right and diagonal directions of the nearest and next nearest neighbors of the current pixel point; The adaptive error diffusion coefficient is inversely correlated with the distance between the current pixel point and the corresponding diffusion point.
9. The method according to any one of claims 1 to 8, characterized in that: The color image to be processed and the corresponding compressed image are both images in PNG format.
10. A color image compression system for improving Web performance, characterized in that: include: An edge detection module is used to perform edge detection on the grayscale image corresponding to the color image to be processed by considering the block statistical characteristics of the grayscale image corresponding to the color image to be processed, and determine the edge area and non-edge area of the color image to be processed; A color sampling module, used for performing color sampling on the edge area and the non-edge area at different sampling densities, obtaining the occurrence frequency of each color in the color image to be processed and generating a color list of the color image to be processed; A color quantization module, used for performing color quantization on each pixel of the color image to be processed based on the occurrence frequency of each color in the color list and the area type weight to obtain a quantized image; An error diffusion module, used for performing error diffusion on the quantized image based on an adaptive error diffusion coefficient to obtain a compressed image corresponding to the color image to be processed; The sampling density and the area type weight corresponding to the edge area are greater than those of the non-edge area, and the adaptive error diffusion coefficient is determined based on the area type where the current pixel point is located.
Citation Information
Cited By
High-resolution remote sensing image transmission method and system applied to mineral resource exploration
CN121056637A
Image edge real-time processing method and system for surface exposure photocuring 3D printing
CN121767680A