An intelligent image compression method
By constructing an image evaluation function, combining edge detection and color gradient entropy, and optimizing the number of color types, the problem of image detail loss caused by color quantization in existing technologies is solved, and efficient image compression and detail retention are achieved.
Patent Information
- Application Number
- CN202411552496.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-01
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2044-11-01
AI Technical Summary
In existing image compression technologies, color quantization methods are based on global image differences, which leads to inappropriate selection of color types, affects image texture and edge information, and affects visual quality and information integrity.
By constructing an image evaluation function, combining edge detection and color gradient entropy, determining the local edge gradient loss, optimizing the number of color types, and using K-Means clustering and Kirsch operator template convolution to accurately measure edge visibility, the image contour visibility map and edge gradient loss map were constructed to achieve image detail preservation and compression.
It improves image compression efficiency, retains important structural information in the image, avoids the loss of detail information, and is suitable for Internet and ultra-high-definition image applications.
Smart Images

Figure CN119383342B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of image color quantization processing, and in particular to an image intelligent compression method. Background Art
[0002] Digital images, as one of the most important ways of transmitting information, are frequently used in people's daily lives. However, due to the limitations of device storage space, images often need to be compressed to facilitate image storage.
[0003] In image compression technology, one of the most prominent methods is color quantization technology. Color mapping the colors of pixels in an image to reduce the number of color types in the image is an image compression method that is very easy to implement. Reducing the number of color types means that less color information needs to be stored, thereby reducing the size of the image file. However, existing methods all measure color types based on global image differences, resulting in inappropriate color types in the image, thereby causing the loss of some texture and edge information in the image. This loss will affect the visual quality of the image and the integrity of the information content. Therefore, when color mapping the colors in the image, if the number of color types is not selected appropriately, the important features in the original image will no longer be prominent, affecting the image's communication effect. Summary of the Invention
[0004] In order to solve the above technical problems, the present application provides an image intelligent compression method to solve the existing problems.
[0005] The present invention provides an intelligent image compression method using the following technical solutions:
[0006] An embodiment of the present application provides an image intelligent compression method, which includes the following steps:
[0007] Obtain the original image to be compressed and its grayscale image;
[0008] Based on the distribution of pixels in the original image and its grayscale image, an image evaluation function is constructed; specifically:
[0009] S1, performing edge detection on the grayscale image to obtain edge points, and determining the contour visibility of each edge point according to the grayscale distribution of the surrounding pixels to obtain an image contour visibility map;
[0010] S2, divide the pixels in the original image into K categories according to their color values; obtain the main color value of each category of pixels, and replace the color value of the pixels in its category according to the main color value to obtain a color mapping image of the original image;
[0011] Based on the difference in the distribution of the positions of the edge points and the distribution difference in the color gradient entropy between the window where any edge point after edge detection of the original image is located and the window where the corresponding position after edge detection of the color mapping image is located, the local edge gradient loss degree of the any edge point is determined to obtain an image edge gradient loss map;
[0012] S3, constructing an image evaluation function using the image edge gradient loss map and the image contour appearance map;
[0013] The number of color categories when the original image is divided into pixel categories is obtained based on the image evaluation function, and then the color of the original image is quantized.
[0014] Preferably, in step S1, the method for determining the contour visibility is further defined as: according to the gradient direction of the edge point, a Kirsch operator template corresponding to the direction closest to the edge point is selected to perform convolution on the edge point.
[0015] Preferably, the division range of the pixel point category number K is further limited as follows: the difference between the main color number and the preset color range value is used as the lower limit value of K, and the sum of the main color number and the preset color range value is used as the upper limit value of K.
[0016] Preferably, the method for obtaining the number of main colors is further defined as:
[0017] Reshape the original image to obtain the pixel values of all pixels;
[0018] Clustering is performed on the results of sampling the pixel values of all pixels;
[0019] The number of clusters after clustering is taken as the number of main colors of the original image.
[0020] Preferably, the main color value is further obtained by the average level of the product of all color values in each type of pixel and their corresponding occurrence frequencies.
[0021] Preferably, the calculation method of the color gradient entropy is further determined as follows:
[0022] For each edge point, calculate the distance between the color values of a preset number of adjacent pixels;
[0023] All distances are quantified according to preset intervals;
[0024] The information entropy of all quantized values is used as the color gradient entropy of each edge point.
[0025] Preferably, the local edge gradient loss is determined by a result of forward fusion of a distribution difference of edge point positions and a distribution difference of color gradient entropy.
[0026] Preferably, the method for obtaining the image edge gradient loss map is: assigning a value of 0 to the local edge gradient loss of the original image that is not an edge point after edge detection; and constructing an image edge gradient loss map according to the local edge gradient loss of all pixel points according to their coordinate positions in the original image.
[0027] Preferably, the method for constructing the image evaluation function is:
[0028] Multiply the values of the corresponding positions of the image edge gradient loss map and the image contour appearance map to obtain the image feature loss evaluation map;
[0029] The image evaluation function is constructed using the average level of all element values in the image feature loss evaluation graph.
[0030] Preferably, on the basis of constructing the image evaluation function, the number of pixel categories in the original image is further added to the process of constructing the image evaluation function.
[0031] This application has at least the following beneficial effects:
[0032] 1. This application selects template operators in different directions to calculate contour visibility by analyzing the edge connection direction of pixel points. The beneficial effect is that it can more accurately measure the contour visibility of each edge point in the edge connection direction, while avoiding redundant calculation of multiple direction templates of edge points, thereby improving calculation efficiency. It also takes into account the impact of the difference in contour edge pixels on the degree of human visual attention, and distinguishes the degree to which the contour edges of different objects containing important structural information of the scene in the image are noticed by human vision, thereby achieving a more detailed division of the importance of image features carried by each position in the image.
[0033] 2. This application determines the local edge gradient loss of each edge point by measuring the spatial distribution of the edge and the degree of color gradient of the edge. Its beneficial effect is that it takes into account the continuity of the edge of the object contour in the image and the hierarchical gradient of the visual color. Through pattern recognition technology, it improves the degree of retention of detail information of the edges of the contours of different objects in the image during the color quantization process, avoiding the problem of missing detail information caused by the existing technology.
[0034] 3. This application constructs an image evaluation function through local edge gradient loss and image contour visualization to obtain the color type of the original image when it is quantized. It can effectively compress the color information in the original image without losing the detail information in the image. It can be widely used in various Internet scenarios and ultra-high-definition images. At the same time, this application obtains the interval of quantized color types through sampling and clustering methods, which can greatly shorten the time for optimizing color types and improve the efficiency of image compression. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the technical solutions and advantages of the embodiments of the present application or the prior art, the following is a brief introduction to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0036] Figure 1 A flowchart of an image intelligent compression method provided in one embodiment of the present application;
[0037] Figure 2 A flowchart of the process of constructing an image evaluation function provided in one embodiment of the present application;
[0038] Figure 3 A flow chart of a method for determining contour visibility provided in one embodiment of the present application;
[0039] Figure 4 A flowchart of a method for obtaining an image edge gradient loss map provided in one embodiment of the present application;
[0040] Figure 5 A schematic diagram showing image size comparison before and after color quantization according to an embodiment of the present application;
[0041] Figure 6 A comparison chart of the same image before and after color quantization provided in one embodiment of the present application. DETAILED DESCRIPTION
[0042] To further illustrate the technical means and effectiveness of this application's implementation of the intended invention, the following, in conjunction with the accompanying drawings and preferred embodiments, details the specific implementation, structure, features, and effectiveness of an intelligent image compression method proposed in this application. In the following description, references to "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics of one or more embodiments may be combined in any suitable manner.
[0043] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs.
[0044] The specific scheme of the image intelligent compression method provided by this application is described in detail below with reference to the accompanying drawings.
[0045] An embodiment of the present application provides an intelligent image compression method.
[0046] Specifically, the following image intelligent compression method is provided, see Figure 1 , the method comprises the following steps:
[0047] The first step is to obtain the original image to be compressed and its grayscale image.
[0048] The RGB three-channel image of the original image to be compressed is obtained, and the obtained RGB three-channel image is converted into a grayscale image A. The conversion of the grayscale image is a well-known technology, and the specific process is not repeated here.
[0049] The second step is to construct an image evaluation function based on the distribution of pixels in the original image and its grayscale image.
[0050] Since the human visual system (HVS) is highly sensitive to edges and contours, which can also provide important structural information in the scene, this application analyzes image structural information through pattern recognition and pattern clustering to achieve fast and accurate image quantification.
[0051] In order to identify important structural information in the scene, the embodiment of the present application uses an edge detection algorithm to extract edge image B from grayscale image A, and extracts all edge contours in edge image B, and records the grayscale value of the pixel point at the corresponding position in grayscale image A of any pixel point in edge image B as the grayscale value of any pixel point in edge image B.
[0052] As one implementation of the present invention, the Canny edge detection algorithm is used to extract edge image B from grayscale image A. The Canny edge detection algorithm is a well-known technique, and the specific process is not described in detail here. As other implementations of the present invention, edge detection algorithms such as the Sobel operator and the Scharr algorithm may also be used to extract edge image B from grayscale image A.
[0053] In the embodiment of the present application, the process flow chart of constructing the image evaluation function is shown in the attached figure. Figure 2 As shown, specifically:
[0054] S1, performing edge detection on the grayscale image to obtain edge points, and determining the contour visibility of each edge point according to the grayscale distribution of the surrounding pixels to obtain an image contour visibility map.
[0055] When there is a clear color contrast between an object and its background, this contrast will form a strong gradient change at the edge of the object's outline in the image to highlight the edge of the object's outline. The more uniform the color distribution on both sides of the object's outline in the image and the greater the color difference on both sides, the more obvious the edge will appear and the easier it will become the visual focus of people. Therefore, when performing color mapping on the original image, the color detail information of the area where the edge is located should be retained.
[0056] Based on the above analysis, taking the j-th edge point B(i,j) on the i-th edge contour B(i) in the edge image B as an example, the contour visibility of the edge point B(i,j) is analyzed as follows:
[0057] First, the gradient direction of each edge point is calculated. The gradient direction is calculated using the Sobel operator. The principle will not be described here. The gradient direction represents the local pixel change direction of each pixel, which can refer to the edge connection direction in this application.
[0058] Then, according to the gradient direction of each edge point, a suitable operator template is selected to calculate the contour visibility of the edge point, specifically:
[0059] If the gradient direction is between 0° and 22.5° or 337.5° and 360°, the 0° template of the Kirsch operator is selected;
[0060] If the gradient direction is between 22.5° and 67.5°, the 45° template of the Kirsch operator is selected;
[0061] If the gradient direction is between 67.5° and 112.5°, the 90° template of the Kirsch operator is selected;
[0062] If the gradient direction is between 112.5° and 157.5°, the 135° template of the Kirsch operator is selected;
[0063] If the gradient direction is between 157.5° and 202.5°, the 180° template of the Kirsch operator is selected;
[0064] If the gradient direction is between 202.5° and 247.5°, the 225° template of the Kirsch operator is selected;
[0065] If the gradient direction is between 247.5° and 292.5°, the 270° template of the Kirsch operator is selected;
[0066] If the gradient direction is between 292.5° and 337.5°, the 315° template of the Kirsch operator is selected.
[0067] The left side of the gradient direction interval is a closed interval, and the right side is an open interval. In addition, the special 360° value is also a closed interval. The Kirsch operator is a well-known technology and will not be described in detail.
[0068] Finally, the corresponding operator template is selected to perform convolution operation with the edge point to obtain the contour visibility. Since the convolution calculation may have negative values, it is also necessary to use range normalization on the result after the convolution operation, and the value after range normalization is used as the final contour visibility of each edge point.
[0069] It should be understood that Kirsch operator templates are directionally selective, and each template can be used to detect contours in a specific direction. By selecting the template that best matches the gradient direction, the degree of contour visibility of each edge point in the edge connection direction can be more accurately measured. Larger values indicate more pronounced contours, and the corresponding image locations are more likely to attract the human eye, making them more likely to be retained during color quantization.
[0070] In other embodiments of the present application, the Sobel operator or other gradient operators can also be used to calculate the contour visibility. For example, the gradient amplitude calculated by the Sobel operator can be used as the contour visibility of the pixel point. The use of the Sobel operator can improve the running speed. The implementer can freely select the method of calculating the contour visibility according to the situation.
[0071] In the embodiment of the present application, the flow chart of the method for determining the contour visibility is shown in the attached figure. Figure 3 shown.
[0072] Furthermore, after calculating the corresponding contour visibility for each edge pixel point, a new image is obtained, which is recorded as the image contour visibility image C, which is used to characterize the degree of difference in grayscale distribution of pixels on the contour edges of all objects in the grayscale image A in the connection direction of their contour edges and the degree of contour highlighting, so as to reflect the distribution of pixels containing different important image features in the grayscale image A.
[0073] S2, divide the pixels in the original image into K categories according to their color values; obtain the main color value of each category of pixels, and replace the color value of the pixels in its category according to the main color value to obtain a color mapping image of the original image; based on the distribution difference of the position of the edge point between the window where any edge point after edge detection of the original image is located and the window where the corresponding position after edge detection of the color mapping image is located, and the distribution difference of the color gradient entropy, determine the local edge gradient loss degree of any edge point to obtain an image edge gradient loss map.
[0074] When color mapping is performed on an original image to reduce the file storage size of the original image, it is usually necessary to map the R, G, and B color values of pixels in the original image to achieve image compression.
[0075] In the embodiment of the present application, the flowchart of the method for obtaining the image edge gradient loss map is shown in the attached figure. Figure 4As shown, specifically:
[0076] S201 , dividing the pixels in the original image into K categories according to their color values.
[0077] Preferably, in an embodiment of the present application, a clustering algorithm is used to divide the color values of pixels in the original image.
[0078] As one implementation of the present invention, a K-Means clustering algorithm is selected to cluster the color values of pixels in the original image. As other implementations of the present invention, other suitable clustering algorithms may also be used, such as a K-Means algorithm, a hierarchical clustering algorithm, and a fuzzy C-means algorithm.
[0079] In other embodiments of the present application, the range of pixel values of the pixel points in each channel may be divided using a median quantization method.
[0080] The specific implementation method is as follows: the pixel value range of each channel of the original image is 0-255, which is evenly divided into a preset number M parts, and all the pixels in each part are mapped to the median of the range.
[0081] For example, if the preset number M is set to 4, 0-255 is divided into four parts: 0-63, 64-127, 128-191, and 192-255. The color values of the pixels in these four parts are mapped to 32, 96, 160, and 224 respectively.
[0082] Furthermore, in order to preserve as much as possible the main color information of the original image when subsequently performing color mapping on the original image, and to increase the speed of finding the optimal number of color types retained in the color mapping result of the original image.
[0083] In the embodiment of the present application, a reshaping operation is first performed on the original image to obtain the pixel values of all pixels, and then the pixel values of all pixels are sampled, and the sampling is a preset ratio value of the number of pixels. The sampled results are clustered, and the number of clusters after clustering is used as the number of main colors of the original image, thereby obtaining the range of K:
[0084] The difference between the number of primary colors and the preset color range value N is used as the lower limit of K, and the sum of the number of primary colors and the preset color range value N is used as the upper limit of K. In this embodiment, the preset ratio value is 0.05, the preset color range value N is 5, and the clustering algorithm uses the DBSCAN algorithm, which is a well-known technology and will not be described in detail. Obtaining the value range of K using this method can greatly improve the calculation speed (because the maximum number of image colors is the cube of 256) and improve the accuracy of quantization.
[0085] K is limited by its lower and upper limits, and the pixel division of the original image is achieved sequentially according to the range of K values for each different value. In other embodiments of the present application, peak detection can also be used to obtain the number of primary colors in the original image. Specifically, peak detection is performed on the grayscale frequency of all grayscale values in the grayscale image of the original image, and the number of peaks is used as the number of primary colors. Peak detection methods are well known in the art, and their principles will not be detailed here.
[0086] S202 , obtaining the main color value of each type of pixel, and replacing the color value of the pixel in the corresponding type according to the main color value to obtain a color mapping image of the original image.
[0087] In this application, taking the k-th pixel point in the original image as an example, the main color value r(k) of the k-th pixel point is calculated to characterize the main color of the k-th pixel point in the original image when the pixel points in the original image are divided into K categories.
[0088] Preferably, in an embodiment of the present application, the main color value is obtained by the average level of the product of all color values in each type of pixel and their corresponding occurrence frequencies.
[0089] As an implementation of an embodiment of the present application, the expression of the main color value r(k) of the k-th type pixel is: Where w1(m) and w2(m) represent the mth color value and the frequency of occurrence of the mth color value in the kth pixel in the original image, respectively; M represents the number of color values in the kth pixel in the original image; and round() is the rounding function.
[0090] It should be understood that the greater the frequency of occurrence of the m-th color value in the k-th pixel in the original image, that is, the larger w2(m), which means that the m-th color value can better reflect the main color of the k-th pixel, and r(k) should be closer to w1(m).
[0091] As another implementation of the embodiment of the present application, the main color value r(k) of the k-th type of pixel may also be set to the color value that appears most frequently among the K-th type of pixel.
[0092] In other embodiments of the present application, the main color value r(k) of the k-th type of pixel may also be obtained according to the centroid of the color values of all pixels in the k-th type of pixel.
[0093] Furthermore, the color values of the pixels in each category of pixels in the original image are replaced by the main color values corresponding to each category of pixels. The color types of the pixels in each category of pixels are reduced by using the main color values of the pixels in each category of pixels as the color values of the pixels in each category of pixels. The replacement result of the original image is recorded as the color mapping image R(K) of the original image, which is used to represent the original image obtained by mapping the pixel points in the original image into K categories, that is, when the color values of the pixel points in the original image are mapped to K color values.
[0094] S203, based on the distribution difference of the position of the edge point and the distribution difference of the color gradient entropy between the window where any edge point after edge detection of the original image is located and the window where the corresponding position after edge detection of the color mapping image is located, determine the local edge gradient loss degree of the any edge point to obtain the image edge gradient loss map.
[0095] The edge detection algorithm is used to extract the edge image BR of the original image and the edge image BR(K) of the color mapping image R(K), and all edge contours in the edge image BR and the edge image BR(K) are extracted respectively. Then, the color gradient entropy of the edge points on the edge contours in the edge image BR and the edge image BR(K) is calculated.
[0096] In the embodiment of the present application, the Canny edge detection algorithm is used to perform edge detection on the edge image BR of the original image and the edge image BR(K) of the color mapping image R(K). The Canny edge detection algorithm is a well-known technology and the specific process will not be repeated here.
[0097] The calculation method of the distribution difference of the edge point positions is specifically as follows:
[0098] In this application, taking the j-th edge point BR(i,j) on the i-th edge contour BR(i) in the edge image BR as an example, a window matrix of size W×W is constructed with the edge point BR(i,j) as the center, and is recorded as the edge distribution matrix h(i,j) of the edge point BR(i,j), which is used to characterize the position distribution of the edge contour of the pixel point BR(i,j) in its window.
[0099] Get the pixel point BR(K,i,j) with the same coordinates as the edge point BR(i,j) in the edge image BR(K), and record the window matrix of the pixel point BR(K,i,j) with a size of W×W as the edge distribution matrix h(K,i,j) of the pixel point BR(K,i,j).
[0100] The distance between the edge distribution matrices h(K,i,j) and h(i,j) is recorded as the edge continuity difference value of the edge point BR(i,j), which is used to characterize the degree of change in the continuity of the contour edge information of the edge point BR(i,j) in its window when the color value of the edge point in the original image is mapped to K color values, that is, the distribution difference of the position of the edge point, such as the absence or increase of pixels in the contour edge. The greater the distance between the matrices, the greater the degree of change. In this embodiment, the above window size W is set to 3, that is, the smallest local window, to improve the calculation speed.
[0101] In the embodiments of the present application, methods for calculating the distance between matrices include, but are not limited to, Euclidean distance, Manhattan distance, and Chebyshev distance. The calculation of Euclidean distance, Manhattan distance, and Chebyshev distance are all well-known techniques, and the specific process will not be repeated here.
[0102] Preferably, in an embodiment of the present application, the method for calculating the color gradient entropy is specifically as follows: for each edge point, the distance between the color values of a preset number of pixel points adjacent to it is calculated respectively; all distances are quantized according to a preset interval; and the information entropy of all quantized values is used as the color gradient entropy of each edge point.
[0103] As an implementation method of an embodiment of the present application, the preset number is set to 8, and the distance is calculated using the L2 distance. For each edge point, the L2 distance of the color values of the 8 adjacent pixels is calculated respectively, and then the L2 distance is quantized according to a preset interval, wherein one quantization interval is: the L2 distance less than or equal to G1 is quantized to 1, the L2 distance in the range of [G1, 2*G1) is quantized to 2, the L2 distance in the range of [2*G1, 3*G1) is quantized to 3, and the L2 distance greater than or equal to 3*G1 is quantized to 4. G1 takes a value of 30 in this embodiment. Among them, the calculation process of the L2 distance and the calculation process of the information entropy are both well-known technologies and will not be repeated here.
[0104] At this point, each of the eight adjacent pixels has a quantized value. The information entropy of the eight quantized values is then calculated and used as the color gradient entropy of the central pixel. The larger the value, the more layered the color gradient around the pixel, and the more complex the gradient.
[0105] In other embodiments of the present application, the following method can also be used for calculation: for each edge point, the color values of the adjacent 8 pixel points are compared with it. If the L2 distance between the adjacent pixel value and the center pixel value is greater than the preset comparison threshold G2, the position of the pixel point is marked as 1, otherwise it is 0.
[0106] In this way, the 8 pixels in the 3*3 neighborhood can generate an 8-bit binary number after comparison, which is then converted into a decimal number as the color gradient entropy of the edge point, where G2 is 30 in this embodiment.
[0107] At this point, the color gradient entropy of each edge point can be obtained, and the distance between the color gradient entropies of pixels at the same position before and after quantization can be calculated, which is recorded as the color gradient difference value of the edge point BR(i,j). It is used to characterize the degree of change in the color gradient of the contour edge information of the edge point BR(i,j) in its window when the color value of the pixel point in the original image is mapped to K color values, that is, the distribution difference of the color gradient entropy of the edge point. The larger the distance between the two matrices, the greater the degree of change.
[0108] Preferably, in an embodiment of the present application, the local edge gradient loss degree is determined by a result of forward fusion of the distribution difference of the edge point positions and the distribution difference of the color gradient entropy.
[0109] It can be understood that forward fusion is a fusion method such as addition and multiplication between data. The specific forward fusion method is determined by the implementer according to the actual situation, and this application does not impose any special restrictions.
[0110] As an implementation method of an embodiment of the present application, the product of the edge continuity difference value and the color gradient difference value of the edge point BR(i,j) is used as the local edge gradient loss degree of the edge point BR(i,j), which is used to characterize the continuity of the contour edge and the degree of color gradient loss of the edge point BR(i,j) in its window when the color value of the pixel point in the original image is mapped to K color values. The worse the continuity of the contour edge and the greater the degree of color gradient loss, the less completely the contour edge is preserved, and the greater the degree of loss, that is, the greater the local edge gradient loss.
[0111] As another implementation of the embodiment of the present application, the sum of the edge continuity difference value and the color gradient difference value of the edge point BR(i,j) may be used as the local edge gradient loss of the edge point BR(i,j).
[0112] The method for obtaining the image edge gradient loss map is as follows:
[0113] In addition, after edge detection of the original image, the local edge gradient loss of non-edge points is assigned to 0; the local edge gradient loss of all pixel points is constructed according to their coordinate positions in the original image to construct an image edge gradient loss map.
[0114] Taking the edge image BR after edge detection of the original image as an example, the local edge gradient loss of non-edge points in the edge image BR is assigned a value of 0. The numerical value of each pixel in the edge image BR is replaced with the local edge gradient loss corresponding to each pixel, and the re-assigned image is recorded as the image edge gradient loss map RC(K). At this point, the feature information of the image is obtained through image pattern recognition, which is used to characterize the distribution of the degree of loss of contour edge information around edge points containing contour edge information of objects in the original image in the color mapping image when the color values of the pixels in the original image are mapped to K color values.
[0115] S3, constructs an image evaluation function using the image edge gradient loss map and the image contour appearance map.
[0116] The image edge gradient loss map RC(K) and the numerical values of the corresponding pixel points in the image contour appearance map C are multiplied, and the resulting image is recorded as the image feature loss evaluation map RD(K) of the original image, which is used to characterize the loss of image detail information of the pixel points in the original image containing important feature information of the original image when the color values of the pixel points in the original image are mapped to K color values.
[0117] In the present application, an image evaluation function FR(K) of the original image is constructed based on the image feature loss evaluation graph RD(K), which is used to obtain the optimal number of color types retained in the color mapping result of the original image when color mapping is performed on the original image, wherein the independent variable K when the function value of the image evaluation function FR(K) is the smallest is used as the number of color types of the original image.
[0118] Preferably, in an embodiment of the present application, the image evaluation function is constructed by the average level of all element values in the image feature loss evaluation graph.
[0119] As an implementation method of an embodiment of the present application, the construction expression of the image evaluation function FR(K) of the original image is: FR(K)=rd(K), where FR(K) represents the image evaluation function of the original image; rd(K) represents the mean value of all element values in the image feature loss evaluation graph RD(K); wherein the independent variable of the image evaluation function FR(K) of the original image is K, and the dependent variable is the function value of FR(K) when the independent variable is K.
[0120] It should be understood that in order to effectively reduce the color information that needs to be stored in the original image, when mapping the color values of the pixels in the original image, the number of color value types in the mapping result should be smaller, that is, K should be smaller. At the same time, in order to retain the important image feature information in the original image, the overall loss of image detail information of the pixels in the original image containing the image feature information should be smaller, that is, rd(K) should be smaller.
[0121] As other implementation methods of the embodiments of the present application, the image evaluation function can continue to consider the size of the independent variable K on the basis of the image feature loss evaluation graph RD(K), that is, consider the number of pixel categories in the original image. Therefore, the construction expression of the image evaluation function FR(K) of the original image can also be set to: FR(K)=rd(K)+K; FR(K)=β1*rd(K)+β2*K, β1 and β2 are weight coefficients, and the values are set by the implementer, and β1+β2=1.
[0122] It should be understood that one application of constructing an image feature loss evaluation map is to determine the optimal number of color types retained in the color mapping result when performing color mapping on an image, thereby achieving image compression. Furthermore, the image feature loss evaluation map can also be applied to the field of image evaluation.
[0123] The third step is to obtain the number of color categories when the original image is divided into pixel categories based on the image evaluation function, and then perform color quantization on the original image.
[0124] In this application, taking the original image as an example, the value of the independent variable K when the image evaluation function FR(K) takes the minimum value is obtained, which is recorded as the number of color types KM of the original image, and the color mapping image R(KM) of the original image when K=KM is obtained as the final mapping image RM of the original image to achieve compression of the color information in the original image.
[0125] In the embodiment of the present application, a schematic diagram of image size comparison before and after color quantization is shown in the attached figure. Figure 5 shown.
[0126] In the attached Figure 5 In the example, the horizontal axis is the sample number of the original image to be compressed, and the vertical axis is the size difference between each sample before and after color quantization, in KB. In this embodiment, 75 samples are selected for comparison of the size difference between the images before and after color quantization.
[0127] In the embodiment of the present application, the comparison diagram of the same image before and after color quantization is shown in the attached figure. Figure 6 As shown, Image 1 is the image before color quantization, and Image 2 is the image after color quantization.
[0128] The various embodiments in this application are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments.
[0129] It should be noted that, unless otherwise specified and limited, terms such as "include", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a circuit structure, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such article or device. In the absence of further restrictions, the phrase "including a ..." defines an element, does not exclude the presence of other identical elements in the article or device including the element. In addition, the term "and\or" used herein includes any and all combinations of one or more related listed items.
[0130] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of the present application and include common knowledge or customary techniques in the art not invented herein.
[0131] It will be understood that the present application is not limited to the exact construction that has been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof.
Claims
1. An intelligent image compression method, characterized in that: The method comprises the following steps: Obtain the original image to be compressed and its grayscale image; Based on the distribution of pixels in the original image and its grayscale image, an image evaluation function is constructed; specifically: S1, after edge detection of the grayscale image, the edge points are obtained, and the Kirsch operator template corresponding to the direction closest to the gradient direction of the edge point is selected to perform convolution on the edge point, and the normalized value of the range of the convolution result is used as the contour visibility of each edge point to obtain the image contour visibility map; S2, divide the pixels in the original image into K categories according to their color values; obtain the main color value of each category of pixels, and replace the color values of the pixels in its category according to the main color value to obtain a color mapping image of the original image; For any edge point after edge detection on the original image, the distance between the color values of a preset number of adjacent pixels is calculated, and the information entropy of the numerical value after quantizing the distance according to a preset interval is used as the color gradient entropy of the any edge point; the product of the distribution difference of the position of the edge point and the distribution difference of the color gradient entropy is used as the local edge gradient loss degree of the any edge point to obtain the image edge gradient loss map; S3, multiplying the values at corresponding positions of the image edge gradient loss map and the image contour appearance map to obtain an image feature loss evaluation map, and constructing the image evaluation function using the average of all element values in the image feature loss evaluation map; The number of color categories when the original image is divided into pixel categories is obtained based on the minimum value of the image evaluation function, and the color of the original image is quantized.
2. The image intelligent compression method according to claim 1, wherein: The division range of the pixel point category number K is further limited as follows: the difference between the main color number and the preset color range value is used as the lower limit value of K, and the sum of the main color number and the preset color range value is used as the upper limit value of K.
3. The image intelligent compression method according to claim 2, wherein: The method for obtaining the number of main colors is further defined as: Reshape the original image to obtain the pixel values of all pixels; Clustering is performed on the results of sampling the pixel values of all pixels; The number of clusters after clustering is taken as the number of main colors of the original image.
4. The image intelligent compression method according to claim 1, wherein: The main color value is further obtained by averaging the product of all color values in each type of pixel and their corresponding occurrence frequencies.
5. The image intelligent compression method according to claim 1, wherein: The method for obtaining the image edge gradient loss map is as follows: after edge detection of the original image, the local edge gradient loss of the points that are not edge points is assigned a value of 0; and the local edge gradient loss of all pixel points is constructed according to their coordinate positions in the original image to construct the image edge gradient loss map.
6. The image intelligent compression method according to claim 1, wherein: On the basis of constructing the image evaluation function, the number of pixel categories in the original image is further added into the construction process of the image evaluation function.
Citation Information
Patent Citations
Image processing apparatus and method of processing image
CN102314605A
Method for improving latent image boundary based on edge detection error diffusion algorithm
CN108921770A