An image compression method based on image data analysis
By clustering and matrix merging images, combined with Huffman coding, the problem that traditional entropy coding cannot utilize local features of images is solved, and the image compression effect is improved.
Patent Information
- Application Number
- CN202410070228.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-17
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-01-17
AI Technical Summary
When traditional entropy coding compresses the entire image, it cannot effectively utilize local features in the image, resulting in poor compression results.
By clustering the image, several matrices are divided, merged and compressed according to the probability of gray value in the matrix, and each matrix is independently encoded using Huffman coding.
The compression effect of the entire image is improved, and the spatial distribution characteristics of the image data are taken into consideration to improve the compression effect.
Smart Images

Figure CN117911546B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image data processing, and in particular to an image compression method based on image data analysis. Background Art
[0002] In the process of wireless communication, people use wireless networks to transmit large amounts of image data. Therefore, image data compression becomes a key task to ensure efficient data transmission. Image data usually contains a lot of redundant information, such as correlation between adjacent pixels and repeated patterns in the spatial domain. These characteristics provide opportunities for image compression. Entropy coding is used to perform lossless compression on these data to reduce the amount of data without compromising image quality.
[0003] When entropy coding is traditionally used to compress the entire image, the distribution of pixel values in the entire image may be non-uniform, that is, some values may be common in the entire image, while other values may only be seen in specific areas. If entropy coding is directly applied to the entire image, then these values that only frequently appear in local areas will not be effectively encoded, which will affect the image compression effect. Summary of the invention
[0004] In order to solve the above problems, the present invention provides an image compression method based on image data analysis.
[0005] An image compression method based on image data analysis of the present invention adopts the following technical solution:
[0006] An embodiment of the present invention provides an image compression method based on image data analysis, the method comprising the following steps:
[0007] Get the grayscale image to be compressed;
[0008] Clustering is performed according to the coordinates and grayscale values of the pixels in the grayscale image to obtain several clusters corresponding to the grayscale image, and several matrices of the grayscale image are obtained according to the coordinates of the pixels in each cluster. For any matrix, the compressibility of each matrix is obtained according to the probability of occurrence of different grayscale values in the matrix, and a threshold value is judged on the compressibility of the matrix to obtain several matrices to be merged. For any adjacent matrix of any matrix to be merged, the adjacent matrix and the matrix to be merged are initially merged to obtain several matrices after the matrix to be merged and the adjacent matrix are initially merged;
[0009] According to the probability of occurrence of different gray values in each matrix after the matrix to be merged and the adjacent matrix are initially merged, the compressibility of the matrix to be merged and the adjacent matrix after the initial merger is obtained, according to the compressibility of the matrix to be merged, the compressibility of the adjacent matrix and the compressibility of the matrix to be merged and the adjacent matrix after the initial merger, the necessity of merging the matrix to be merged and each adjacent matrix is obtained, and according to the necessity of merging the matrix to be merged and the adjacent matrix, several merged matrices are obtained;
[0010] The merge matrix and each matrix in the grayscale image except the merge matrix are compressed and stored separately.
[0011] Furthermore, the clustering according to the coordinates and grayscale values of the pixels in the grayscale image to obtain a number of clusters corresponding to the grayscale image includes the following specific steps:
[0012] The horizontal coordinate, vertical coordinate and grayscale value of any pixel point in the grayscale image to be compressed are obtained, and the grayscale value is used as the vertical coordinate of the pixel point. A sample point in the three-dimensional space is obtained according to the horizontal coordinate, vertical coordinate and vertical coordinate of the pixel point, and the sample point corresponding to each pixel point in the grayscale image to be compressed in the three-dimensional space is obtained. All sample points are clustered using an iterative self-organizing clustering algorithm to obtain several clusters corresponding to the grayscale image to be compressed.
[0013] Furthermore, the method of obtaining several matrices of grayscale images according to the coordinates of the pixels in each cluster includes the following specific steps:
[0014] The cluster where the pixel with coordinate (1,1) in the grayscale image to be compressed is located is recorded as the first cluster, and the maximum horizontal coordinate of the pixel in the first cluster is recorded as x max , the minimum horizontal coordinate of the pixel in the first cluster is recorded as x min , the maximum vertical coordinate of the pixel in the first cluster is recorded as y max , the minimum vertical coordinate of the pixel in the first cluster is recorded as y min , and the vertex is (x min ,y min )、(x min ,y max )、(x max ,y min )、(x max ,y max ) is determined in the range of the grayscale image to be compressed, recorded as the first matrix. In the grayscale image to be compressed, the matrices determined by other pixel points are obtained in the order from left to right and from top to bottom, and finally several matrices of the grayscale image to be compressed are obtained.
[0015] Further, obtaining the compressibility of each matrix according to the probabilities of different gray values appearing in the matrix includes the following specific steps:
[0016]
[0017] In the formula, C is the compressibility of any matrix, and P i is the probability that the i-th gray value among the different gray values of the matrix appears in the matrix, log2() is the logarithmic function with base 2, n is the number of different gray values in the matrix, and exp{} is the exponential function with the natural constant as the base.
[0018] Further, performing a threshold judgment on the compressibility of the matrix to obtain several matrices to be merged includes the following specific steps:
[0019] Preset a first threshold, denoted as th1. If C < th1, where C is the compressibility of any matrix, then take this matrix as a matrix to be merged.
[0020] Further, performing an initial merge on the adjacent matrix and the matrix to be merged to obtain several matrices after the initial merge of the matrix to be merged and the adjacent matrix includes the following specific steps:
[0021] Take any matrix to be merged, denoted as the target matrix, and obtain any matrix adjacent to the target matrix as the adjacent matrix. Denote the overlapping edge segment of the target matrix and the adjacent matrix as the overlapping segment. Draw two perpendicular lines through both ends of the overlapping segment, and denote the matrix intercepted by the two perpendicular lines in the target matrix as the first target matrix. Merge the first target matrix and the adjacent matrix into one matrix, denoted as an initial merged matrix; take the remaining matrices in the target matrix and the adjacent matrix except the initial merged matrix plus the initial merged matrix as several matrices after the initial merge of the matrix to be merged and the adjacent matrix.
[0022] Further, obtaining the compressibility after the initial merge of the matrix to be merged and the adjacent matrix according to the probabilities of different gray values appearing in each matrix after the initial merge of the matrix to be merged and the adjacent matrix includes the following specific steps:
[0023] Denote the several matrices after the initial merge of the matrix to be merged and the adjacent matrix as a matrix set;
[0024]
[0025] In the formula, C′ is the compressibility after the initial merge of the target matrix and the adjacent matrix, and P jkis the probability of the kth gray value of different gray values in the jth matrix of the matrix set appearing in the jth matrix, log2() is the logarithmic function with base 2, num j is the number of different gray values in the jth matrix, N is the number of matrices in the matrix set, and exp{} is an exponential function with a natural constant as the base.
[0026] Furthermore, the necessity of merging the matrix to be merged and each adjacent matrix is obtained according to the compressibility of the matrix to be merged, the compressibility of the adjacent matrix, and the compressibility of the matrix to be merged and the adjacent matrix after initial merging, and the specific steps include the following:
[0027] The compressibility of the target matrix is denoted as A1, the compressibility of the adjacent matrix is denoted as A2, the result of adding A1 and A2 is denoted as A3, the ratio of C′ to A3 is used as the necessity of merging the target matrix and the adjacent matrix, and C′ is the compressibility of the target matrix and the adjacent matrix after merging.
[0028] Furthermore, the step of obtaining a plurality of merged matrices according to the necessity of merging the matrix to be merged and the adjacent matrix includes the following specific steps:
[0029] A second threshold is preset, denoted as th2, and the necessity of merging the target matrix and each adjacent matrix is obtained. The maximum value of the necessity of merging is denoted as AC, and the adjacent matrix corresponding to AC is denoted as the first adjacent matrix. If AC>th2, the target matrix and the first adjacent matrix are merged to obtain a merged matrix.
[0030] The specific method of merging the target matrix and the first adjacent matrix to obtain a merged matrix is:
[0031] The edge line segment where the target matrix and the first adjacent matrix overlap is recorded as the first overlapping line segment. Two perpendicular lines are drawn through the two ends of the first overlapping line segment. The matrix intercepted by the two perpendicular lines in the target matrix is recorded as the second target matrix. The second target matrix and the first adjacent matrix are merged into one matrix as a merged matrix.
[0032] Furthermore, the step of compressing and storing the merged matrix and each matrix in the grayscale image except the merged matrix separately includes the following specific steps:
[0033] In order from left to right and from top to bottom, all merged matrices and each matrix in the grayscale image to be compressed except the merged matrix are encoded and compressed respectively using Huffman coding to obtain the encoded data of each matrix, and all the encoded data are stored.
[0034] The beneficial effects of the technical solution of the present invention are as follows: when traditional entropy coding is used to compress image data, the entire image data is directly compressed. Since the pixel value distribution in the entire image may be non-uniform, if entropy coding is directly applied to the entire image, the local characteristics of the image data cannot be taken into account. The present invention analyzes the image grayscale value and considers the spatial distribution characteristics of the image data. According to the spatial distribution characteristics of the image data, the image division matrices are merged to obtain several merged matrices, and each matrix in the image is compressed separately, thereby improving the compression effect of the entire image. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0036] Figure 1 A flowchart of the steps of an image compression method based on image data analysis provided by one embodiment of the present invention;
[0037] Figure 2 A grayscale image schematic diagram of an image compression method based on image data analysis provided by an embodiment of the present invention;
[0038] Figure 3 A schematic diagram of a three-dimensional spatial clustering result of an image compression method based on image data analysis provided by an embodiment of the present invention;
[0039] Figure 4 A schematic diagram of a clustering result of an image compression method based on image data analysis provided by an embodiment of the present invention;
[0040] Figure 5 Several matrix schematic diagrams of grayscale images of an image compression method based on image data analysis provided by one embodiment of the present invention;
[0041] Figure 6 A schematic diagram of the initial merging relationship of matrices of an image compression method based on image data analysis provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of the image compression method based on image data analysis proposed by the present invention, its specific implementation, structure, features and effects, in conjunction with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[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 invention belongs.
[0044] The following is a detailed description of a specific solution of an image compression method based on image data analysis provided by the present invention in conjunction with the accompanying drawings.
[0045] See also Figure 1 , which shows a flowchart of an image compression method based on image data analysis provided by an embodiment of the present invention, the method comprising the following steps:
[0046] Step S001: Obtain a grayscale image to be compressed.
[0047] It should be noted that the purpose of this embodiment is to analyze the grayscale values of pixels in the image, consider the spatial distribution characteristics of the image, divide the image into blocks according to the spatial distribution characteristics of the image, and compress the image according to the block results. Before starting the analysis and processing, it is necessary to first collect the image.
[0048] Specifically, an initial image to be compressed is obtained, and the initial image is grayscaled to obtain a grayscale image to be compressed.
[0049] It should be noted that this embodiment uses grayscale images as an example for analysis. If the RGB image needs to be compressed, the R channel, G channel and B channel images can be processed separately, and each channel image can be regarded as a grayscale image for subsequent analysis and processing.
[0050] At this point, the grayscale image to be compressed is obtained.
[0051] Step S002, clustering is performed according to the coordinates and grayscale values of the pixel points in the grayscale image to obtain several clusters corresponding to the grayscale image, several matrices of the grayscale image are obtained according to the coordinates of the pixel points in each cluster, the compressibility of each matrix is obtained according to the probability of occurrence of different grayscale values in the matrix, a threshold judgment is performed on the compressibility of the matrix to obtain several matrices to be merged, and adjacent matrices and matrices to be merged are initially merged to obtain several matrices after the initial merging of the matrices to be merged and the adjacent matrices.
[0052] It should be noted that in the same grayscale image, the grayscale values of pixels at different positions are distributed differently, that is, some grayscale values may appear frequently in the entire grayscale image, while other grayscale values may only appear in specific areas. If the entire grayscale image is directly compressed using entropy coding, the compression effect may not be good enough. Therefore, it is necessary to perform clustering operations on grayscale images. Clustering operations can divide images into several clusters, and the grayscale values in each cluster have similar characteristics. Then, when grayscale images are encoded separately according to each cluster, these characteristics can be better captured and utilized.
[0053] Specifically, clustering is performed according to the coordinates and grayscale values of the pixels in the grayscale image to obtain several clusters corresponding to the grayscale image, as follows:
[0054] The horizontal coordinate, vertical coordinate and grayscale value of any pixel point in the grayscale image to be compressed are obtained, and the grayscale value is used as the vertical coordinate of the pixel point. A sample point in the three-dimensional space is obtained according to the horizontal coordinate, vertical coordinate and vertical coordinate of the pixel point, and the sample point corresponding to each pixel point in the grayscale image to be compressed in the three-dimensional space is obtained. All sample points are clustered using an iterative self-organizing clustering algorithm to obtain several clusters corresponding to the grayscale image to be compressed.
[0055] It should be noted that the coordinate system of the grayscale image is constructed with the upper left corner of the grayscale image as the coordinate origin, the horizontal right direction as the positive direction of the horizontal axis, and the vertical upward direction as the positive direction of the vertical axis, and the coordinates of the coordinate origin are (1,1).
[0056] It should be noted that in three-dimensional space, when clustering pixels according to their grayscale values, the pixels in each cluster may not be continuous due to local mutation points in the image data. That is, the pixels belonging to the same cluster are not necessarily adjacent in the image. Please refer to Figure 2 , Figure 2 is a schematic diagram of a grayscale image of this embodiment, Figure 2 Contains a 3×3 pixel matrix and the grayscale value corresponding to each pixel, see Figure 3 , Figure 3 is a schematic diagram of the three-dimensional spatial clustering result of this embodiment, Figure 3 Included Figure 2 The two clusters obtained after clustering are shown in Figure 4 , Figure 4 is a schematic diagram of the clustering result of this embodiment. Figure 4 The two pixels marked by the black circle in the middle are one cluster, and the remaining pixels are another cluster. It should be noted that the schematic diagram in this embodiment is only for reference and understanding, and needs to be adjusted according to actual conditions during specific implementation.
[0057] It should be further explained that if the pixels in each cluster are not necessarily adjacent, then in order to decompress the data, it is necessary to record the index positions of all pixels before compression, which will result in a high compression cost. Therefore, the grayscale image needs to be regularly divided into blocks according to the clustering results. Before compression, only the position of the block matrix needs to be recorded, thereby reducing the compression cost of the image data. Therefore, it is necessary to divide the matrix range of each cluster according to the clustering results of the grayscale image.
[0058] Specifically, several matrices of grayscale images are obtained according to the coordinates of the pixels in each cluster, as follows:
[0059] The cluster where the pixel with coordinate (1,1) in the grayscale image to be compressed is located is recorded as the first cluster, and the maximum horizontal coordinate of the pixel in the first cluster is recorded as x max , the minimum horizontal coordinate of the pixel in the first cluster is recorded as x min , the maximum vertical coordinate of the pixel in the first cluster is recorded as y max , the minimum vertical coordinate of the pixel in the first cluster is recorded as y min , and the vertex is (x min ,y min )、(x min ,y max )、(x max ,y min )、(x max ,y max ) is determined in the grayscale image to be compressed, recorded as the first matrix, the first matrix contains the corresponding pixels in several clusters, in the grayscale image to be compressed, the matrices determined by other pixels are obtained in the order from left to right and from top to bottom, and finally several matrices of the grayscale image to be compressed are obtained; please refer to Figure 5 , Figure 5 are schematic diagrams of several matrices of grayscale images of this embodiment, Figure 5 It contains several matrices of different sizes. It should be noted that the pixels already in the matrix do not participate in determining other matrices.
[0060] It should be noted that when dividing the matrix as described above, any matrix may contain multiple clusters. The more the number of clusters, the wider the range of gray-scale values in the matrix. The wider the range of gray-scale values, the fewer the pixel points with the same gray-scale value in the matrix. The fewer the pixel points with the same gray-scale value, the closer the occurrence probabilities of different gray-scale values within the matrix range. When using entropy coding to compress image data, the closer the occurrence probabilities of different gray-scale values, the worse the compression effect, that is, the lower the compressibility when compressing the image data in this matrix alone. Therefore, it is necessary to analyze the compressibility of the matrix through the probabilities of each gray-scale value in any matrix.
[0061] Specifically, for any matrix, the compressibility of each matrix is obtained according to the occurrence probabilities of different gray-scale values in the matrix, as follows:
[0062]
[0063] In the formula, C is the compressibility of any matrix, P i is the probability that the i-th gray-scale value among different gray-scale values in the matrix appears in the matrix, log2() is the logarithmic function with base 2, n is the number of different gray-scale values in the matrix, exp{} is the exponential function with base e. In this embodiment, the exp{-U} model is used to present the inverse proportional relationship and normalization processing. U is the input of the model, and the implementer can set the inverse proportional function and normalization function according to the actual situation. It should be noted that the probability that the i-th gray-scale value appears in the matrix can be obtained by the ratio of the number of times the i-th gray-scale value appears in the matrix to the number of times all gray-scale values appear in the matrix, which will not be elaborated here.
[0064] It should be noted that represents the entropy value of the occurrence probabilities of different gray-scale values in any matrix. The smaller the entropy value, the more discrete the distribution of gray-scale values in the matrix, the better the compression effect of the gray-scale values in the matrix, that is, the higher the compressibility of the matrix.
[0065] Furthermore, a threshold judgment is made on the compressibility of the matrix to obtain several matrices to be merged, as follows:
[0066] A first threshold is preset, denoted as th1. In this embodiment, th1 = 0.6 is used for description. If C < th1, it means that the compressibility of this matrix is too low and it needs to be merged with the adjacent matrix, and this matrix is used as a matrix to be merged. If C ≥ th1, it means that the compressibility of this matrix is high and it can be directly compressed without merging, and this matrix is not used as a matrix to be merged.
[0067] Furthermore, for any adjacent matrix of any matrix to be merged, the adjacent matrix and the matrix to be merged are initially merged to obtain several matrices after the matrix to be merged and the adjacent matrix are initially merged, as follows:
[0068] Any matrix to be merged is recorded as the target matrix, and any matrix adjacent to the target matrix is obtained as the adjacent matrix. The edge line segment where the target matrix and the adjacent matrix overlap is recorded as the overlapping line segment. Two vertical lines are drawn through the two ends of the overlapping line segment. The vertical lines and the overlapping line segments are perpendicular. The matrix intercepted by the two vertical lines in the target matrix is recorded as the first target matrix. The first target matrix and the adjacent matrix are merged into one matrix, which is recorded as an initial merged matrix. The remaining matrices in the target matrix and the adjacent matrix except the initial merged matrix are added to the initial merged matrix as several matrices after the initial merge of the matrix to be merged and the adjacent matrix. It should be noted that after the initial merge of the adjacent matrix and the matrix to be merged to obtain the initial merged matrix, there will be several remaining matrices. Please refer to Figure 6 , Figure 6 Schematic diagram of the initial matrix merging relationship of this embodiment. Figure 6 There are three cases where the adjacent matrix and the target matrix are initially merged. For the first case, Figure 6 In the top case, the dotted line where the adjacent matrix and the target matrix overlap is the overlapping line segment. After the initial merging of the adjacent matrix and the target matrix, two matrices are obtained, including the dotted shadow matrix, which is the initial merged matrix, and the remaining matrix 1; for the second case, that is Figure 6 In the middle case, the adjacent matrix and the target matrix are initially merged to obtain three matrices, including the dotted shadow matrix, which is the initial merge matrix, and the remaining two matrices, matrix 1 and matrix 2; for the third case, that is Figure 6 In the bottom case, the adjacent matrix and the target matrix are initially merged to obtain a matrix, namely the initial merged matrix.
[0069] Step S003: according to the probability of occurrence of different gray values in each matrix after the initial merging of the matrix to be merged and the adjacent matrix, the compressibility of the matrix to be merged and the adjacent matrix after the initial merging is obtained, according to the compressibility, the necessity of merging the matrix to be merged and each adjacent matrix is obtained, according to the necessity of merging the matrix to be merged and the adjacent matrix, several merged matrices are obtained, and the merged matrix and each matrix in the gray image except the merged matrix are compressed and stored respectively.
[0070] It should be noted that if a matrix is a matrix to be merged, it means that the distribution of the grayscale values in the matrix is relatively uniform, and the compression effect of directly compressing the matrix is not good. Therefore, it is necessary to merge the matrix with its adjacent matrices to change the distribution characteristics of the grayscale values in the matrix so that the data distribution in the merged matrix becomes discrete, that is, the greater the probability difference of each grayscale value, the better the compression effect of the merged matrix can be judged.
[0071] Specifically, according to the probability of occurrence of different gray values in each matrix after the matrix to be merged and the adjacent matrix are initially merged, the compressibility of the matrix to be merged and the adjacent matrix after the initial merger is obtained, as follows:
[0072] A number of matrices obtained after the matrix to be merged and the adjacent matrix are initially merged are recorded as a matrix set.
[0073]
[0074] Where C′ is the compressibility of the target matrix and the adjacent matrix after the initial merging, P jk is the probability of the kth gray value of different gray values in the jth matrix of the matrix set appearing in the jth matrix, log2() is the logarithmic function with base 2, num j is the number of different grayscale values in the jth matrix, N is the number of matrices in the matrix set, exp{} is an exponential function with a natural constant as the base, and this embodiment adopts the exp{-U} model to present the inverse proportional relationship and normalization processing, U is the input of the model, and the implementer can set the inverse proportional function and normalization function according to the actual situation.
[0075] It should be noted that if the probability distribution of each gray value in each matrix of the matrix set is more uneven, the compressibility of the target matrix and the adjacent matrix after the initial merging is higher and the compression effect is better. Conversely, the compression effect is worse and the compressibility is lower.
[0076] It should be noted that if the compressibility of the target matrix and the adjacent matrix after the initial merging is higher than that before the merging, it means that the compression effect after merging the two is better, otherwise, the compression effect is worse.
[0077] Specifically, according to the compressibility of the matrix to be merged, the compressibility of the adjacent matrix, and the compressibility of the matrix to be merged and the adjacent matrix after the initial merging, the necessity of merging the matrix to be merged and each adjacent matrix is obtained, as follows:
[0078] The compressibility of the target matrix is denoted as A1, the compressibility of the adjacent matrix is denoted as A2, the result of adding A1 and A2 is denoted as A3, and the ratio of C′ to A3 is used as the necessity of merging the target matrix and the adjacent matrix.
[0079] It should be noted that the greater the necessity of merging the target matrix and the adjacent matrix, the greater the compressibility of the matrix to be merged and its adjacent matrix after merging, and the higher the mergeability, and vice versa, the lower the mergeability.
[0080] Furthermore, several merging matrices are obtained according to the necessity of merging the matrix to be merged and the adjacent matrix, as follows:
[0081] A second threshold is preset, denoted as th2. This embodiment is described as th2=1, and the necessity of merging the target matrix and each adjacent matrix is obtained. The maximum value of the necessity of merging is recorded as AC, and the adjacent matrix corresponding to AC is recorded as the first adjacent matrix. If AC>th2, the target matrix and the first adjacent matrix are merged to obtain a merged matrix.
[0082] The specific method of merging the target matrix and the first adjacent matrix to obtain a merged matrix is:
[0083] The edge line segment where the target matrix and the first adjacent matrix overlap is recorded as the first overlapping line segment. Two perpendicular lines are drawn through the two ends of the first overlapping line segment, and the perpendicular lines are perpendicular to the first overlapping line segment. The matrix intercepted by the two perpendicular lines in the target matrix is recorded as the second target matrix. The second target matrix and the first adjacent matrix are merged into one matrix as a merged matrix. The remaining matrices in the target matrix and the first adjacent matrix except the merged matrix are taken as split matrices, and no longer participate in other merges, but are directly used as matrices for subsequent compression and storage.
[0084] If AC≤th2, the target matrix and the first adjacent matrix are not merged.
[0085] It should be noted that the matrices that have already participated in the merge will not be merged again, that is, they will only be merged once, and will not be merged if the threshold condition is not met.
[0086] Furthermore, the merged matrix and each matrix in the grayscale image except the merged matrix are compressed and stored separately, as follows:
[0087] In order from left to right and from top to bottom, all merged matrices and each matrix in the grayscale image to be compressed except the merged matrix are encoded and compressed respectively using Huffman coding to obtain the encoded data of each matrix, and all the encoded data are stored.
[0088] It should be noted that when using Huffman coding for compression, it is necessary to record the position of each matrix in the grayscale image to be compressed and the Huffman tree corresponding to each matrix to facilitate subsequent decompression. The purpose of this embodiment is to compress the image, and the decompression will not be described in detail. Huffman coding is a kind of entropy coding.
[0089] Through the above steps, an image compression method based on image data analysis is completed.
[0090] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present invention should be included in the protection scope of the present invention.
Claims
1. An image compression method based on image data analysis, It is characterized in that The method comprises the following steps: Get the grayscale image to be compressed; Clustering is performed according to the coordinates and grayscale values of the pixels in the grayscale image to obtain several clusters corresponding to the grayscale image, and several matrices of the grayscale image are obtained according to the coordinates of the pixels in each cluster. For any matrix, the compressibility of each matrix is obtained according to the probability of occurrence of different grayscale values in the matrix, and a threshold value is judged on the compressibility of the matrix to obtain several matrices to be merged. For any adjacent matrix of any matrix to be merged, the adjacent matrix and the matrix to be merged are initially merged to obtain several matrices after the matrix to be merged and the adjacent matrix are initially merged; According to the probability of occurrence of different gray values in each matrix after the matrix to be merged and the adjacent matrix are initially merged, the compressibility of the matrix to be merged and the adjacent matrix after the initial merger is obtained, according to the compressibility of the matrix to be merged, the compressibility of the adjacent matrix and the compressibility of the matrix to be merged and the adjacent matrix after the initial merger, the necessity of merging the matrix to be merged and each adjacent matrix is obtained, and according to the necessity of merging the matrix to be merged and the adjacent matrix, several merged matrices are obtained; Compress and store the merged matrix and each matrix in the grayscale image except the merged matrix respectively; The specific steps of obtaining several matrices of grayscale images according to the coordinates of the pixel points in each cluster are as follows: The coordinates of the grayscale image to be compressed are The cluster where the pixel point is located is recorded as the first cluster, and the maximum horizontal coordinate of the pixel point in the first cluster is recorded as , the minimum horizontal coordinate of the pixel in the first cluster is recorded as , the maximum vertical coordinate of the pixel in the first cluster is recorded as , the minimum vertical coordinate of the pixel in the first cluster is recorded as , and the vertex is A range determined in the grayscale image to be compressed is recorded as a first matrix. In the grayscale image to be compressed, matrices determined by other pixel points are obtained in order from left to right and from top to bottom, and finally several matrices of the grayscale image to be compressed are obtained; The method of obtaining the compressibility of each matrix according to the probability of occurrence of different gray values in the matrix includes the following specific steps: In the formula, is the compressibility of any matrix, is the probability that the i-th gray value appears in the matrix among the different gray values of the matrix, is the logarithmic function with base 2, is the number of different gray values in the matrix, is an exponential function with a natural constant as base; The initial merging of the adjacent matrix and the matrix to be merged to obtain a plurality of matrices after the matrix to be merged and the adjacent matrix are initially merged includes the following specific steps: Any matrix to be merged is recorded as a target matrix, and any matrix adjacent to the target matrix is obtained as an adjacent matrix. The edge line segments where the target matrix and the adjacent matrix overlap are recorded as overlapping line segments. Two perpendicular lines are drawn through the two ends of the overlapping line segments. The matrix intercepted by the two perpendicular lines in the target matrix is recorded as the first target matrix. The first target matrix and the adjacent matrix are merged into one matrix, which is recorded as an initial merged matrix. The remaining matrices in the target matrix and the adjacent matrix except the initial merged matrix are added to the initial merged matrix as several matrices after the initial merge of the matrix to be merged and the adjacent matrix.
2. According to claim 1, an image compression method based on image data analysis, It is characterized in that The clustering according to the coordinates and grayscale values of the pixels in the grayscale image to obtain a number of clusters corresponding to the grayscale image includes the following specific steps: The horizontal coordinate, vertical coordinate and grayscale value of any pixel point in the grayscale image to be compressed are obtained, and the grayscale value is used as the vertical coordinate of the pixel point. A sample point in the three-dimensional space is obtained according to the horizontal coordinate, vertical coordinate and vertical coordinate of the pixel point, and the sample point corresponding to each pixel point in the grayscale image to be compressed in the three-dimensional space is obtained. All sample points are clustered using an iterative self-organizing clustering algorithm to obtain several clusters corresponding to the grayscale image to be compressed.
3. The image compression method based on image data analysis according to claim 1, It is characterized in that The method of performing threshold judgment on the compressibility of matrices to obtain a plurality of matrices to be merged includes the following specific steps: A first threshold is preset, denoted as th1, if , is the compressibility of any matrix, and the matrix is regarded as a matrix to be merged.
4. The image compression method based on image data analysis according to claim 1, It is characterized in that According to the probability of occurrence of different gray values in each matrix after the matrix to be merged and the adjacent matrix are initially merged, the compressibility degree of the matrix to be merged and the adjacent matrix after the initial merger is obtained, including the following specific steps: The matrix to be merged and the adjacent matrix are initially merged into several matrices, which are recorded as a matrix set; In the formula, is the degree of compressibility of the target matrix and the adjacent matrix after the initial merging, is the probability that the kth gray value of different gray values in the jth matrix of the matrix set appears in the jth matrix, is the logarithmic function with base 2, is the number of different grayscale values in the j-th matrix, is the number of matrices in the matrix set, is an exponential function with a natural constant as its base.
5. The image compression method based on image data analysis according to claim 1, It is characterized in that The necessity of merging the matrix to be merged and each adjacent matrix is obtained according to the compressibility of the matrix to be merged, the compressibility of the adjacent matrix, and the compressibility of the matrix to be merged and the adjacent matrix after initial merging, and the specific steps include the following: The compressibility of the target matrix is recorded as A1, the compressibility of the adjacent matrix is recorded as A2, and the result of adding A1 and A2 is recorded as A3. The ratio of A3 as the necessity of merging the target matrix and the adjacent matrix, The degree of compressibility after merging the target matrix and the adjacent matrix.
6. The image compression method based on image data analysis according to claim 1, It is characterized in that The step of obtaining a plurality of merged matrices according to the necessity of merging the matrix to be merged and the adjacent matrix includes the following specific steps: A second threshold is preset, denoted as th2, and the necessity of merging the target matrix and each adjacent matrix is obtained. The maximum value of the necessity of merging is recorded as AC, and the adjacent matrix corresponding to AC is recorded as the first adjacent matrix. If , merge the target matrix and the first adjacent matrix to obtain a merged matrix; The specific method of merging the target matrix and the first adjacent matrix to obtain a merged matrix is: The edge line segment where the target matrix and the first adjacent matrix overlap is recorded as the first overlapping line segment. Two perpendicular lines are drawn through the two ends of the first overlapping line segment. The matrix intercepted by the two perpendicular lines in the target matrix is recorded as the second target matrix. The second target matrix and the first adjacent matrix are merged into one matrix as a merged matrix.
7. The image compression method based on image data analysis according to claim 1, It is characterized in that The specific steps of compressing and storing the merged matrix and each matrix in the grayscale image except the merged matrix are as follows: In order from left to right and from top to bottom, all merged matrices and each matrix in the grayscale image to be compressed except the merged matrix are encoded and compressed respectively using Huffman coding to obtain the encoded data of each matrix, and all the encoded data are stored.
Citation Information
Patent Citations
Method for compressing and uncompressing image based on color classification and cluster
CN103458242A
Efficient data compression and storage method for unmanned aerial vehicle
CN115834895A
