A deep learning-based secondary lossless encoding method for JPEG files
The deep learning-driven JPEG file secondary lossless encoding method solves the problem of low compression efficiency in existing JPEG files. Through fine grouping of DCT coefficients and hybrid encoding strategies, it achieves adaptive and efficient compression, which is suitable for diverse image content and compression parameters.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SANDSTONE DATA TECH CO LTD
- Filing Date
- 2026-01-19
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies for lossless secondary compression of JPEG files suffer from insufficient statistical modeling, failure to fully utilize the multidimensional and complex correlations of DCT coefficients, coarse metadata processing, poor system adaptability, and low compression efficiency.
A deep learning-based approach is used to perform frequency domain grouping and spatial rearrangement of DCT quantization coefficients in JPEG files, construct a deep learning probability estimation module, and combine a hybrid coding strategy and intelligent metadata processing to generate an accurate probability distribution and encode it, thereby optimizing the compression of the quantization table and Huffman table.
It significantly improves the compression rate of JPEG files, achieves adaptive and efficient compression, is suitable for different image content and compression parameters, and ensures lossless reconstruction.
Smart Images

Figure CN121527207B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to image data compression and deep learning technology, in particular to a JPEG file secondary lossless coding method based on deep learning. BACKGROUND
[0002] As the most widely used image compression format, JPEG files account for a large proportion in network storage and transmission. In order to further reduce storage and bandwidth costs, lossless secondary compression of the generated JPEG files has become an important technical requirement. At present, there are mainly two types of solutions in the industry, but both have significant shortcomings.
[0003] First, directly using traditional general lossless compression algorithms such as ZIP and 7Z to process JPEG files has extremely limited compression efficiency. This is because such algorithms, as general compression tools, are not optimized for the unique structure of compressed JPEG data (such as discrete cosine transform DCT quantization coefficients), and cannot effectively utilize the statistical redundancy contained therein for further compression.
[0004] Second, some JPEG-focused lossless transcoding schemes, although directly operating on DCT coefficients, have a serious lack of depth in statistical modeling. Specifically, existing schemes fail to fully exploit the complex correlations between DCT coefficients in different frequency bands and between adjacent blocks in the spatial domain, and lack the ability to understand and model the distribution characteristics of different image contents (such as natural scenery, portraits, and text) and different JPEG compression quality factors using deep learning and other methods. This directly leads to the use of static or semi-static entropy encoding methods (such as Huffman encoding) that cannot adaptively match the dynamically changing statistical characteristics brought about by specific image content and compression parameters.
[0005] In summary, the main defects of existing technologies can be summarized as three points: first, the statistical modeling is insufficient, and the multi-dimensional complex correlations of DCT coefficients cannot be fully utilized; second, the metadata processing is extensive, and there is a lack of efficient compression strategies for important metadata such as the quantization table and Huffman table in the JPEG header information, resulting in a high proportion of the overall volume after secondary compression; third, the system adaptability is poor, and the coding strategy is rigid, unable to adaptively and dynamically adjust to JPEG files of different quality factors and different content types, making it difficult to achieve compression rates close to the theoretical limit in various application scenarios.
[0006] It should be noted that the information disclosed in the above background section is only for understanding the background of the present application, and therefore can include information that does not constitute prior art known to those of ordinary skill in the art. SUMMARY
[0007] The main purpose of the present application is to overcome the defects in the background art, and provide a JPEG file secondary lossless coding method based on deep learning.
[0008] To achieve the above-mentioned purpose, the present application adopts the following technical solutions:
[0009] A JPEG file secondary lossless coding method based on deep learning, comprising the following steps:
[0010] S1. Input the JPEG file and disassemble it to obtain DCT quantization coefficients, quantization tables, Huffman tables and other metadata;
[0011] S2. Preprocess the DCT quantization coefficients, and group and spatially rearrange them according to their frequency domain characteristics;
[0012] S3. Construct a deep learning probability estimation module, based on an autoregressive model and combined with global and local context information, to generate accurate probability distribution for each group of DCT coefficients processed in step S2;
[0013] S4. Adopt a hybrid coding strategy, combine traditional coding methods with entropy coding methods based on the probability distribution obtained in step S3, and encode the DCT coefficients, and output the encoded code stream;
[0014] S5. Intelligently analyze and classify the compression of the quantization table, Huffman table and other metadata, and output the metadata encoding result;
[0015] S6. Combine the encoded code stream output in step S4 and the metadata encoding result output in step S5 to form the final compressed code stream;
[0016] S7. Decode the final compressed code stream to reconstruct a lossless file consistent with the hash of the original JPEG file.
[0017] A computer program product comprising a computer program, which, when executed by a processor, implements the JPEG file secondary lossless coding method based on deep learning.
[0018] The present application has the following beneficial effects:
[0019] The application provides a JPEG file secondary lossless coding method based on deep learning. The method performs deep learning driven probability estimation and entropy coding on DCT quantization coefficients of a coded JPEG file, combines intelligent processing of metadata, and significantly improves the compression ratio under the premise of ensuring complete lossless reconstruction of the original file. The core advantage of the method is the deep and adaptive statistical modeling capability. Unlike existing solutions, the application performs fine frequency domain grouping and spatial rearrangement on the DCT coefficients, and uses an autoregressive context reference mechanism, so that the deep learning network can fully exploit the complex multi-dimensional correlation of the coefficients in the frequency domain and the spatial domain, thereby generating more accurate probability distribution, laying a solid foundation for efficient entropy coding.
[0020] In the probability modeling layer, the application differentially processes the distribution characteristics of different frequency band coefficients. The DC and low-frequency data with flat distribution are processed by using a mixed Gaussian model, and the medium-high frequency and high-frequency data with a sharp peak distribution affected by quantization are processed by using a mixed Laplace model. This quantization-aware modeling method enables the probability model to closely match the actual statistical characteristics of the data under different compression qualities, thereby improving the compression efficiency at the source. At the same time, the system introduces a hybrid coding strategy, which can intelligently select whether to first perform traditional run-length coding on high-frequency coefficients according to the image content, and selects the optimal coding scheme through a search mechanism, thereby maintaining high compression performance when facing images with different characteristics.
[0021] In the metadata processing aspect, the application completely changes the drawbacks of the traditional scheme processing. By classifying the quantization table and the Huffman table and comparing and indexing coding with the standard table library, and compressing the residual of the non-standard table, the efficient compression of the metadata part is realized. In addition, the system provides two modes of "complete file hash lossless" and "pixel viewing lossless", which can be flexibly selected according to different application scenarios, further optimizing the overall compression ratio under the premise of ensuring the lossless of the core visual information.
[0022] The design of the application has good practicability and deployment convenience. The trained model does not depend on parameters customized for different quality factors, and its adaptive ability is endogenous in the network structure. The system ensures bit-accurate lossless reconstruction through SHA-256 hash verification, and has high reliability. The whole scheme is particularly suitable for image storage and transmission systems deployed in centralized servers sensitive to storage and bandwidth costs, and can achieve a compression ratio significantly higher than general lossless compression algorithms and existing JPEG transcoding solutions under the premise of ensuring complete data restoration, which has important practical application value.
[0023] Other beneficial effects in the embodiments of the application will be further described below. BRIEF DESCRIPTION OF DRAWINGS
[0024] Figure 1 Figure 1 is a system overall architecture diagram of the embodiment of the present application JPEG file secondary lossless encoding method.
[0025] Figure 2 is a hyperparameter model diagram of the deep learning autoregressive encoding network architecture of the embodiment of the present application.
[0026] Figure 3 is a DCT coefficient preprocessing module diagram of the deep learning autoregressive encoding network architecture of the embodiment of the present application.
[0027] Figure 4A is a first-step DC data odd-even row splitting first encoding and decoding flowchart of the efficient autoregressive main process of the embodiment of the present application.
[0028] Figure 4B Figure 4B is a second-step DC data odd-even row splitting second encoding and decoding flowchart of the efficient autoregressive main process of the embodiment of the present application.
[0029] Figure 4C Figure 4C is a final-step middle-high frequency data encoding and decoding flowchart of the efficient autoregressive main process of the embodiment of the present application.
[0030] Figure 5 is a lite-Swin Transformer module implementation diagram of the embodiment of the present application.
[0031] Figure 6 Figure 6 is a code stream file structure design diagram of the embodiment of the present application. DETAILED DESCRIPTION
[0032] The embodiments of the present application are described in detail below. It should be emphasized that the following description is only exemplary and is not intended to limit the scope of the present application and its applications.
[0033] In addition, the terms "first", "second" are only for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, the meaning of "multiple" is two or more, unless otherwise specifically limited.
[0034] The present application aims to solve the problem of insufficient efficiency of existing JPEG lossless recompression technology, and proposes a secondary lossless compression method based on deep learning probability estimation and adaptive entropy coding. By deeply mining the frequency domain / spatial domain statistical characteristics of DCT coefficients, combining intelligent metadata processing and hybrid coding strategy, the compression efficiency is significantly improved under the premise of completely lossless reconstruction, and good scene adaptability is achieved.
[0035] Reference Figures 1 to 6The embodiment of the present application provides a JPEG file secondary lossless coding method based on deep learning, which comprises the following steps:
[0036] Step S1. Input a JPEG file and disassemble it to obtain DCT quantization coefficients, a quantization table, a Huffman table and other metadata.
[0037] Step S2. Preprocess the DCT quantization coefficients, and group and spatially rearrange them according to their frequency domain characteristics.
[0038] In some embodiments, in step S2, the preprocessing of the DCT quantization coefficients specifically comprises: dividing the DCT coefficients into a plurality of frequency band groups from low to high frequency; for the low-frequency and low-to-medium-frequency coefficient groups, further splitting them according to the odd-even positions in the spatial domain to form a spatial context for autoregressive coding; for the medium-to-high-frequency and high-frequency coefficient groups, the spatial domain splitting is not performed; the coding order of each group of coefficients is from low frequency to high frequency, and the coding process of the subsequent group takes the coded previous group data as a context reference.
[0039] Step S3. Construct a deep learning probability estimation module, based on an autoregressive model and combined with global and local context information, to generate accurate probability distribution for each group of DCT coefficients processed in step S2.
[0040] In some embodiments, in step S3, the generation of accurate probability distribution specifically comprises: for DC coefficients and low-to-medium-frequency data groups, a mixed Gaussian probability model is used; for medium-to-high-frequency and high-frequency data groups, a mixed Laplace probability model is used due to the more acute distribution caused by quantization; the mixing weight, mean and scale parameters of the probability model are all generated by a deep learning network according to the input context information.
[0041] In some embodiments, the construction of the deep learning probability estimation module in step S3 comprises: first, constructing a hyperparameter model, which takes the quantization table and all DCT coefficients as input, extracts and outputs a global hyperparameter context feature through an encoder network; second, constructing a backbone network, which successively comprises a residual network module for extracting local features, a window-based Transformer module for capturing medium-range dependencies and a final convolutional layer for outputting probability parameters; the backbone network takes the global hyperparameter context feature, the coded context DCT coefficients and the quantization table information as input to generate probability distribution parameters for the current DCT coefficient group to be coded; wherein the window-based Transformer module can be discarded when processing medium-to-high-frequency and high-frequency coefficient groups to reduce the amount of calculation.
[0042] Step S4. Adopting a hybrid coding strategy, combining traditional coding methods with entropy coding methods based on the probability distribution obtained in step S3, to encode the DCT coefficients and output the encoded bitstream.
[0043] In some embodiments, the hybrid coding strategy in step S4 specifically includes: first, based on a predetermined decision condition, selecting to precode the partial high-frequency AC coefficients using traditional run-length coding and Golomb-Rice coding; then, using the entropy coding method of the probability distribution to encode all the remaining DCT coefficients; through searching or prediction, selecting between the pre-coding scheme and the deep learning entropy coding scheme, or between the hybrid scheme containing the pre-coding part and the pure deep learning entropy coding scheme, to determine the final coding strategy with compression rate as the main evaluation index; wherein, if the final strategy contains a pre-coding part, the pre-coded AC coefficient data will be input as prior information to the subsequent deep learning probability estimation module, and the coding operation for this part of data will be skipped in the final entropy coding bitstream.
[0044] Step S5. Intelligent analysis and classified compression of the quantization table, Huffman table and other metadata, outputting the metadata encoding result.
[0045] In some embodiments, the intelligent analysis and classified compression of the quantization table and Huffman table in step S5 specifically includes: comparing the input quantization table with a predefined standard quantization table set covering common quality factors, and comparing the input Huffman table with a standard Huffman table set; if there is a matching standard table, using an index value instead of the complete table data; if there is no completely matching standard table, calculating the residual between it and the closest standard table, and scanning and storing the residual after regular lossless compression.
[0046] In some embodiments, step S5 supports two lossless encoding modes: complete file hash lossless mode: all metadata are losslessly compressed and encoded, ensuring that the decoded file is completely consistent with the source file in binary; pixel viewing lossless mode: only image direction information and complete ICC color profile data are extracted from the original file for encoding, and other metadata that do not affect visual content are discarded, ensuring that the reconstructed image after decoding is consistent with the source file.
[0047] Step S6. Combining the encoded bitstream output in step S4 and the metadata encoding result output in step S5 to form the final compressed bitstream.
[0048] In some embodiments, the final compressed code stream formed in step S6 has a predefined packaging format, and the file header of the format contains: a field for identifying the DCT coefficient frequency band grouping configuration, flag bits for indicating whether the quantization table and Huffman table adopt standard tables or custom tables, fields for recording the length of the AC pre-encoding code stream and the length of the metadata compressed code stream, and a header checksum; the code stream body contains the AC pre-encoding code stream, the metadata compressed code stream, the custom table code stream, and the main encoding code stream based on deep learning probability estimation in a predefined order.
[0049] Step S7. Decoding the final compressed code stream to reconstruct a lossless file consistent with the original JPEG file hash.
[0050] In some embodiments, the deep learning-based secondary lossless encoding method for JPEG files further comprises a model training step, specifically comprising: first, training the network on a training data set using a fixed initial frequency band grouping configuration to obtain the basic model weight; second, enabling the dynamic frequency band grouping decision network, jointly training with the probability estimation network, and classifying the training data according to the output of the dynamic grouping decision network; finally, based on the classification results, jointly optimizing the dynamic grouping decision network and the probability estimation network for each type of data to determine the optimal frequency band grouping configuration suitable for the data.
[0051] The deep learning-based secondary lossless encoding method for JPEG files effectively overcomes the technical defects of traditional general compression algorithms, such as limited compression efficiency for JPEG files, insufficient mining of DCT coefficient statistical characteristics in existing transcoding schemes, and the inability of entropy encoding methods to adapt to changes in image content and quality factors. Through deep integration of deep learning-driven probability estimation, adaptive hybrid encoding strategy, and intelligent metadata processing, the method significantly improves the secondary compression rate of JPEG files while ensuring bit-accurate lossless reconstruction, and has wide adaptability to diverse image content and compression parameters.
[0052] The following further describes specific embodiments of the present application, algorithm examples, and experimental verification.
[0053] A JPEG secondary lossless encoding method can include DCT coefficient preprocessing, deep learning probability estimation, hybrid traditional encoding and metadata intelligent processing modules. The JPEG secondary lossless encoding is realized through the cooperation of the above modules. First, the DCT coefficient preprocessing module groups the DCT quantization coefficients obtained by decoding in frequency and rearranges them in space, to build a structured data basis for subsequent encoding. Next, the deep learning probability estimation module generates accurate probability distribution for each group of coefficients according to the context information formed thereby. Then, the hybrid traditional encoding module selectively uses traditional encoding methods to compress part of the high-frequency coefficients in advance based on search or pre-judgment, and compares the encoding results based on deep learning, to select the optimal compression strategy. At the same time, the metadata intelligent processing module classifies and efficiently compresses the quantization table and Huffman table, and can adapt to the complete file hash lossless and pixel viewing lossless modes according to the requirements. The above modules are sequentially connected and jointly act, so as to realize the secondary efficient compression of the JPEG file under the premise of ensuring complete lossless reconstruction.
[0054] As Figure 1 shown in the system overall architecture, the complete process of data preprocessing, core encoding and decoding, metadata processing and verification output, etc. is exhibited, including the data interaction path and code stream combination logic among the modules.
[0055] According to the method of the application, the overall architecture of the system sequentially includes four main stages. First, in stage one, the input original JPEG file is disassembled by the parser. This process separates the file into core metadata, compression parameter table, compressed data stream and other auxiliary parameters. Among them, the core metadata includes basic information such as image size, color space, sampling factor and restart interval; the compression parameter table mainly includes the quantization table and Huffman coding table; the compressed data stream includes the DC and AC coefficient entropy encoding data to be secondary compressed, which will be restored to DCT quantization coefficients using existing open source decoder (such as libjpeg) as the core object for subsequent processing. Then, the system enters stage two, i.e. the core encoding and decoding stage, which will use deep learning probability estimation and hybrid encoding strategy to efficiently compress the coefficients. Next, in stage three, the system intelligently processes and specially compresses the extracted metadata. Finally, in stage four, the system completes verification and output, and ensures that the output file is completely consistent with the original JPEG file through reconstruction and verification, thereby forming a complete secondary lossless encoding process.
[0056] The overall implementation architecture of the method of the present application starts from a full parsing of the original JPEG file. Specifically, first, the input file is disassembled by a JPEG file parser into multiple logical parts. These parts mainly include: core metadata containing image size, color space, sampling factor, restart interval and component order definition; compression parameter table consisting of luminance and chrominance quantization tables, and DC and AC Huffman coding tables of each component; compressed data stream as the main object of secondary compression, which contains the entropy coded data of DC and AC coefficients to be decoded (including the coded representation of zero run and non-zero coefficients), which will be restored to DCT quantized coefficients by the existing standard decoder; in addition, other auxiliary parameters such as restart markers, scan head parameters, etc. are also included to ensure the complete reconstruction of the file. This disassembly stage provides a structured data basis for the subsequent deep compression processing.
[0057] In the preferred embodiment, the core coding stage first pre-processes the DCT quantized coefficients obtained by decoding, and this method is suitable for both luminance and chrominance components in JPEG data. Figure 3The network architecture of the DCT coefficient preprocessing module is detailed. Through the cooperation of ResBlock stacking, global average pooling, and multiple convolution layers, the grouping and channel configuration of high and low frequency coefficients are realized, and the odd-even row splitting logic of DC data and medium-low frequency data is also embodied. In order to balance processing speed and coding efficiency, DCT coefficients can be divided into multiple groups according to frequency from low to high, with an initial default of 4 groups. The specific grouping suggestion is to include 1, 7, 21, and 35 coefficients, and to build an autoregressive-based context reference mechanism: first, the lowest frequency data is encoded and decoded, then the group data is used as a reference context input to the network to generate the encoding and decoding parameters of the next group (the next low frequency) data, and the iteration is performed in this order until the last high frequency parameter is encoded. In practical applications, the number of groups can be expanded to 64. Because the quantization step size configuration of different JPEG files will cause the data distribution of the quantized DCT coefficients to be scalable (for example, the smaller the quantization quality factor, the more values fall within the range of 0~10, and this trend extends to low frequencies), the system should allocate variable channel configurations to each group when processing data with different contents and different quantization quality factors. For convolutional networks, the number of channels is fixed, so a feasible mechanism is to preset a sufficient number of channels for the convolutional layers of each group; when the actual input data is insufficient, the subsequent channels are zero-padded. A specific implementation is to preset 40 input channels (an integer multiple of 8 to adapt to the efficient operation of some hardware) for each group, and the number of output channels is set to 160 to carry the parameters of the hybrid probability model. The number of groups actually written into the code stream is stored using three unsigned 8-bit integers. Finally, the actual number of groups used will be recorded in the encoded code stream. This dynamic grouping mechanism is implemented by a lightweight router network that takes DCT coefficients as input and directly generates the channel number configuration of each group.
[0058] The inference of the deep learning network relies on a hyperparameter model that provides globally representative context features for all DCT coefficients to be encoded and can directly generate the probability parameters required for DC coefficient encoding and decoding. Figure 2The super parameter model architecture of deep learning autoregressive coding is displayed, taking DC data, AC data and quantization table as input, and outputting global super parameter context features through feature extraction and conversion of ViT-32 and convolution / deconvolution layers, providing global reference for subsequent probability estimation. In a preferred embodiment: taking a 512x512 pixel image block as an encoding unit, only the DC data is designed using a lightweight ViT-32 architecture (see Table 1 for example specific configuration), and an autoencoder-based super network is used to process all data. On the basis of frequency domain grouping, the data in each group is further spatially divided to form a context. Because the correlation of low-frequency data in the spatial domain is much higher than that of high-frequency data, the order based on the odd-even cross position is used for encoding and decoding on DC data and medium-low frequency data; while for medium-high frequency and high frequency data, no spatial domain splitting is performed to balance the computing power and performance of encoding and decoding. Figures 4A to 4C The efficient autoregressive main process is jointly displayed, which completes the group-by-group encoding and decoding process from low-frequency to high-frequency coefficients through dynamic optional input design, context transmission of pre-decoding data, and combined hybrid Gaussian / Laplace entropy model. Among them, Figure 4A The first step of the efficient autoregressive main process (the first part of the encoding and decoding process of the DC data odd-even row splitting) is shown, Figure 4B The second step of the efficient autoregressive main process (the second part of the encoding and decoding process of the DC data odd-even row splitting) is shown, Figure 4C The last step of the efficient autoregressive main process (the encoding and decoding process of medium-high frequency data) is shown. The efficient autoregressive main process repeatedly generates multiple rounds of encoding and decoding parameters in the order of low frequency to high frequency, Figure 4B and Figure 4C The intermediate steps between them are omitted and not expanded.
[0059] Table 1: ViT-32 architecture parameter configuration
[0060] The probability estimation network of each group of data is composed of three groups of designs in the following order: first, a small number of ResNet blocks are stacked to extract sufficient spatial domain local features; second, a lightweight SwinTransformer module based on a 4x4 window is used to supplement spatial domain local features with medium receptive fields. Figure 5The specific implementation scheme of the SwinTransformer module is shown, including 4x4 Patch division, non-shift Swin Transformer calculation, attention mechanism, and up-sampling fusion, etc. to realize efficient capture of local features. Finally, the probability parameters of the target data are output through a 3x3 convolution layer. In order to further balance the computing power and performance, the above network design can discard the Swin Transformer module when processing medium and high frequency data to reduce the amount of calculation; at the same time, due to the higher quantization degree of high frequency data, the performance loss is smaller.
[0061] In terms of probability distribution modeling, the system adopts a differentiated modeling strategy for the distribution characteristics of different frequency band DCT coefficients. For the DC coefficient and the low-frequency data group with relatively flat distribution, a mixed Gaussian probability model is used for modeling, and its probability density function is expressed as: .
[0062] And for the medium and high frequency and high frequency data which show more peak distribution due to the influence of quantization, a mixed Laplace probability model is used, and its probability density function is: .
[0063] The parameters of the model are generated by network inference.
[0064] In actual encoding, the system introduces a hybrid traditional encoding module to improve compression efficiency. The core strategy is that when the quantization parameter is large, resulting in a large number of continuous zeros in the DCT coefficient, the traditional run-length encoding (RLE) combined with Golomb-Rice encoding can often achieve very high compression ratio. Therefore, the system sets an efficient traditional encoding budget, which can try to use RLE and Golomb-Rice encoding for pre-encoding part of the high-frequency AC coefficients before the aforementioned deep learning encoding. The applicable threshold of pre-encoding can be set to 1 / 10 of the size of the source JPEG file, and can be used as an option to adjust the encoding speed. The search range of the strategy is usually set based on the proportion of the source file size (such as not enabled, 1 / 20, 1 / 10, 1 / 5). Then, the remaining DC and AC coefficients continue to be encoded by the conventional deep learning probability encoding, and the pre-encoded AC part can be input into the network as global prior information and directly skip the entropy encoding process of this part of data. The theoretical basis of this approach is that the sparse mode of high-frequency coefficients reflects the edge and texture information of the image, which constrains the accurate value of the low-frequency coefficients. Considering that the above strategy is not optimal in all cases, the system provides a flexible decision-making mechanism: when the encoding computing power and time is sufficient, the pure deep learning encoding strategy and the hybrid strategy containing traditional pre-encoding can be searched for compression ratio, and the better one is selected; also, according to the prediction of the type of the current batch of data, the strategy to be used can be determined in advance.
[0065] In terms of metadata processing, the system intelligently classifies and compresses the metadata in JPEG files. These metadata are divided into three levels according to their importance: Level 1 is absolutely necessary metadata, including quantization tables (usually 2-4, each containing 64 16-bit integers), Huffman tables (2 for DC and AC tables, each with up to 256 entries), image size, color space, sampling factor, and restart interval, and the absence of any of them will result in incorrect decoding; Level 2 is encoding parameter metadata, including Huffman table selection, DCT coefficient arrangement order, DC difference encoding initial value, etc., which affects the specific bitstream structure; Level 3 is optional metadata, such as EXIF information, ICC color profile, etc., which affects file compatibility but is not fatal. Based on different application goals, the system provides two lossless encoding modes: one is the "pixel viewing lossless" mode, which only ensures that Level 1 and Level 2 metadata are correctly encoded to ensure that the reconstructed picture content is consistent; the second is the "complete file hash lossless" mode, which encodes all three levels of metadata to ensure that the decoded file and the source file hash are completely consistent. In the complete file hash lossless mode, Brotli algorithm is used for lossless encoding of all metadata (except quantization tables and Huffman tables). In the pixel viewing lossless mode, the orientation information is obtained by extracting the Orientation label in EXIF, and the ICC color profile is completely retained. The choice of mode is completely determined by user configuration.
[0066] For the compression of quantization tables, the system takes advantage of their highly standardized characteristics. By establishing an index containing 128 commonly used quantization tables (which cover the 100 quality factors corresponding to the quantization tables commonly used by libjpeg), only 7 bits are needed to index the corresponding table, thereby greatly saving code stream space. Specifically, the luminance and chrominance components each require an unsigned 8-bit integer to index their corresponding 100 standard quantization tables, and after successful index matching, the standard table is directly called without additional compression operations. If a non-standard quantization table is encountered, the nearest neighbor matching method is used: the Manhattan distance (L1 distance) is used as the criterion to find the closest table in the standard table; then the difference (residual) between the non-standard table and the standard table is calculated, and the Zigzag order defined by the JPEG standard (T.81A3.6) is used to scan the residual; finally, the default compression level (such as Zlib level 6) is used for lossless compression and storage, which can also significantly reduce the data volume.
[0067] The processing of Huffman table follows similar principles. The system first determines whether the four standard tables defined in ISO / IEC 10918-1 Annex C (one DC and one AC table for luminance and chrominance, respectively) are used, and records this using a 4-bit flag. For custom Huffman tables, the residual between the custom table and the corresponding standard table format is calculated, and this residual is conventionally losslessly compressed. The residual between a custom Huffman table and a standard table is calculated as: residual = standard table - custom table. This residual is also processed using a conventional lossless compression algorithm (e.g. Zlib, default level). In this way, up to four Huffman tables are efficiently encoded by the system.
[0068] Finally, the system includes a bit-exact verification module. The core requirement of this module is to perform a hash consistency check on the reconstructed JPEG file after decoding the secondary encoding, to ensure that it is identical to the original file. The specific reconstruction implementation can be achieved using open-source or standard methods.
[0069] The training process of the network is carried out in multiple stages in order. First, in the first training period, a large-scale dataset is used for training, at this time the decision network (multi-expert module) of dynamic DCT frequency group division is not enabled, and the number of grouping channels for low frequency, medium-low frequency, medium-high frequency and high frequency is fixed as 1, 7, 21, 35, the training target is to obtain a basic model weight. Subsequently, in the second training period, the training of the multi-expert module is released; after the training is completed, according to the channel number characteristics output by the module, the training data is divided into N categories. Finally, based on the average distribution characteristics of the N categories of data, the multi-expert module is retrained jointly, aiming to determine the optimal low frequency, medium-low frequency, medium-high frequency and high frequency grouping number for each category of data. The training dataset used is derived from public resources such as DIV2K, Unsplash and Flickr2K, totaling 100,000 images, with a resolution of 2K as the main. In the preprocessing stage, the images are cropped to 512x512 blocks, and libjpeg is used to encode in the quality factor range of 10 to 100 to construct training samples. The training batch size is set to 32, the loss function is the estimated codeword size, and the optimizer uses Adam (β1=0.9, β2=0.999). The network parameters are initialized using Kaiming uniform distribution. The training uses cosine annealing learning rate scheduling, the warm-up phase is 20,000 steps, and the total training steps are divided into 1.5 million, 0.5 million and 1 million steps.
[0070] In terms of training deployment and verification implementation, the server hardware configuration adopted in the training stage includes two Intel Gold 5218 CPUs, four 4090 GPUs, eight 32 GB memories, and one 4T SSD solid state disk. The training process does not involve specific parallel processing strategies, and no additional optimization operations (such as quantization or pruning) are performed on the model inference. To verify the losslessness of the encoding, the system uses the SHA-256 algorithm to calculate the hash value of the entire reconstructed JPEG file to ensure complete consistency with the source file. If the verification fails, it is considered to fail the verification, but the specific failure processing mechanism and file reconstruction implementation (for example, the method of jpeg-lepton can be used by default) are not within the scope of the core design of the algorithm. Regarding the structure of the compressed code stream, the generated code streams A, B, C, and D are continuous pure data streams, and different combinations (such as A+B or A+C+D) are determined by the specific strategy of the hybrid encoding module. The overall encapsulation format follows an independent file header design, and the structure design of the overall encoded file is as shown in Figure 6 During the model inference process, the system does not dynamically load different model parameters for different quality factors or image content, and the balance between computing power and compression rate is only achieved through the search strategy in the aforementioned hybrid traditional encoding module regarding whether to enable AC pre-encoding. The training convergence determination of the model is mainly based on the fixed step training stage design. In the final training stage, the iteration can be extended and the learning rate can be kept constant. When the compression performance on the test set fluctuates by less than 0.1% within 100,000 consecutive training steps, it is determined that the model has converged. In this way, stable performance is obtained while avoiding overfitting.
[0071] The embodiment of the present application also provides a storage medium for storing a computer program, which is executed to perform at least the method described above.
[0072] The embodiment of the present application also provides a control device, which includes a processor and a storage medium for storing a computer program; wherein the processor is used to execute the computer program to perform at least the method described above.
[0073] The embodiment of the present application also provides a processor, which executes a computer program to perform at least the method described above.
[0074] The storage medium can be implemented by any type of nonvolatile storage device, or a combination thereof. The nonvolatile memory can be a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), a Ferromagnetic Random Access Memory (FRAM), a Flash Memory, a magnetic surface storage, an optical disc or a Compact Disc Read-Only Memory (CD-ROM). The magnetic surface storage can be a magnetic disc memory or a magnetic tape memory. The storage medium described in the embodiments of the present application is intended to include, but is not limited to, these and any other suitable type of memory.
[0075] In several embodiments provided by the present application, it should be understood that the disclosed system and method can be implemented in other manners. The described device embodiments are merely schematic, and the division of the units is merely a logical function division. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed coupling or direct coupling or communication connection between the components can be indirect coupling or communication connection through some interface, device or unit, and can be electrical, mechanical or other forms.
[0076] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., can be located in one place or distributed on a plurality of network units; some or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.
[0077] In addition, each functional unit in the embodiments of the present application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in the form of hardware, or in the form of hardware plus software functional units.
[0078] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction related hardware, and the foregoing program can be stored in a computer readable storage medium, and the program performs the steps of the above-mentioned method embodiments when executed; and the foregoing storage medium includes a mobile storage device, a read-only memory (ROM), a random access memory (RAM), a magnetic disc or an optical disc and various storage medium capable of storing program codes.
[0079] Alternatively, the integrated unit of the present application can be stored in a computer readable storage medium if it is realized in the form of a software function module and sold or used as an independent product. Based on such understanding, the technical solutions of the embodiments of the present application can be embodied in the form of a software product, and the computer software product is stored in a storage medium, includes several instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the methods described in the embodiments of the present application. The foregoing storage medium includes a mobile storage device, a ROM, a RAM, a magnetic disc or an optical disc and various storage medium capable of storing program codes.
[0080] The methods disclosed in the several method embodiments provided by the present application can be combined arbitrarily without conflict to obtain new method embodiments.
[0081] The features disclosed in the several product embodiments provided by the present application can be combined arbitrarily without conflict to obtain new product embodiments.
[0082] The features disclosed in the several method or device embodiments provided by the present application can be combined arbitrarily without conflict to obtain new method embodiments or device embodiments.
[0083] The above is a further detailed description of the present application in combination with specific preferred embodiments, and the specific implementation of the present application cannot be limited to these descriptions. For those skilled in the art of the present application, without departing from the concept of the present application, a number of equivalent substitutions or obvious modifications can be made, and the performance or use is the same, which should be regarded as belonging to the protection scope of the present application.
Claims
1. A deep learning-based method for secondary lossless encoding of JPEG files, characterized in that, Includes the following steps: S1. Input a JPEG file and decompose it to obtain DCT quantization coefficients, quantization table, Huffman table and other metadata; S2. The DCT quantization coefficients are preprocessed and grouped and spatially rearranged according to their frequency domain characteristics; S3. Construct a deep learning probability estimation module. Based on an autoregressive model and combined with global and local contextual information, generate accurate probability distributions for each group of DCT coefficients processed in step S2. The construction of the deep learning probability estimation module in step S3 includes: constructing a hyperparameter model, which takes the quantization table and all DCT coefficients as input, extracts and outputs a global hyperparameter contextual feature; constructing a backbone network consisting of a residual network module, a lightweight Swing Transformer module, and convolutional layers stacked sequentially; the backbone network takes the global hyperparameter contextual feature, the encoded contextual DCT coefficients, and the quantization table information as input, and generates probability distribution parameters for the current group of DCT coefficients to be encoded. S4. A hybrid coding strategy is adopted, which combines the traditional coding method with the entropy coding method based on the probability distribution obtained in step S3 to encode the DCT coefficients and output the encoded bitstream; S5. Perform intelligent analysis, classification, and compression on the quantization table, Huffman table, and other metadata, and output the metadata encoding results; S6. Combine the encoded bitstream output in step S4 with the metadata encoding result output in step S5 to form the final compressed bitstream; S7. Decode the final compressed bitstream to reconstruct a lossless file that matches the hash of the original JPEG file.
2. The deep learning-based JPEG file secondary lossless encoding method as described in claim 1, characterized in that, Step S2, specifically the preprocessing of the DCT quantization coefficients, includes: The DCT coefficients are divided into multiple groups according to their frequency from low to high. For the low-frequency and mid-low-frequency coefficient groups, they are further split in the spatial domain according to their odd and even positions to form a spatial context for autoregressive coding. The coding order of the coefficients in each group is from low frequency to high frequency, and the coding process of the subsequent groups uses the data of the encoded preceding groups as context references.
3. The deep learning-based lossless encoding method for JPEG files as described in claim 1, characterized in that, In step S3, generating the precise probability distribution specifically includes: A Gaussian mixture probability model was used for the DC coefficients and the low-to-medium frequency data sets. A hybrid Laplace probability model was used for medium- and high-frequency data sets; The parameters of the probability model are generated by a deep learning network based on the input context information.
4. The deep learning-based JPEG file secondary lossless encoding method as described in claim 1, characterized in that, The hybrid coding strategy in step S4 specifically includes: For high-frequency AC coefficients, traditional run-length encoding and Columbus-Rice encoding are used for precoding; For all remaining DCT coefficients, entropy coding method of the probability distribution is used for encoding; Comparing the compression ratios of the two encoding schemes, the scheme with the better compression ratio is selected as the final output. If the traditional precoding scheme is selected, the precoded AC coefficients will be used as prior information input to the subsequent deep learning probability estimation module, and they will no longer participate in entropy encoding.
5. The deep learning-based JPEG file secondary lossless encoding method as described in claim 1, characterized in that, Step S5, specifically the intelligent analysis and classification compression of the quantification table and the Huffman table, includes: The input quantization table and Huffman table are compared with a predefined set of standard tables. If a matching standard table exists, the index value is used to replace the complete table data; If no matching standard table exists, the residual between the table and the closest standard table is calculated, and the residual is stored in a lossless compressed manner.
6. The deep learning-based JPEG file secondary lossless encoding method as described in claim 1, characterized in that, Step S5 supports at least two lossless encoding modes: Complete file hash lossless mode: All metadata is losslessly compressed and encoded to ensure that the decoded file is completely identical to the source file; Pixel-wise lossless viewing mode: Only the orientation and ICC color profile metadata directly related to the image display are retained and encoded to ensure that the decoded image content is consistent with the source file.
7. The deep learning-based JPEG file secondary lossless encoding method as described in claim 1, characterized in that, The final compressed bitstream formed in step S6 has a predefined encapsulation format. The file header of this format includes at least: a field for identifying the number of groups, a flag for indicating whether the quantization table and Huffman table use the standard table, a field for recording the length of each encoded part, and a header checksum; the bitstream body contains, in sequence, the metadata compressed bitstream, the custom table bitstream, and the DCT coefficient encoded bitstream.
8. The deep learning-based JPEG file lossless encoding method according to any one of claims 1 to 7, characterized in that, It also includes the model training step, specifically including: Train the network on the dataset using a fixed-frequency grouping configuration to obtain the basic weights; A dynamic frequency grouping decision network is enabled for joint training, and the training data is classified according to its output. Based on the classification results, a dynamic frequency grouping decision network and a probability estimation network are jointly optimized for each data class to determine the optimal frequency grouping strategy for that data class.
9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the deep learning-based JPEG file secondary lossless encoding method as described in any one of claims 1-8.
Citation Information
Patent Citations
Adaptive JPEG lossless transcoding method, system and device and storage medium
CN116980626A
Image processing method and device thereof
WO2022028197A1