Method for lossy image compression using PCA and lzma
By applying PCA to variance-based block groups and using LZMA for lossless compression, the method enhances lossy image compression, achieving better compression ratios and smaller file sizes with minimal quality loss, addressing inefficiencies in existing techniques.
Patent Information
- Application Number
- PCT/BG2023/050003
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-05-05
- Publication Date
- 2024-11-14
AI Technical Summary
Existing lossy image compression techniques, including JPEG, do not achieve optimal compression ratios while preserving image quality, especially for small mean square errors, due to inefficiencies in processing color values across rows and columns.
The method employs Principal Component Analysis (PCA) to reduce dimensionality by splitting images into 8x8 blocks, applying PCA to variance-based block groups, and using Lempel–Ziv–Markov chain algorithm (LZMA) for lossless compression of eigenvectors and transformed data, allowing for flexible encoding schemes to control mean square error and file size.
This approach results in significantly smaller file sizes and improved compression ratios for images with minimal quality loss, offering two encoding schemes to balance speed and flexibility in achieving target mean square errors.
Smart Images

Figure BG2023050003_14112024_PF_FP_ABST
Abstract
Description
METHOD FOR LOSSY IMAGE COMPRESSION USING PCA AND LZMA
[0001] This invention relates to a method for lossy image compression for storing and transmitting still images over the internet.
[0002] There are quite a few existing methods of image compression, which can be grouped in two types: lossless and lossy. With the lossless compression one can reconstruct the image without any loss of information, but it cannot produce a compression ratio better than 0.5, which quite insufficient for the current volumes of multimedia files. The better solution is the lossy compression, which ensures much better compression ratio with a reasonable error compared to the original image, which cannot be spotted by the human eye.
[0003] The most widely used standard for saving still images with lossy compression is the JPEG format [NPL:1]. It produces good quality images for small mean square errors (MSE), but it the compression ratio is not so good and can be improved. The proposed method for lossy image compression method produces much better compression ratio than JPEG for small MSE, i.e. preserving the quality of the original image. It uses principal component analysis (PCA) and Lempel–Ziv–Markov chain algorithm (LZMA) lossless compression to store the eigenvectors and transformed data (coefficients) necessary to decode the image.
[0004] JPEG is the most popular lossy image compression. The algorithm consists of several steps. First the RGB image is converted to YUV, also known as YCbCr color space using the following formula:
[0005]
[0006] After the transformation U and V are downsampled by a factor of 2 (or 4). That means every 4 pixels (or 16 pixels) are averaged into one pixel. This downsampling is almost unnoticeable for the human eye. Then the image is divided into 8x8 pixel blocks and Discrete Cosine Transform (DCT) is applied to each block of brightness (Y) values. DCT is a type of Discrete Fourier Transform and converts pixel brightness to coefficients for different frequencies. The idea is to discard some of the high frequencies, which correspond to high level of detail, which cannot be noticed by our eyes. In the end run length encoding, differential pulse code modulation and entropy coding are applied to compress the DCT coefficients.
[0007] A group of image compression techniques are based on further optimisation of DCT. Brahini et al [NPL:2] proposed an approximate multiplication-free of discrete cosine transform for still image compression. They introduced null elements into a specified integer DCT, which lead to a low complexity and faster transform. Similarly Puchala [NPL:3] tried to find the best approximation of a 8-point DCT based on the parametric model of the DCT matrix. The parameters are determined in such a way that only additions and bit-shift operations are required which also reduces the computational complexity and better performance. Ibrahim et al [NPL:4] also proposed a DCT based lossy image compression technique. The original image is divided into NxN blocks, where N is multiple of 2, each block is categorized whether it is high frequency or low frequency according to its spatial details. The image blocks are converted into 1D vectors using horizontal scan order. Then, one dimensional DCT is applied for each vector to produce transform coefficients. The transformed coefficients are quantized with different quantization values according to the energy of the block. An enhanced entropy encoder is applied to store the quantized coefficients.
[0008] Many other quite different compression methods have been proposed. Jassim and Qassim [NPL:5] developed an image compression technique they call a five modulus method. Similarly to the JPEG compression the image is first divided into blocks of size 8x8 pixels. Then each RGB value of each pixel is divided by 5. The new colours are in the range 0-51. After that the minimum is found for each block and subtracted from all values in that block. As a result only 6 bits are needed to store a colour value.
[0009] Jeromel & Žalik [NPL:6] introduced a lossy compression for cartoon images. First the image is portioned to regions with approximately the same colour. Chain codes are determined for all regions and the sequence of these code symbols are transformed and compresses with run length encoding. In the end an arithmetic encoder may be used to compress the obtained binary stream additionally.
[0010] Wang et al [NPL:7] used medial descriptors and B-splines for lossy image compression. The image is first split into n layers, then spline medial axis transforms are applied to reconstruct the image. However their method cannot get better compression and quality than JPEG for all image types, i.e. it is not very successful for images with many fine details.
[0011] Zhang et al [NPL:8] tried to increase the quality of JPEG compression model for low bit rates. First the image is portioned into 8×8 size blocks with high texture complexity and 16×16 size blocks with low texture complexity using texture adaptive non-uniform rectangular partition algorithm. Then a new encoding based on the complete orthogonal U-system is proposed for coding image blocks with different sizes. As a result the quality of the compressed low bit rate image is improved, and the blocking artefacts are also suppressed.
[0012] Neural networks and deep learning approaches are also quite common. Agustsson et al [NPL:9] decided to use generative adversarial networks for learned image compression, which works on low bitrates. Their model synthesizes details which require too much storage, obtaining visually pleasing results at bitrates where other methods fail.
[0013] Sebai & Shah [NPL:10] use a neural network-based scheme which can to automatically optimize coding parameters with multi-term perceptual loss function based on semantic-important structural SIMilarity index. They suggested modulating the compression network on the bitwidth of its activations by quantizing them according to several bitwidth values.
[0014] Clausen and Wechsler [NPL:11] use a hybrid approach. First the image is partitioned in 2x2 pixel blocks with 3 (RGB) components per pixel, the image is presented as a set of 12 dimensional vectors. Then a neural network based on PCA is used to compress the image and a feed forward neural network trained with back propagation needed for the decompression. The result of the compression step is a black & white image, which can be further compressed with other methods. The decompression restores the RGB colours. Although the compression rate is good, the mean square error is relatively high and training takes time.
[0015] The next several techniques utilize PCA for lossy compression. Lim and Manap's [NPL:12] method is optimized for medical black & white images. An automatic segmentation based on brain symmetrical property is used to determine the important regions of interest (ROI). Then PCA is used to compress the ROI with higher compression and all other regions with lower compression rates. As a results the diagnostically important regions are compressed with near lossless quality.
[0016] Ma and Yuan [NPL:13] utilized a hybrid approach. First they used a convolution neural network for image feature extraction, and then PCA to reduced dimensions of the extracted features. They optimized the PCA algorithm to process high-dimensional sparse big data.
[0017] Asnaoui [NPL:14] used a similar to PCA technique for lossy image compression based on Singular Value Decomposition (SVD). SVD is a generalization of the eigen-decomposition used to analyze rectangular matrices. The input image of m x n pixels is split into R, G, B components and SVD is applied to each component. Block iterative algorithm is used to compute the SVD and the experimental results show it has better compression properties than MATLAB's SVD.
[0018] Ng [NPL:15] applied PCA directly on the image matrix withmrows andncolumns. The paper gives results only for black & white (BW) images and the loss of quality of compressed images, when reducing the total variance to 0.99 or 0.97 is quite obvious, though the achieved compression ratio is low.
[0019] Similarly Santo [NPL:16] apply PCA to the image matrix directly on BW medical images and Fan et al [NPL:17] found an interesting application of PCA for robust video steganography for social media to construct reliable hidden communication.
[0020]
[0021] The existing lossy image compression techniques do not produce good image compression ratio for small mean square errors, i.e. preserving the quality of the original image as much as possible. Most of the current approaches using PCA for image compression take as an input data for the PCA transform the image pixel matrix of m row and n columns. This does not produce good compression and good image quality because the colour values change a lot in a given row (or column).
[0022] The current invention uses PCA to reduce dimensionality of the image, which works in the following way. An input matrixXstoresmobservations ofnvariables. The first step is to compute the mean values of all observations, i.e. of each column and subtract them from the original data. Thus anmxnmatrixXis determined, in which every row is the mean vector x. The next step is to calculate the covariance matrix of the data set
[0023] [Math. 2]
[0024] Cov(X) = (X–X)T(X–X).
[0025] Then Eigen or Singular Value Decomposition is applied to the covariance matrix to obtain the eigenvalues vectorband anmxnmatrixVof their corresponding eigenvectors, which are also called principal components (PC). The PC vectors are perpendicular to each other and are normalized, i.e. their length is one. The eigenvalues are variances in the direction of the corresponding PC, sorted in descending order, and are also called the modes of variation. One can reduce data dimensionality significantly without losing much of the variation by taking only the firstkeigenvalues, which sum up to some 0.96-0.99 of the total variance. In this way the size of matrixVbecomeskxn. PCA can be used to transform original dataxin a new coordinate system with axes the PC vectors with the following equation:
[0026] [Math. 3]
[0027] c=V(x–x)
[0028] The transformed vectorcis of lengthkand is also called mode coefficients of the PCA model. Having a coefficient vectorc, one can go back to the original data space by applying Math. 4.
[0029] [Math. 4]
[0030] x = x + VTc
[0031] xis an approximation of the original vectorx, though the approximation error can be very small, if only several percent of the total variance has been discarded.
[0032] Most of the current approaches using PCA for image compression take as an input dataX(mxn) for the PCA transform the image pixel matrix ofmrow andncolumns. This does not produce good compression and good image quality because the colour values change a lot in a given row (or column) and the variance of the pixels to the mean values will be large. The present invention applies a different approach to split the image in 8x8 pixel blocks, as in the JPEG compression as the variance to the mean in these blocks is much lower than in a whole row or column. If the image dimensions are not multiples of 8, then the last row and column are repeated as many times as needed to make them multiples of 8. The mean square error (MSE) to measure the image quality. In case of a colour image whereRoGoBoare the RGB values of the original andRcGcBc– of the compressed image, then the MSE is calculated as shown in Math. 5.
[0033]
[0034] Encoding algorithm
[0035] The steps of the encoding algorithm are shown in. First the image is converted to YUV format using Math. 1. Then the luminance Y and the chrominance values UV are processed in a different way.
[0036] Luminance Y
[0037] For each 8x8 block its mean value and variance are computed. Then the blocks are split into two groups: low variance blocs Y0 with variance below a certain threshold and high variance blocks Y1 with variance above this threshold. Then PCA is applied to each of these block groups.
[0038] Chrominance values UV
[0039] Before PCA a subsampling step is applied to the chrominance values. This means that the image is partitioned in blocks and the values in each block are replaced by their average. The present invention makes it possible to use the following block sizes: 1x2, 2x1, 2x2, 2x4, 4x2, 4x4. There are two types of encoding schemes possible: the first one is quicker, but the second is more flexible and allows the user to specify a target MSE and produces a compressed image with the smallest file size for this MSE. Averaging is applied only in the slower version. First the algorithm computes the subsampling MSEs which would be introduced for each of the block types: 1x2, 2x1, 2x2, 2x4, 4x2, 4x4. If the target MSE is less than the smallest subsampling MSE multiplied by a certain factor, then no averaging is performed. Otherwise the subsampling MSEs are sorted in ascending order and the block with the last MSE smaller than the target one is selected for subsampling.
[0040] There are 4 groups of blocks (Y0, Y1, U, V) and for each of them PCA is applied to reduce the data dimensionality. The input data matricesX(see Math. 2) for all the four cases have 64 rows and the number of columns is different and equal to the number of blocks in each group. In this way the mean vector for each group consists of the average values in each block. Then PCA is applied to each data set and the mean vector, eigenvalues, eigenvectors and coefficients are computed. The coefficients are in fact the transformed dataset, see Math. 3, however they are normalized by dividing them by the square root of the corresponding eigenvalue as suggested by Ruto [NPL:18].
[0041] The means, eigenvalues, eigenvectors and coefficients are stored in the binary image file, so that an approximation of the original image can be restored at the decoding stage. However, they are first converted in the following way:
[0042] Means: Each value is a float number between 0 and 255, so it is rounded to an unsigned byte.
[0043] Eigenvalues: They are not many, usually less than 40, so they are directly stored as 32-bit floats.
[0044] Eigenvectors: Their number is equal to the number of eigenvalues, but their dimensionality is quite high – the number of blocks in the image, which can be several thousand. So it is crucial to reduce their size. The eigenvectors are normalized, i.e. their length is one, and their coordinates are in the interval [-1, 1]. The algorithm first finds the minimum and maximum of all elements in the eigenvectors matrix and then they are converted to unsigned byte as follows:
[0045] [Math. 6]
[0046] b= round((x-min) ⁄ (max-min)*range),
[0047] wherexis the original coordinate andrange= 255, so thatbis in [0, 255].
[0048] However, the size occupied by the eigenvectors can be further reduced, bearing in mind the following fact. The eigenvalues are in fact the variances in the direction of each eigenvector (principal component) and they are ordered in descending order. So, the first principal component is the most important one and encodes most of the image information. Every next PC is less important and can be encoded as byte with a lower accuracy by reducingrange:
[0049] ,
[0050] wheremaxrange= 255. Math. 7 ensures that fewer bits will be used to store the less significant principal components.
[0051] Coefficients: After normalization they are usually in the interval [-3, 3], sominandmaxcoefficient is found and they are converted to unsigned byte using Math. 6. Therangefor the coefficients was determined experimentally and in the current system it equals 63, so only 6 bits are used to store each coefficient.
[0052] All the converted numbers are stored in a binary file, which starts with a header with the following data, needed for decoding: image width and height, sizes of the subsampling blocks, the indexes of the blocks in group Y0 converted to a set of bits, where the number of bits equals to the number of blocks, in order to take less space. The min and max values for the eigenvector coordinates and coefficients are also stored in the binary file.
[0053] After that a lossless compression is applied to the binary file using the Lempel–Ziv–Markov chain algorithm (LZMA).
[0054] There are several parameters that can be used to control the MSE and the size of the compressed image. The first one is the coefficients range in Math. 6. It was determined experimentally and set to 63, but in general it influences the quality of compression and file size.
[0055] The other two are connected with the PCA models. As above mentioned the number of eigenvalues, respectively eigenvectors, can be significantly reduced by taking only the first several eigenvalues that sum up to a certain fraction of the total model variance. We denote them as follows:
[0056] kY1: the faction parameter for the PCA model of blocks Y1.
[0057] kY0: the faction parameter for the PCA model of blocks Y0. Experimentally we set it to 0.75kY1.
[0058] kUV: the faction parameter for the PCA models for the U and V blocks. So, we use the same parameter for both PCA models.
[0059] Our system offers two types of encoding, which determine these two parameters (kY1,kUV) in a different way.
[0060] Quick encoding
[0061] This is encoder is quicker, but less flexible. It just set the parameters to certain values. In our implementationkY1=0.99,kUV=0.88. Experimental results are shown in the next section. In general the user can be allowed to modify these parameters
[0062] MSE encoding
[0063] With this encoder the user specifies a target MSE and the algorithm generates an encoded image with this given MSE and with the smallest file size. In fact the two parameterskY1andkUVare determined in such a way that |imageMSE-targetMSE| < 0.5. This is performed in the following way (see Algorithm 1).
[0064] First full PCA models are computed for the Y blocks. Full means that all eigenvalues are considered. The data is transformed, i.e. mode coefficients are calculated using Math. 3, then converted to unsigned byte (Math. 6) and back to float. Models parameters (mean, eigenvectors) are also converted to unsigned byte, as described above, and then back to float. Subsampling for UV is found as described earlier and full models computed for U and V. UV coefficients and models' parameters are processed in the same way as for the Y blocks. Then in a loop for eachkY1from 1.0 to 0.8kUVhas to be found, which solves Math. 8.
[0065] [Algorithm 1]
[0066] [Math. 8]
[0067] MSE(kY1,kUV) = targetMSE
[0068] First a good initial value forkUVneeds to be found and then the secant method [NPL:19] is applied to find the root of Math. 8. First the average variance for Y blocks (varY) and average variance for UV blocks (varUV) are computed. A very good approximation of the MSE was found experimentally:
[0069] [Math. 9]
[0070] MSE = (1-kY1)*varY + (1-kUV)*varUV + MSE0,
[0071] where MSE0 is the initial mean square error for the full models, which is due to the UV subsampling and converting the models parameters and coefficients from float to byte.
[0072] Math. 9 is applied to find the initial value forkUV.Then the number of eigenvalues (resp. eigenvectors) for each PCA model is reduced so that the specified percentage of the total variance is preserved, coefficients are computed and all parameters converted to byte. The ComputeImageMSE function calculates the approximated RGB values using the PCA models and coefficients in the same way as decoding is done, and finds the mean square error in relation to the original image. As the initial value of the unknown variable is a good approximation of the root, the secant method converges quickly in 2-3 steps. Image size is computed for all pairs (kY1,kUV)that solve Math. 8 andkY1andkUVfor the minimum file size are determined.
[0073] Decoding algorithm
[0074] The steps of the decoding algorithm are shown in. The encoded file is first decompressed with LZMA algorithm, and the header, the parameters and coefficients of the four PCA models are read from the binary file and converted to float. Due to the conversion to byte and then back to float the eigenvectors' length may not be one, so they are normalized after converted to float. An approximation of the original data is computed using Math. 4 and merged to YUV image. Conversion back to the RGB space is performed as shown in Math. 10.
[0075]
[0076] The current invention produces much smaller file sizes than JPEG for small mean square errors.
[0077] The second version of the encoding algorithm of this invention can produce an image with the smallest file size for a given mean square error.
Claims
A method for lossy image compression for storing and transmitting still images over the internet, where the encoding algorithm consists of the following steps:converting the image pixels is in YUV colour space;subsampling UV values;partitioning the image in 8 x 8 pixel blocks;dividing the blocks in four groups and applying principal component analysis (PCA) to each group;transforming the original pixel data in the new space, i.e. calculating mode coefficients;converting the parameters of the PCA models and coefficients to unsigned byte and saving them in a binary file;applying Lempel–Ziv–Markov chain algorithm (LZMA) for lossless compression to obtain the final encoded file.A method as claimed in claim 1 where the U and V values are subsampled in 1x2, 2x1, 2x2, 2x4, 4x2, 4x4 blocks according to a target mean square error.A method as claimed in claim 1 and claim 2 wherein the blocks are divided in four groups as follows:Y0: all 8x8 Y blocks for which the variance is less than a certain thresholdY1: all 8x8 Y blocks for which the variance is greater than a certain thresholdU: all 8x8 U blocksV: all 8x8 V blocksA method as claimed in any of the preceding claims, where the principal component coordinates are converted from double precision floating point to unsigned byte using the following equations:b= round((x-min) ⁄ (max-min)*range)wherexis the original floating point coordinate.A method as claimed in claim 4 where the PCA mode coefficients are converted from floating point to unsigned byte using 6 bits with the following equation:c= round((x-min) ⁄ (max-min)*63)wherexis the original floating point coefficient.A method as claimed in claim 5 where all PCA parameters and coefficients are compressed using lossless LZMA algorithm and saved to an encoded image file.A method as claimed in claim 6 where the two parameters (kY1andkUV)of the PCA are set to fixed values.A method as claimed in claim 6 where the two parameters (kY1andkUV)of the PCA are determined to achieve a target MSE and guarantee the smallest file size in the following way:For eachkY1from 1 to 0.8, step -0.005,kUVstarts from initial valuekUV = 1-(targetMSE-(1-kY1)*varY-MSE) / varUVand computed in several iteration using the secant method for numerically solving non-linear equations.A method for lossy image compression for storing and transmitting still images over the internet, where the decoding algorithm consists of the following steps:decompressing the encoding image file;reading PCA parameters from a binary file;converting all parameters to floating point values;normalizing eigenvectors;computing original YUV pixels;converting YUV to RGB colour space.
