Image encoding method and apparatus

CN122994492APending Publication Date: 2026-10-27QINGDAO HI-IMAGE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510543859.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-27
Publication Date
2026-10-27

AI Technical Summary

Technical Problem

[0005]为解决图像编码的灵活性差的问题,本实施例提供了一种图像编码方法及装置

Benefits of technology

[0038]上述技术方案中的一个技术方案具有如下优点或有益效果:通过将编码压力与预设的第一阈值和第二阈值进行比较,本公开实施例能够灵活地选择适应当前编码压力的编码模式。在编码压力较低时,采用最小编码损失的编码模式,能够最大程度地保留图像的细节和质量。当编码压力适中时,选择最小率失真代价的编码模式,旨在平衡图像质量与编码数据量,确保图像在可接受的失真范围内达到最优的压缩效果。而当编码压力过高时,则切换到最小编码数据量的编码模式,优先减少编码数据量,以应对带宽或存储空间的限制,从而保证了编码过程在不同压力情境下的适应性和灵活性。这种动态调整编码模式的方法,不仅提升了编码效率,还有效增强了编码系统的鲁棒性,使其在各种应用场景中均能表现出色。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122994492A_ABST
    Figure CN122994492A_ABST
Patent Text Reader

Abstract

The embodiment of the present disclosure provides an image coding method and device, the method comprises the following steps: dividing an input image into a plurality of macroblocks, the macroblocks comprising a first macroblock and a second macroblock adjacent to each other; coding the first macroblock by using a first coding parameter; after the coding of the first macroblock is completed, calculating a coding pressure, the coding pressure being a cumulative difference between an actual data amount of the coded macroblock after coding and a budget data amount; if the coding pressure reaches a pressure threshold, calculating a first quality parameter of the first macroblock, and adjusting the first coding parameter by using Bayesian optimization according to the first quality parameter to obtain a second coding parameter, wherein a target function of the Bayesian optimization is a function of an image quality parameter with respect to a coding parameter; determining a target coding mode corresponding to the coding pressure; and coding the second macroblock by using the second coding parameter and the target coding mode. The embodiment of the present disclosure improves the adaptive level of the code rate control.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of image coding technology, and in particular to an image coding method and apparatus. Background Technology

[0002] In image encoding, bitrate is a crucial indicator affecting compression performance. If the bitrate is too low, while the compression ratio increases, it can lead to loss of image detail, blockiness, or blurring. Conversely, if the bitrate is too high, although more detail can be preserved, the compression ratio decreases, potentially wasting storage or transmission resources. Therefore, in practical applications, it is necessary to select an appropriate bitrate based on encoding requirements, striking a balance between compression ratio and visual quality.

[0003] In related technologies, bitrate adjustment can be achieved during the encoding process by switching between different encoding modes. Different encoding modes correspond to different encoding parameters, which can be used to control the bitrate. After switching encoding modes, the unencoded image data is encoded using the switched encoding parameters, allowing the entire image to reach the expected bitrate requirement after encoding. For example, during the encoding process, if the current bitrate is lower than a preset value, it switches to a high bitrate mode; conversely, it switches to a low bitrate mode.

[0004] However, the encoding parameters of the above-mentioned different encoding modes are usually fixed values, which makes it difficult to adapt to complex and ever-changing image content. This can easily lead to low image quality or high bit rate after encoding, failing to meet the ever-increasing encoding requirements for visual quality and compression rate. Summary of the Invention

[0005] To address the problem of poor flexibility in image encoding, this embodiment provides an image encoding method and apparatus.

[0006] In some embodiments, an image encoding method is provided, including:

[0007] The input image is divided into multiple macroblocks, and each macroblock includes an adjacent first macroblock and second macroblock.

[0008] The first macroblock is encoded using the first encoding parameters;

[0009] After the first macroblock is encoded, the encoding pressure is calculated. The encoding pressure is the cumulative difference between the actual amount of data and the budgeted amount of data after encoding of the encoded macroblock.

[0010] If the encoding pressure reaches the pressure threshold, the first quality parameter of the first macroblock is calculated. Based on the first quality parameter, the first encoding parameter is adjusted through Bayesian optimization to obtain the second encoding parameter. The objective function of Bayesian optimization is a function of the image quality parameter of the macroblock with respect to the encoding parameter.

[0011] Determine the target encoding mode corresponding to the encoding pressure;

[0012] The second macroblock is encoded using the second encoding parameters and the target encoding mode.

[0013] One of the above technical solutions has the following advantages or beneficial effects: In this embodiment, after the encoding of the first macroblock is completed, the encoding pressure is determined based on the cumulative difference between the actual data volume and the budgeted data volume of the encoded macroblock. The encoding pressure is used to determine the target encoding mode and trigger the adjustment of encoding parameters. If the encoding pressure is too high, the target encoding mode corresponding to the encoding pressure may lead to lower image quality. To ensure image quality, the first encoding parameters are optimized using a function of the image quality parameters with respect to the encoding parameters as the objective function to obtain the second encoding parameters. This allows the second macroblock encoded according to the second encoding parameters to maintain high image quality while effectively reducing the encoding pressure, ensuring the stability and efficiency of the overall encoding process.

[0014] Furthermore, since the second macroblock and the first macroblock are adjacent macroblocks, the second coding parameters obtained by optimizing the first coding parameters based on the first quality parameters of the first macroblock can more accurately adapt to the image content of the second macroblock, thereby improving the adaptive level of image quality and bit rate control and enhancing the flexibility of image coding.

[0015] Compared with the prior art, the embodiments of this disclosure achieve a dynamic balance between coding efficiency and image quality, significantly improving the adaptability and robustness of the coding system and providing a reliable guarantee for high-definition image transmission.

[0016] In some embodiments, an image encoding method is provided, which obtains a second encoding parameter by adjusting a first encoding parameter through Bayesian optimization, including:

[0017] The pre-trained Gaussian process model is optimized using the first encoding parameter and the first image quality parameter, wherein the Gaussian process model is used to fit the objective function;

[0018] Based on the optimized Gaussian process model, the first encoding parameters are adjusted through the acquisition function to obtain the second encoding parameters.

[0019] One of the above technical solutions has the following advantages or beneficial effects: By fitting the objective function using a Gaussian process model, the image quality that may be obtained under different coding parameters can be accurately predicted, thereby guiding the adjustment of coding parameters and effectively avoiding image quality fluctuations caused by blind adjustments, thus improving the stability and efficiency of the coding process. The application of a pre-trained model further enhances the accuracy of coding parameter optimization, ensuring high-quality image output under different coding scenarios.

[0020] The application of pre-trained models further enhances the accuracy of encoding parameter optimization.

[0021] In some embodiments, an image encoding method is provided, wherein the kernel function of the Gaussian process model is determined based on the ratio of the mean square error corresponding to two sets of encoding parameters to the maximum pixel value, wherein the maximum pixel value is the maximum pixel value corresponding to the bit depth of the input image.

[0022] One of the above technical solutions has the following advantages or beneficial effects: Since PSNR also involves the calculation of mean square error, by calculating the mean square error in the Gaussian kernel function, the change in the parameter vector can better reflect the change in PSNR, thus achieving an effective correlation between image quality and coding parameters. Normalizing the mean square error by using the maximum pixel value ensures the accuracy and adaptability of parameter adjustment under different pixel values, further optimizing compression ratio control and improving coding efficiency.

[0023] In some embodiments, an image encoding method is provided to calculate a first image quality parameter of a first macroblock, including:

[0024] Calculate the peak signal-to-noise ratio of the first macroblock in the encoded image and the uncoded image;

[0025] The square root of the peak signal-to-noise ratio is calculated to obtain the first image quality parameter.

[0026] One of the above technical solutions has the following advantages or beneficial effects: Peak signal-to-noise ratio (PSNR), as an important indicator for measuring image quality, can intuitively reflect the degree to which the encoding process preserves image quality. By calculating the PSNR of the images before and after encoding and taking its square root as the first image quality parameter, the change in image quality parameter caused by changes in encoding parameters is made more gradual. This avoids drastic changes in image quality parameters due to small differences in parameter vectors, which could affect the optimization process of the Gaussian model. This improves the robustness of encoding parameter adjustment, ensures that image quality remains stable during dynamic changes, and further enhances the overall performance of the encoding system and the user experience.

[0027] In some embodiments, an image encoding method is provided, which adjusts a first encoding parameter through an acquisition function to obtain a second encoding parameter, including:

[0028] The candidate encoding parameters corresponding to the first encoding parameter are determined by the acquisition function;

[0029] Based on the optimized Gaussian process model, the predicted values ​​of the objective function for the candidate coding parameters are determined.

[0030] Based on the predicted value and the maximum value of the objective function, the expected improvement value of the candidate coding parameters is calculated, where the maximum value of the objective function is the maximum value of the square root of the peak signal-to-noise ratio;

[0031] The candidate coding parameter corresponding to the largest expected improvement value is determined as the second coding parameter.

[0032] One of the above technical solutions has the following advantages or beneficial effects: By intelligently filtering candidate coding parameters through an acquisition function and predicting their objective function values ​​using an optimized Gaussian process model, potentially better coding parameters can be efficiently located. By calculating the expected improvement value, the adjustment process becomes more focused on those coding parameters most likely to bring significant image quality improvements, thereby accelerating the optimization process of coding parameters. Furthermore, defining the maximum value of the objective function as the maximum value of the square root of the peak signal-to-noise ratio provides a clear and reasonable benchmark for calculating the expected improvement value, further ensuring the effectiveness and accuracy of coding parameter adjustment.

[0033] In some embodiments, an image encoding method is provided, wherein the second encoding parameter includes a first threshold and a second threshold, and the target encoding mode corresponding to the encoding pressure is determined, including:

[0034] The encoding pressure is compared with a first threshold and a second threshold, and the first threshold is less than the second threshold.

[0035] If the coding pressure is less than or equal to the first threshold, the target coding mode is determined to be the coding mode with the minimum coding loss;

[0036] If the coding pressure is between the first and second thresholds, the target coding mode is determined to be the coding mode with the minimum rate-distortion cost;

[0037] If the encoding pressure is greater than the second threshold, the target encoding mode is determined to be the encoding mode with the minimum amount of encoded data.

[0038] One of the above technical solutions has the following advantages or beneficial effects: By comparing the encoding pressure with a preset first threshold and a second threshold, the embodiments of this disclosure can flexibly select an encoding mode that adapts to the current encoding pressure. When the encoding pressure is low, the encoding mode with the minimum encoding loss is adopted, which can preserve the details and quality of the image to the greatest extent. When the encoding pressure is moderate, the encoding mode with the minimum rate-distortion cost is selected, aiming to balance image quality and the amount of encoded data, ensuring that the image achieves the optimal compression effect within an acceptable distortion range. When the encoding pressure is too high, the encoding mode with the minimum amount of encoded data is switched to, prioritizing the reduction of the amount of encoded data to cope with bandwidth or storage space limitations, thereby ensuring the adaptability and flexibility of the encoding process under different pressure situations. This method of dynamically adjusting the encoding mode not only improves the encoding efficiency but also effectively enhances the robustness of the encoding system, enabling it to perform well in various application scenarios.

[0039] In some embodiments, an image encoding method is provided, wherein the second encoding parameter includes scaling factors corresponding to multiple encoding pressure levels, and the target encoding mode corresponding to the encoding pressure is determined, including:

[0040] Based on the encoding pressure level corresponding to the encoding pressure, the target scaling factor is determined from multiple scaling factors of the second encoding parameter.

[0041] The target data size of the second macroblock after encoding is calculated by multiplying the target scaling factor and the budget data size. The budget data size is the average data size of the macroblock after encoding, calculated based on the total budget data size of the input image after encoding.

[0042] The second macroblock is pre-coded using multiple coding modes to obtain the predicted value of the encoded data volume;

[0043] In coding patterns where the predicted data volume is greater than or equal to the target data volume, the target coding pattern is determined based on the coding pressure.

[0044] One of the above technical solutions has the following advantages or beneficial effects: by subdividing the coding pressure into multiple levels and assigning a corresponding scaling factor to each level, the scaling factor can be quickly determined based on the coding pressure, thereby accurately calculating the target data volume and ensuring that the precoding process is efficient and accurate. Precoding is performed based on the target data volume, and the coding mode is determined among coding modes whose predicted data volume is greater than or equal to the target data volume. This avoids coding modes with smaller data volumes becoming the target coding mode, thus ensuring the quality of the encoded image.

[0045] In some embodiments, an image encoding method is provided, which encodes a second macroblock using second encoding parameters and a target encoding mode, including:

[0046] The second macroblock is encoded based on the parameters belonging to the target encoding mode in the second encoding parameters and the target data volume.

[0047] One of the above technical solutions has the following advantages or beneficial effects: during the encoding process, the combined effects of the target data volume, the second encoding parameters, and the target encoding mode are fully considered, ensuring the accuracy and efficiency of the encoding results.

[0048] In some embodiments, an image encoding apparatus is provided, comprising:

[0049] The image segmentation module is used to divide the input image into multiple macroblocks, where each macroblock includes an adjacent first macroblock and a second macroblock.

[0050] The encoding pressure calculation module, connected to the image block segmentation module, is used to calculate the encoding pressure after the encoding of the first macroblock is completed. The encoding pressure is the cumulative difference between the actual data volume and the budgeted data volume of the encoded macroblock after encoding.

[0051] The Bayesian optimization module, connected to the coding pressure calculation module, is used to calculate the first quality parameter of the first macroblock when the coding pressure reaches the pressure threshold. Based on the first quality parameter, the first coding parameter is adjusted through Bayesian optimization to obtain the second coding parameter. The objective function of Bayesian optimization is a function of the image quality parameter with respect to the coding parameter.

[0052] The macroblock encoding module is connected to the Bayesian optimization module and the encoding pressure calculation module, respectively. It is used to encode the first macroblock using the first encoding parameters. When Bayesian optimization is triggered after the first macroblock is encoded, the target encoding mode is determined based on the encoding pressure, and the second macroblock is encoded using the second encoding parameters and the target encoding mode.

[0053] One of the above technical solutions has the following advantages or beneficial effects: The image encoding apparatus of this disclosure achieves efficient and high-quality encoding of the input image through the collaborative work of various modules. The image segmentation module divides the input image into multiple macroblocks, providing a foundation for the subsequent encoding process. The encoding pressure calculation module calculates the encoding pressure in real time, providing a basis for dynamically adjusting encoding parameters and selecting the encoding mode. The Bayesian optimization module adjusts the encoding parameters according to the encoding pressure and image quality parameters, ensuring the stability of the encoding process and image quality. The macroblock encoding module encodes the macroblocks according to the optimized encoding parameters and the target encoding mode, realizing adaptive encoding of the input image.

[0054] Compared with the prior art, the embodiments of this disclosure achieve a dynamic balance between coding efficiency and image quality, significantly improving the adaptability and robustness of the coding system and providing a reliable guarantee for high-definition image transmission.

[0055] In some embodiments, an image encoding apparatus is provided, wherein the encoding pressure calculation module is provided with a swimming pool model, the swimming pool model including:

[0056] The water inlet unit is used to increase the actual data volume of the first macroblock after encoding to the current data volume after the first macroblock is encoded.

[0057] The drainage unit is used to subtract the budget data amount of the first macroblock from the current data amount after the encoding of the first macroblock is completed, wherein the budget data amount is the average data amount of the macroblock after encoding, calculated based on the total budget data amount of the input image after encoding.

[0058] The water level monitoring unit is connected to both the water inlet unit and the water outlet unit. It is used to determine the current water level based on the data level corresponding to the current data volume after the water inlet unit completes the increase of the current data volume and the water outlet unit completes the decrease of the current data volume. The current water level represents the coded pressure.

[0059] One of the above technical solutions has the following advantages or beneficial effects: The pool model reflects the changes in data flow and encoding pressure during the encoding process in an intuitive and dynamic way. The water inlet unit simulates the increase in the actual data volume after encoding, while the drainage unit simulates the decrease in data volume according to the budget. The two work together to affect the current data volume, forming a dynamic change in encoding pressure. The water level monitoring unit visualizes the encoding pressure as a water level by monitoring the data volume level corresponding to the current data volume, providing a basis for adjusting encoding parameters and selecting encoding modes. Through this dynamic monitoring mechanism, the encoding system can respond to fluctuations in data volume in real time, ensuring the stability of the encoding process and the balance of image quality. The application of the pool model not only improves encoding efficiency but also enhances the system's adaptability, further optimizing the transmission effect of high-definition images. Attached Figure Description

[0060] To more clearly illustrate the technical solutions in this disclosure, the accompanying drawings used in some embodiments of this disclosure will be briefly described below. Obviously, the drawings described below are only drawings of some embodiments of this disclosure, and those skilled in the art can obtain other drawings based on these drawings. In addition, the drawings described below can be regarded as schematic diagrams and are not intended to limit the actual size of the product, the actual flow of the method, the actual timing of the signals, etc. involved in the embodiments of this disclosure.

[0061] Figure 1 This is a flowchart illustrating an image encoding method according to some embodiments;

[0062] Figure 2 This is a schematic diagram illustrating the encoding order of macroblocks according to some embodiments;

[0063] Figure 3 This is a schematic diagram of a Bayesian optimization process according to some embodiments;

[0064] Figure 4 This is a schematic diagram of the initial state of a swimming pool model according to some embodiments;

[0065] Figure 5 This is a schematic diagram of water level changes in a swimming pool model according to some embodiments;

[0066] Figure 6 This is a schematic diagram of the final state of a swimming pool model according to some embodiments;

[0067] Figure 7 This describes the data processing flow prior to initiation coding according to some embodiments;

[0068] Figure 8 This is a flowchart illustrating a method for determining encoding parameters according to some embodiments;

[0069] Figure 9 This is a flowchart illustrating a method for determining an encoding pattern according to some embodiments;

[0070] Figure 10 This is a schematic diagram of the structure of an image encoding apparatus according to some embodiments;

[0071] Figure 11 This is a structural schematic diagram of a swimming pool model according to some embodiments. Detailed Implementation

[0072] The embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described below do not represent all embodiments consistent with this application. They are merely examples of systems and methods consistent with some aspects of this application as detailed in the claims.

[0073] It should be noted that the brief descriptions of terms in this application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise stated, these terms should be understood according to their ordinary and common meanings.

[0074] The terms "first," "second," "third," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar or related objects or entities, and do not necessarily imply a specific order or sequence, unless otherwise specified. It should be understood that such terms are interchangeable where appropriate.

[0075] The terms “comprising” and “having”, and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device that includes a range of components is not necessarily limited to all of the components that are clearly listed, but may include other components that are not clearly listed or that are inherent to such product or device.

[0076] The term "module" refers to any known or subsequently developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with that element.

[0077] To address the issue of poor encoding flexibility caused by using fixed encoding parameters, this disclosure provides an image encoding method. This method achieves adaptive matching between encoding parameters and image content by dynamically adjusting the encoding parameters, balancing bitrate and image quality, and ensuring optimal encoding results in different scenarios.

[0078] Figure 1 This is a flowchart illustrating an image encoding method according to some embodiments, such as... Figure 1 As shown, the method may include the following steps:

[0079] Step S110: Divide the input image into multiple macroblocks, wherein the macroblocks include adjacent first macroblocks and second macroblocks.

[0080] In some embodiments, the input image is the image to be encoded, and the output image is the encoded image. Dividing the input image into multiple macroblocks, such as n macroblocks (n greater than 1), facilitates encoding processing on a macroblock basis, improving the fineness of the encoding. The size of each macroblock can be flexibly set according to the image resolution and encoding requirements.

[0081] For example, the standard size of each macroblock can be 16*16 pixels, which can be adjusted according to actual needs. For an input image of 1920*1080, it can be divided into 8040 16×16 macroblocks and 120 16*8 macroblocks.

[0082] For example, the standard size of each macroblock can be 16*8 pixels. For an input image of 1920*1080, it can be divided into 16200 16×8 macroblocks.

[0083] For example, the standard size of each macroblock can be 8x8 pixels. For an input image of 1920x1080, it can be divided into 32,400 8x8 macroblocks.

[0084] This disclosure's embodiments dynamically adjust coding parameters based on adjacent macroblocks. Two adjacent macroblocks can be referred to as the first macroblock and the second macroblock, where the first macroblock is the preceding macroblock of the second macroblock. The first macroblock can be any macroblock in the input image except the last macroblock. For example, the first macroblock might be the first macroblock, such as the macroblock in the upper left corner; in this case, the second macroblock would be the second macroblock. Another example is that the first macroblock is the m-th macroblock, where m is less than n, and the second macroblock is the (m+1)-th macroblock, where n is the total number of macroblocks in the input image.

[0085] Figure 2 This is a schematic diagram illustrating the encoding order of macroblocks according to some embodiments, such as Figure 2 As shown, taking an input image containing 16 macroblocks as an example, the 16 macroblocks are numbered 1 to 16 in sequence. Two macroblocks with adjacent numbers are adjacent in position in the input image, and the encoding order is from macroblock 1 to macroblock 16.

[0086] Step S120: Encode the first macroblock using the first encoding parameters.

[0087] In some embodiments, after dividing the input image into n macroblocks, each macroblock can be encoded individually. Before encoding a macroblock, its encoding parameters and encoding mode need to be determined to decide how to encode it.

[0088] In some embodiments, the encoding parameters include a scaling factor, which is used to determine the target data size of the macroblock after encoding. The target data size is the product of the scaling factor and the budgeted data size. The budgeted data size is the average data size of the macroblock after encoding, calculated based on the total budgeted data size of the input image after encoding. After dividing the input image into n macroblocks, the budgeted data size of each macroblock can be calculated based on the compression ratio or the data size to be achieved after encoding, i.e., the total budgeted data size. The budgeted data size is the average of the total budgeted data size, where the unit of data size is bits. The budgeted data size represents the reference data size of the macroblock after encoding.

[0089] Before encoding macroblocks, the budgeted data size can be adjusted using scaling factors to obtain the target data size. For example, if the input image data size is 'a' bits, and a compression ratio of 'b' is desired, then the budgeted data size T0 for each macroblock is: T0 = a * b / n, in bits. The target data size T1 for each macroblock is: T1 = a * b * c / n, in bits, where c is the scaling factor.

[0090] The target data size is an important indicator in the encoding process, used to encode macroblocks based on the encoding mode and with reference to the target data size. Since different encoding modes have different encoding targets, the actual data size after encoding may vary significantly.

[0091] For example, if one encoding mode aims to ensure image quality, then the macroblocks are encoded based on the target data volume, and the actual data volume after encoding may be large. If another encoding mode aims to ensure bit rate, then the macroblocks are encoded based on the same target data volume, and the actual data volume after encoding may be small.

[0092] In some embodiments, the encoding parameters include quantization granularity Q, which is an important factor affecting the amount of data, bit rate, and reconstruction quality of the encoded macroblock.

[0093] In some embodiments, the encoding parameters of the first macroblock may be referred to as the first encoding parameters. When the first macroblock is the first macroblock of the input image, the first encoding parameters may be the initial encoding parameters. When the first macroblock is a subsequent macroblock of the input image, the encoding parameters of the previous macroblock may be dynamically adjusted based on the encoding result of the previous macroblock to obtain a better encoding effect.

[0094] In some embodiments, the scaling factor and quantization granularity Q in the initial encoding parameters can be preset empirically. For example, if a compression ratio of 50% is required, the scaling factor is set to 50% and the quantization granularity Q is set to 1; if a compression ratio of 70% is required, the scaling factor is set to 70% and the quantization granularity Q is set to 1.

[0095] In some embodiments, there may be multiple encoding modes, corresponding to different encoding objectives. These encoding objectives have varying degrees of emphasis on bitrate control and image quality control. For example, the encoding modes include a first mode, a second mode, and a third mode. The encoding objective of the first mode is to ensure image quality, the encoding objective of the second mode is to balance bitrate and quality, and the encoding objective of the third mode is to ensure bitrate to avoid excessive bitrate.

[0096] To match different encoding modes, some parameters in the encoding parameters include multiple sub-parameters. For example, the quantization granularity Q can be further subdivided into three sub-parameters: Q1, Q2, and Q3, corresponding to the first mode, the second mode, and the third mode, respectively.

[0097] In some embodiments, when the first macroblock is the first macroblock, since the target total budget data amount for the entire image after encoding is still far away, an encoding mode that prioritizes image quality can be selected, resulting in a larger target data amount to ensure image quality. As encoding progresses, the encoding mode of subsequent macroblocks can be dynamically adjusted to balance image quality and bitrate.

[0098] In some embodiments, the first macroblock is not the first macroblock. In this case, the first macroblock can be encoded according to the encoding parameters determined after the previous macroblock is encoded. These encoding parameters may be the same as or different from the encoding parameters of the previous macroblock. The specific determination needs to be made after the previous macroblock is encoded, depending on whether the encoding parameter adjustment process is triggered.

[0099] It should be noted that, in this embodiment of the disclosure, since there are multiple encoding modes, but a macroblock actually uses only one encoding mode, and after the encoding parameter adjustment process is triggered, the adjusted encoding parameters may involve multiple encoding modes. Therefore, for ease of describing the changes in encoding parameters, the encoding parameters of a macroblock during encoding specifically refer to the encoding parameters of that macroblock in all modes during encoding.

[0100] Step S130: After completing the encoding of the first macroblock, calculate the encoding pressure, which is the cumulative difference between the actual data volume and the budgeted data volume of the encoded macroblock.

[0101] In some embodiments, after the encoding of the first macroblock is completed, the data volume of the first macroblock in the encoded image can be obtained, which is the actual data volume.

[0102] In some embodiments, after the encoding of the first macroblock is completed, the encoding pressure is calculated. The encoding pressure is used to characterize the probability that the compression ratio of the input image exceeds a preset compression ratio after the unencoded macroblocks are encoded.

[0103] For example, after encoding half of the macroblocks, if the actual data volume of the encoded macroblocks reaches more than half of the total budgeted data volume of the input image calculated according to the preset compression rate, for example, two-thirds, then the encoding pressure is relatively high, and the encoding parameters need to be optimized to control the bit rate; if the actual data volume of the encoded macroblocks does not reach half of the total budgeted data volume, for example, two-fifths, then the encoding pressure is acceptable, and the encoding parameters do not need to be optimized.

[0104] In some embodiments, the encoding pressure can be determined based on the cumulative difference between the actual amount of data in the encoded macroblock and the budgeted amount of data.

[0105] For an encoded macroblock, if the difference between the actual data size and the budgeted data size after encoding is positive, it will increase the risk that the actual compression ratio of the entire image will exceed the required compression ratio. If the difference is negative, it will reduce the risk that the actual compression ratio of the entire image will exceed the required compression ratio.

[0106] During the encoding process, to control the actual compression ratio of the image to converge towards the desired compression ratio, the difference between the actual data size and the budgeted data size of the macroblock after encoding is calculated each time a macroblock is completed. These differences for all encoded macroblocks are then summed to obtain a cumulative difference. Encoding parameters are dynamically adjusted based on this cumulative difference to ensure that the overall compression ratio of the input image meets expectations after subsequent macroblocks are encoded, while also guaranteeing image quality.

[0107] Step S140: If the encoding pressure reaches the pressure threshold, calculate the first quality parameter of the first macroblock. Based on the first quality parameter, adjust the first encoding parameter through Bayesian optimization to obtain the second encoding parameter. The objective function of Bayesian optimization is the image quality parameter of the macroblock as a function of the encoding parameter.

[0108] In some embodiments, the pressure threshold is a critical value for measuring the compression ratio deviation. When the cumulative difference reaches this pressure threshold, it indicates that the coding parameters need to be optimized and adjusted to control the actual compression ratio of the image to converge towards the required compression ratio. At this time, the coding parameter adjustment process is triggered to optimize the coding parameters. The optimized parameters will be reapplied to subsequent macroblock coding to ensure that image quality and compression ratio are consistent, avoiding over-compression or under-compression, thereby improving overall coding efficiency and visual effect.

[0109] In some embodiments, the encoding parameters may include the pressure threshold. In the initial encoding parameters, the pressure threshold may be preset based on experience. During the adjustment of the encoding parameters, the pressure threshold may be adaptively adjusted to ensure more accurate compression ratio control under different image content and complexity.

[0110] In some embodiments, the coding parameters are adjusted through Bayesian optimization; that is, the process of adjusting the coding parameters is a Bayesian optimization process. Leveraging the characteristic of Bayesian optimization to automatically determine the optimal parameter combination based on the objective function, the coding parameters are automatically adjusted to achieve the best balance between image quality and compression ratio.

[0111] After the first macroblock is encoded, if the encoding pressure reaches the pressure threshold, the Bayesian optimization process is initiated to adjust the first encoding parameters and obtain the second encoding parameters.

[0112] Bayesian optimization includes an initial modeling phase and an iterative optimization phase. In this embodiment of the disclosure, the initial modeling phase is performed before the input image is encoded, and the iterative optimization phase is performed during the encoding process.

[0113] In some embodiments, during the initial modeling phase, a surrogate model is constructed based on initial sampled data, and the acquisition function is initialized. The prior distribution reflects an estimate of the initial range and probability of parameter values, providing a starting point for Bayesian optimization. In embodiments of this disclosure, multiple sets of encoding parameters are determined using the prior distribution as initial sampled data. For example, multiple sets of encoding parameters are preset, and these parameters are used to encode sample images, calculating the encoded image quality parameters, which are then used as the objective function values ​​for these initial sampled data, forming an initial dataset.

[0114] After obtaining the initial dataset, a surrogate model for fitting the relationship between image quality parameters and encoding parameters can be established using a Gaussian process; this model is called the Gaussian process model. Here, image quality parameters are those that represent the image quality of the encoded image, such as PSNR (Peak Signal-to-Noise Ratio), or the square root of PSNR, etc. The kernel function of the Gaussian process model is:

[0115]

[0116] Where MaxValue is the maximum pixel value corresponding to the bit depth of the input image. If the input image is an 8-bit image, MaxValue is 255; if the input image is a 10-bit image, MaxValue is 1023. i ,x j These are two sets of parameter vectors input to the Gaussian model, each representing a set of encoding parameters. MSE represents the mean squared error of these two parameter vectors. Since PSNR also involves the calculation of mean squared error, calculating the mean squared error within the Gaussian kernel function ensures that changes in the parameter vectors better reflect changes in PSNR, effectively linking image quality with the encoding parameters. MaxValue is used to normalize the MSE, ensuring the accuracy and adaptability of parameter adjustments at different pixel values, further optimizing compression ratio control and improving encoding efficiency.

[0117] In some embodiments, the image quality parameter is the square root of PSNR. This allows for a more gradual change in the image quality parameter caused by variations in the input parameter vector, preventing drastic changes in the image quality parameter due to small differences in the parameter vector, which could negatively impact the optimization process of the Gaussian model. This gradual change makes the Gaussian model more robust when adjusting encoding parameters, reducing image quality instability caused by parameter fluctuations.

[0118] In some embodiments, the acquisition function is used to determine where in the parameter space to perform the next sampling, balancing the search for new, potentially better parameter regions with the selection of parameters currently considered optimal based on existing information.

[0119] For example, the acquisition function adopts the desired improved acquisition function, denoted as F(x,y). max ):

[0120] F(x,y max )=EI(x)=E(max(0,y(x)-y max (x)))

[0121] Here, x represents one set of input parameter vectors, and EI(x) represents the expected improvement value of x. By calculating the expected improvement value, the sampling direction in the parameter space is guided, making each sampling closer to the optimal parameter region, thereby gradually improving the image quality parameters. This method effectively utilizes historical data, reduces blind search, and improves the efficiency and accuracy of parameter optimization. y(x) represents the objective function. y max (x) is the square root transform of the observed largest PSNR, i.e. The objective function is chosen to be the square root transformation of PSNR, which makes its changes more gradual. This is because PSNR changes too much when its value is greater than or equal to 40, which will cause significant interference to the optimization process.

[0122] In some embodiments, if Bayesian optimization is triggered during the encoding of the input image, the process enters the iterative optimization phase.

[0123] Figure 3 This is a flowchart illustrating Bayesian optimization according to some embodiments, applicable to the iterative optimization stage of Bayesian optimization, such as... Figure 3 As shown, the method may include the following steps:

[0124] Step S210: Calculate the first image quality parameter of the first macroblock.

[0125] In some embodiments, during the iterative optimization phase, based on the fact that Bayesian optimization was triggered after the first macroblock was encoded, the image quality parameters of the first macroblock are calculated. The calculation process includes: calculating the peak signal-to-noise ratio (PSNR) between the encoded image and the unencoded image of the first macroblock, calculating the square root of the PSNR, and obtaining the first image quality parameters, i.e., the image quality parameters of the first macroblock.

[0126] Step S220: Optimize the pre-trained Gaussian process model using the first encoding parameters and the first image quality parameters, wherein the Gaussian process model is used to fit the objective function.

[0127] In some embodiments, the pre-trained Gaussian process model is optimized based on the coding parameters and image quality parameters of the first macroblock, so that the Gaussian process model is adjusted from a prior distribution to a posterior distribution. This can improve the accuracy of fitting the relationship between image quality parameters and coding parameters in the current input image, thereby providing more accurate guidance for subsequent parameter selection.

[0128] Step S230: Based on the optimized Gaussian process model, the first encoding parameters are adjusted using the acquisition function to obtain the second encoding parameters.

[0129] In some embodiments, after optimizing the Gaussian process model, the acquisition function of the Gaussian process model determines a new set of coding parameters as candidate coding parameters based on a certain range of coding parameters of the first macroblock. The deviation between these new coding parameters and the coding parameters of the first macroblock is within a certain range, ensuring the continuity and stability of parameter adjustment and avoiding large fluctuations that could affect image quality. Based on the optimized Gaussian process model, the predicted objective function value of the candidate coding parameters is determined, i.e., its predicted image quality parameter, which is called the new image quality parameter. Based on the predicted objective function value and the maximum value of the objective function, the expected improvement value of the candidate coding parameters is calculated, where the maximum value of the objective function is the maximum value of the square root of the peak signal-to-noise ratio. After calculating the expected improvement value of a set of coding parameters, the acquisition function intelligently selects the next sampling point as a candidate coding parameter in the parameter space based on the current model state and existing experimental results. This allows for both exploring new, potentially better parameter regions and utilizing existing information to select the currently considered optimal parameters.

[0130] The above process is iterated continuously. When the preset number of iterations is reached, or when the improvement in PSNR is small in several consecutive iterations, it indicates that good performance has been achieved, and the iteration can be stopped to save computing resources. The candidate coding parameter corresponding to the largest expected improvement value is determined as the second coding parameter.

[0131] Step S150: Determine the target encoding mode corresponding to the encoding pressure.

[0132] In some embodiments, different cumulative differences correspond to different coding modes to ensure a balance between image quality and coding efficiency. For example, when the cumulative difference is less than or equal to a first threshold, the corresponding coding mode is the coding mode with the minimum coding loss to reduce image quality loss; when the cumulative difference is greater than the first threshold and less than or equal to a second threshold, the corresponding coding mode is the coding mode with the minimum rate-distortion cost to balance image quality and coding efficiency; when the cumulative difference exceeds the second threshold, the corresponding coding mode is the coding mode with the minimum number of coding bits to prioritize compression ratio.

[0133] The specific encoding methods for the various encoding modes described above are not specifically limited in this disclosure. This disclosure improves image encoding performance by optimizing the timing of encoding mode switching, optimizing encoding parameters within the encoding mode (such as quantization granularity), and flexibly determining the target data volume based on encoding pressure.

[0134] The first and second thresholds can be determined based on prior distributions, i.e., pre-determined based on the coding performance of the sample images. The first coding parameters include the aforementioned first and second thresholds. Through Bayesian optimization, the first and second thresholds are updated, improving their adaptability to the input images, thus enhancing the rationality of the coding mode selection and ensuring a balance between image quality and coding efficiency.

[0135] By dynamically adjusting the encoding mode, the system can achieve the optimal balance between image quality and encoding efficiency in different scenarios, ensuring stable and efficient overall performance.

[0136] In some embodiments, the second threshold may be the aforementioned pressure threshold to ensure image quality under high compression scenarios. By setting this threshold, the system can flexibly respond to different encoding requirements while ensuring image quality, further optimizing the selection of encoding parameters.

[0137] In the above steps, the coding parameters of each coding mode are optimized and adjusted by the coding parameters of the first macroblock and the image quality parameters to obtain the second coding parameters. The second coding parameters include the coding parameters of each coding mode. After the target coding mode is determined, the coding parameters of the target coding mode can be determined as the coding parameters of the second macroblock.

[0138] Step S160: Encode the second macroblock using the second encoding parameters and the target encoding mode.

[0139] In some embodiments, the second macroblock is encoded based on second encoding parameters obtained by adjusting the first encoding parameters. Since the adjusted encoding parameters are obtained by optimizing the encoding parameters of the first macroblock based on the image quality after encoding the first macroblock, and the second macroblock is an adjacent macroblock with a high probability of similar image content to the first macroblock, the adjusted encoding parameters have a higher matching degree with the content of the second macroblock, thereby effectively improving the encoding efficiency and image quality of the second macroblock.

[0140] By employing the block-by-block optimization strategy described above, the coding results of each macroblock are fully utilized, coding parameters are continuously optimized, the overall image coding effect is gradually improved, and a smooth transition of parameters between different macroblocks is ensured to reduce image quality fluctuations, ultimately achieving high-quality and high-efficiency image coding output.

[0141] To further describe the above image encoding process, some implementation methods in the encoding process are explained below.

[0142] In some embodiments, a pool model can be used for bitrate control and target encoding mode decision-making to achieve the goal of encoding the most suitable encoding mode for the current macroblock while maintaining the compression ratio. Bitrate control refers to determining the scaling factor for the next macroblock based on the water level in the pool model. Target encoding mode decision-making refers to determining the target encoding mode for the next macroblock based on the water level in the pool model.

[0143] See Figure 4 This is a schematic diagram of the initial state of a swimming pool model according to some embodiments. Figure 4 As shown, in the pool model, "water" represents the amount of data. The pool model has an inflow mechanism and a outflow mechanism. The inflow mechanism adds the actual data amount to the pool model after encoding a macroblock, while the outflow mechanism subtracts the budgeted data amount from the pool model after encoding a macroblock. Through these inflow and outflow mechanisms, the "water amount" in the pool model becomes the cumulative difference between the actual data amount and the budgeted data amount of the encoded macroblock, calculated using the following formula:

[0144] The amount of data remaining in the pool after coding = the amount of data remaining in the pool before coding - the budgeted amount of data + the actual amount of coded data.

[0145] In the above formula, the amount of data remaining in the pool before encoding refers to the amount of data in the pool model before encoding a macroblock, and the amount of data remaining in the pool after encoding refers to the amount of data in the pool model after the pool model is adjusted through the water inlet and water outlet mechanisms after encoding a macroblock is completed.

[0146] In a swimming pool model, the amount of data can be measured by the water level, or water surface height. A rising water level represents an increase in the cumulative difference, while a falling water level represents a decrease in the cumulative difference. The water level can also represent coding pressure; the higher the water level, the greater the coding pressure, and the lower the water level, the less the coding pressure.

[0147] In some embodiments, the water level can be a normalized value to allow for more intuitive monitoring and adjustment of the coding process. For example, the water level can be a value normalized to the range of 0 to 1, or a value normalized to the range of 0 to 10.

[0148] The swimming pool model can be set with an initial water level, corresponding to the initial cumulative difference. Setting the initial water level is to prevent the pool's water level from becoming negative if the actual data volume is less than the budgeted data volume after encoding a macroblock, thus ensuring the stability and accuracy of the swimming pool model.

[0149] In some embodiments, an initial water level may not be set, and the system may start directly from zero water level. During the encoding process of the input image, the water level changes are monitored, and the encoding parameters are dynamically adjusted to ensure that the water level fluctuates within a reasonable range, thereby accurately controlling the image compression rate.

[0150] See Figure 5 This is a schematic diagram illustrating water level changes in a swimming pool model based on some embodiments. For example... Figure 5 As shown, the water level gradually rises or falls as macroblock coding progresses, reflecting the changes in the cumulative difference in real time.

[0151] In some embodiments, the water level in the pool model is used to determine the scaling factor for the next macroblock. During the encoding of the input image, water level changes are monitored, and the scaling factor is dynamically adjusted to ensure precise control of the data volume during encoding. The scaling factor is reduced when the water level is high and increased when the water level is low, thereby maintaining a balance between image quality and compression ratio and improving encoding efficiency.

[0152] In some embodiments, to quickly determine the scaling factor, the water level can be divided into multiple levels, such as L levels, each corresponding to a scaling factor: δ1~δ L This hierarchical strategy allows for precise adjustment of the scaling factor based on changes in water level when processing complex images, ensuring both image quality and compression ratio are optimized, further improving the real-time performance and stability of the encoding system.

[0153] In some embodiments, after encoding a macroblock, the water level of the pool model is updated, and the scaling factor of the next macroblock is determined based on the level of the updated water level, so as to achieve bitrate control during the encoding process.

[0154] In some embodiments, after updating the water level in the pool model, the target coding mode for the next macroblock can be determined based on the latest water level. The coding objective of the target coding mode corresponds to the water level in the pool model; that is, different water level levels correspond to different coding objectives. Coding objectives may include ensuring image quality, balancing bitrate and image quality, and ensuring bitrate, among others.

[0155] For example, the pool model has a first threshold and a second threshold, where the first threshold is less than the second threshold. When the water level is below the first threshold, the encoding objective is to ensure image quality, and the target encoding mode is the encoding mode with the minimum encoding loss. When the water level is between the first and second thresholds, the encoding objective is to balance bit rate and image quality, and the target encoding mode is the encoding mode with the minimum rate distortion cost. When the water level is above the second threshold, the encoding objective is to ensure bit rate, and the target encoding mode is the encoding mode with the minimum number of encoded bits. By selecting the optimal mode described above, optimal encoding quality is achieved while controlling the bit rate.

[0156] In some embodiments, to accurately select the target coding mode, after determining the scaling factor of the macroblock to be encoded, the target number of bits for the macroblock to be encoded can be calculated. Based on the target number of bits, the macroblock to be encoded is pre-coded using multiple coding modes. Based on the pre-coding results, the coding loss and number of bits for each coding mode are determined, thereby determining the target coding mode according to the coding target corresponding to the current water level.

[0157] In some embodiments, when the water level is detected to have reached a pressure threshold, Bayesian optimization is triggered to adjust the encoding parameters, thereby guiding the water level to fall back, maintaining a balance between compression ratio and image quality, and ensuring the stability and efficiency of the encoding process.

[0158] In some embodiments, the pressure threshold may be the same as the second threshold, thereby adjusting the encoding parameters to guide the water level to fall back, preventing the water level from remaining above the second threshold and causing more macroblocks to choose the encoding mode with the minimum number of encoded bits for encoding, resulting in lower encoding quality.

[0159] See Figure 6 This is a schematic diagram illustrating the final state of a swimming pool model according to some embodiments. Figure 6 As shown, with the completion of macroblock coding, the water level eventually drops to zero or near zero, indicating that the cumulative difference is effectively controlled. At this point, the coding process is complete, and the optimal balance between image quality and compression ratio is achieved, ensuring that the output image meets storage requirements while maintaining high-quality visual effects. Through this dynamic adjustment mechanism, the coding system can flexibly respond to different image features, avoiding compression distortion caused by fixed parameters, and further improving the user experience. Experiments show that the pooling model coding scheme significantly improves compression efficiency while ensuring image quality, providing reliable technical support for high-definition video transmission and storage.

[0160] In some embodiments, since the water level represents the encoding pressure, Bayesian optimization can be initiated based on the water level. If the water level reaches the pressure threshold, Bayesian optimization is initiated.

[0161] In some embodiments, the target encoding mode can also be determined based on the water level. The pool model can be set with a first threshold and a second threshold to control entry into different target encoding modes. To optimize the encoding effect, the first and second thresholds can also be adjusted through Bayesian optimization.

[0162] Based on the above pool model, after the encoding of each macroblock is completed, the data processing flow for a macroblock to be encoded, such as the second macroblock, before starting encoding can be found in [reference needed]. Figure 7 ,like Figure 7 As shown, the process may include the following steps:

[0163] Step S310: Determine the encoding parameters.

[0164] In some embodiments, determining the encoding parameters refers to determining whether the encoding parameters of the previous macroblock need to be reused. The method for determining this can be found in [reference needed]. Figure 8 This includes steps S410-S450.

[0165] Step S410: After the first macroblock encoding is completed, control the pool model to update the water level.

[0166] In some embodiments, the water level of the pool model is updated through the pool model's inlet and outlet mechanisms.

[0167] Step S420: Determine whether the water level is higher than the second threshold.

[0168] In some embodiments, after the water level is updated, it is necessary to determine whether the water level is higher than the coding pressure threshold in order to decide whether to initiate Bayesian optimization. The coding pressure threshold may be a second threshold.

[0169] Step S430: If the water level is higher than the second threshold, perform Bayesian optimization to adjust the first encoding parameter to the second encoding parameter.

[0170] In some embodiments, both the first encoding parameter and the second encoding parameter include δ1 to δ2. L Let η1, η2, and Q be the first threshold and η2 be the second threshold. Through Bayesian optimization, the values ​​of some or all of the parameters in the first encoding parameters are updated to obtain the second encoding parameters.

[0171] Step S440: Determine the second encoding parameter as the encoding parameter of the second macroblock.

[0172] Step S450: If the water level is not higher than the second threshold, the first encoding parameter is determined as the encoding parameter of the second macroblock.

[0173] pass Figure 8 The method shown implements the following: after adjusting the water level based on the encoding result of the first macroblock, if the current water level does not trigger Bayesian optimization, the encoding parameters of the first macroblock are used; otherwise, the encoding parameters are regenerated.

[0174] Step S320: Calculate the scaling factor based on the water level.

[0175] In some embodiments, the current water level of the pool model is compared with the water level range of each level to obtain the level to which the current water level belongs, and the scaling factor of the level is determined as the scaling factor corresponding to the current water level, which is the target scaling factor.

[0176] Step S330: Calculate the target data volume based on the scaling factor.

[0177] In some embodiments, the target data volume is calculated based on a determined scaling factor, which is the product of the target scaling factor and the budgeted data volume.

[0178] Step S340: Perform precoding.

[0179] In some embodiments, precoding is performed under each encoding mode according to the encoding parameters determined in step S310 to obtain the estimated data volume of the second macroblock after encoding by each encoding mode. At this time, all encoding modes are candidate encoding modes.

[0180] Step S350: Filter the encoding pattern based on the precoding result.

[0181] In some embodiments, the precoding result includes the estimated data volume obtained in step S340. If the estimated data volume corresponding to a coding pattern is less than the target data volume, it indicates that the coding quality of the coding pattern is poor, and the coding pattern is filtered to ensure coding quality.

[0182] Step S360: Determine the encoding mode.

[0183] In some embodiments, a coding pattern can be determined from candidate coding patterns based on the current water level. The determination method can be found in [reference needed]. Figure 9 This includes steps S510-S570:

[0184] Step S510: Obtain the water level height.

[0185] Step S520: Determine whether the water level is less than or equal to the first threshold.

[0186] Step S530: If the water level is less than or equal to the first threshold, determine the target coding pattern as the coding pattern with the minimum coding loss.

[0187] Step S540: If the water level is greater than the first threshold, determine whether the water level is less than or equal to the second threshold.

[0188] Step S550: If the water level is less than or equal to the second threshold, determine the target coding mode as the coding mode with the minimum rate distortion cost.

[0189] Step S560: If the water level is greater than the second threshold, determine the target encoding mode as the encoding mode with the minimum amount of encoded data.

[0190] According to the above process, after the encoding mode is determined, the encoding parameters under that encoding mode can be used to encode the second macroblock.

[0191] This disclosure also provides an image encoding apparatus for implementing the image encoding method described in the above embodiments. See also Figure 10 The image encoding device may include the following functional modules: an image segmentation module, an encoding pressure calculation module, a Bayesian optimization module, and a macroblock encoding module.

[0192] The image segmentation module is used to divide the input image into multiple macroblocks, which include adjacent first macroblocks and second macroblocks.

[0193] The encoding pressure calculation module, connected to the image segmentation module, is used to calculate the encoding pressure after the encoding of a macroblock is completed. The encoding pressure is the cumulative difference between the actual data volume and the budgeted data volume of the encoded macroblock.

[0194] In some embodiments, see Figure 11 The coding pressure calculation module is equipped with a swimming pool model, which includes an inlet unit, a drainage unit, and a water level monitoring unit.

[0195] The water intake unit is used to increase the actual data volume of the first macroblock after encoding to the current data volume after the first macroblock is encoded.

[0196] The drainage unit is used to subtract the budgeted data volume of the first macroblock from the current data volume after the first macroblock is encoded, wherein the budgeted data volume is the average data volume of the macroblock after encoding, calculated based on the total budgeted data volume of the input image after encoding.

[0197] The water level monitoring unit is connected to both the water inlet unit and the water outlet unit. It is used to determine the current water level based on the data level corresponding to the current data volume after the water inlet unit completes the increase of the current data volume and the water outlet unit completes the decrease of the current data volume. The current water level represents the coded pressure.

[0198] The Bayesian optimization module, connected to the coding pressure calculation module, is used to calculate the first quality parameter of the first macroblock when the coding pressure reaches the pressure threshold. Based on the first quality parameter, the first coding parameter is adjusted through Bayesian optimization to obtain the second coding parameter. The objective function of Bayesian optimization is a function of the image quality parameter with respect to the coding parameter.

[0199] The macroblock encoding module is connected to the Bayesian optimization module and the encoding pressure calculation module, respectively. It is used to encode the first macroblock using the first encoding parameters. When Bayesian optimization is triggered after the first macroblock is encoded, the target encoding mode is determined based on the encoding pressure, and the second macroblock is encoded using the second encoding parameters and the target encoding mode.

[0200] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the disclosure herein. This application is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the claims. The above embodiments of this application do not constitute a limitation on the scope of protection of this application.

Claims

1. An image encoding method, characterized in that, include: The input image is divided into multiple macroblocks, wherein the macroblocks include adjacent first macroblocks and second macroblocks; The first macroblock is encoded using the first encoding parameters; After the first macroblock is encoded, the encoding pressure is calculated. The encoding pressure is the cumulative difference between the actual data volume and the budgeted data volume of the encoded macroblock after encoding. If the encoding pressure reaches a pressure threshold, the first quality parameter of the first macroblock is calculated. Based on the first quality parameter, the first encoding parameter is adjusted by Bayesian optimization to obtain the second encoding parameter. The objective function of the Bayesian optimization is a function of the image quality parameter of the macroblock with respect to the encoding parameter. Determine the target encoding mode corresponding to the encoding pressure; The second macroblock is encoded using the second encoding parameters and the target encoding mode.

2. The image encoding method according to claim 1, characterized in that, The step of adjusting the first encoding parameters through Bayesian optimization to obtain the second encoding parameters includes: The pre-trained Gaussian process model is optimized using the first encoding parameters and the first image quality parameters, wherein the Gaussian process model is used to fit the objective function; Based on the optimized Gaussian process model, the first encoding parameters are adjusted using the acquisition function to obtain the second encoding parameters.

3. The image encoding method according to claim 2, characterized in that, The kernel function of the Gaussian process model is determined based on the ratio of the mean square error corresponding to the two sets of encoding parameters to the maximum pixel value, wherein the maximum pixel value is the maximum pixel value corresponding to the bit depth of the input image.

4. The image encoding method according to claim 1, characterized in that, The calculation of the first image quality parameter of the first macroblock includes: Calculate the peak signal-to-noise ratio of the first macroblock in the encoded image and the uncoded image; The first image quality parameter is obtained by calculating the square root of the peak signal-to-noise ratio.

5. The image encoding method according to claim 2, characterized in that, The step of adjusting the first encoding parameter through an acquisition function to obtain the second encoding parameter includes: The candidate encoding parameters corresponding to the first encoding parameter are determined by the acquisition function; Based on the optimized Gaussian process model, the predicted value of the objective function for the candidate coding parameters is determined; Based on the predicted value and the maximum value of the objective function, the expected improvement value of the candidate coding parameters is calculated, wherein the maximum value of the objective function is the maximum value of the square root of the peak signal-to-noise ratio; The candidate encoding parameter corresponding to the largest expected improvement value is determined as the second encoding parameter.

6. The image encoding method according to claim 1, characterized in that, The second encoding parameter includes a first threshold and a second threshold, and determining the target encoding mode corresponding to the encoding pressure includes: The encoding pressure is compared with a first threshold and a second threshold, wherein the first threshold is less than the second threshold; If the encoding pressure is less than the first threshold, the target encoding mode is determined to be the encoding mode with the minimum encoding loss; If the encoding pressure is between the first threshold and the second threshold, the target encoding mode is determined to be the encoding mode with the minimum rate-distortion cost; If the encoding pressure is greater than the second threshold, the target encoding mode is determined to be the encoding mode with the minimum amount of encoded data.

7. The image encoding method according to claim 1, characterized in that, The second encoding parameter includes scaling factors corresponding to multiple encoding pressure levels, and determining the target encoding mode corresponding to the encoding pressure includes: Based on the encoding pressure level corresponding to the encoding pressure, a target scaling factor is determined from multiple scaling factors of the second encoding parameter; The target data size of the second macroblock after encoding is calculated based on the product of the target scaling factor and the budget data size. The budget data size is the average data size of the macroblock after encoding, calculated based on the total budget data size of the input image after encoding. The second macroblock is pre-coded using multiple coding modes to obtain the predicted value of the encoded data volume; In encoding modes where the predicted data volume is greater than or equal to the target data volume, the target encoding mode is determined based on the encoding pressure.

8. The image encoding method according to claim 7, characterized in that, The encoding of the second macroblock using the second encoding parameters and the target encoding mode includes: The second macroblock is encoded based on the parameters belonging to the target encoding mode in the second encoding parameters and the target data volume.

9. An image encoding device, characterized in that, include: An image segmentation module is used to divide an input image into multiple macroblocks, wherein the macroblocks include adjacent first macroblocks and second macroblocks; The encoding pressure calculation module, connected to the image block segmentation module, is used to calculate the encoding pressure after the encoding of a macroblock is completed. The encoding pressure is the cumulative difference between the actual data volume and the budgeted data volume of the encoded macroblock after encoding. A Bayesian optimization module, connected to the coding pressure calculation module, is used to calculate the first quality parameter of the first macroblock when the coding pressure reaches the pressure threshold, and adjust the first coding parameter through Bayesian optimization based on the first quality parameter to obtain the second coding parameter, wherein the objective function of the Bayesian optimization is a function of the image quality parameter with respect to the coding parameter; The macroblock encoding module is connected to the Bayesian optimization module and the encoding pressure calculation module, respectively. It is used to encode the first macroblock using the first encoding parameters. When the Bayesian optimization is triggered after the first macroblock is encoded, the module determines the target encoding mode based on the encoding pressure and encodes the second macroblock using the second encoding parameters and the target encoding mode.

10. The image encoding apparatus according to claim 9, characterized in that, The coding pressure calculation module is equipped with a swimming pool model, which includes: The water inlet unit is used to increase the actual data volume of the first macroblock after encoding to the current data volume after the first macroblock is encoded. A drainage unit is used to subtract the budgeted data amount of the first macroblock from the current data amount after the encoding of the first macroblock is completed, wherein the budgeted data amount is the average data amount of the macroblock after encoding, calculated based on the total budgeted data amount of the input image after encoding. A water level monitoring unit, connected to the water inlet unit and the water outlet unit respectively, is used to determine the current water level according to the data level corresponding to the current data volume after the water inlet unit completes the increase of the current data volume and the water outlet unit completes the decrease of the current data volume. The current water level represents the coded pressure.