Image coding method and device, electronic equipment, chip and storage medium
By adjusting the quantization parameters based on the target code length in video image encoding, combining flatness and grayscale value detection, the problems of long encoding time and low compression efficiency in the prior art are solved, and better subjective quality and efficient encoding are achieved.
Patent Information
- Application Number
- CN202310809736.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-03
- Publication Date
- 2025-01-03
AI Technical Summary
The existing video image encoding technology needs to traverse all quantization parameters during code rate control, resulting in long encoding time, low compression efficiency, and difficulty in improving subjective quality.
By determining the first quantization parameter from the set quantization parameters based on the target code length of the unit to be encoded, and the flatness and grayscale value are detected, the second quantization parameter is adjusted to achieve code rate control without requiring Iterate through all quantization parameters.
It shortens the encoding time, improves the subjective quality of the image, reduces the hardware design area, and improves the encoding efficiency.
Smart Images

Figure CN119254968A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing, and in particular to an image encoding method and device, electronic equipment, chip and storage medium. Background Art
[0002] The technology and industry in the multimedia field are constantly developing, which can meet people's demand for higher resolution of video images and provide a more convenient and comfortable Internet experience. As a result, the amount of video image data has increased significantly. How to effectively store these video image data and achieve fast transmission with high quality has become the focus. There are many video image coding standards (such as JPEG, H.26X and MPEG, etc.) that can compress image and video data. Among them, bit rate control is an important part of the image coding process. It is used to allocate a certain number of bits to the unit to be encoded, which will directly affect whether the image compression efficiency and subjective quality requirements can be met. Summary of the invention
[0003] The present disclosure provides an image encoding method, device, electronic device, chip and storage medium. During the image encoding process, quantization parameters are adjusted according to the characteristics of the content to be encoded to achieve bit rate control, and there is no need to traverse all quantization parameters during the process, which can shorten the encoding time and ensure better subjective quality of the image.
[0004] A first aspect embodiment of the present disclosure proposes an image encoding method, the method comprising: determining a first quantization parameter of the unit to be encoded from two or more set quantization parameters based on a target code length of the unit to be encoded; performing flatness detection and / or grayscale value detection on the unit to be encoded; adjusting the first quantization parameter according to the flatness detection and / or grayscale value detection results to obtain a second quantization parameter of the unit to be encoded, wherein the encoding code length corresponding to the second quantization parameter is less than or equal to the target code length; encoding the unit to be encoded based on the second quantization parameter.
[0005] In some embodiments of the present disclosure, the method also includes: obtaining an image to be encoded and a target code length of the image to be encoded; dividing the image to be encoded into a preset number of image blocks; taking the image blocks as units to be encoded, and determining the target code length of the units to be encoded according to the target code length of the image to be encoded and the preset number.
[0006] In some embodiments of the present disclosure, based on the target code length of the unit to be encoded, determining the first quantization parameter of the unit to be encoded from multiple set quantization parameters includes: setting two or more quantization parameters, wherein the values of the two or more quantization parameters are all less than or equal to the image bit width of the unit to be encoded; determining the minimum quantization parameter that satisfies a first condition from the two or more quantization parameters, wherein the first condition is that the coding length corresponding to the quantization parameter is less than or equal to the target code length of the unit to be encoded; dividing the unit to be encoded into multiple sub-blocks, and using the minimum quantization parameter as the first quantization parameter of each sub-block of the unit to be encoded.
[0007] In some embodiments of the present disclosure, performing flatness detection and / or grayscale value detection on the unit to be encoded includes: performing flatness detection on each sub-block of the unit to be encoded, and / or performing grayscale value detection on each sub-block of the unit to be encoded.
[0008] In some embodiments of the present disclosure, performing flatness detection on a sub-block includes: determining gradient values of all adjacent pixels in the sub-block; performing a first statistical processing on the gradient values of all adjacent pixels in the sub-block; and determining a flatness level of the sub-block based on a result of the first statistical processing and a first preset rule, wherein the first preset rule includes two or more judgment conditions for the flatness level.
[0009] In some embodiments of the present disclosure, performing a first statistical processing on the gradient values of all adjacent pixel points in a sub-block includes: determining a maximum gradient value, a minimum gradient value, and an average gradient value based on the gradient values of all adjacent pixel points in the sub-block; using the maximum gradient value, the minimum gradient value, and the average gradient value as thresholds to divide two or more gradient value intervals; and counting the number of gradient values of all adjacent pixel points in the sub-block that fall within two or more gradient value intervals.
[0010] In some embodiments of the present disclosure, grayscale value detection on a sub-block includes: determining the grayscale values of all pixels in the sub-block; performing a second statistical processing on the grayscale values of all pixels in the sub-block; and determining the grayscale value level of the sub-block based on the result of the second statistical processing and a second preset rule, wherein the first preset rule includes two or more judgment conditions for grayscale value levels.
[0011] In some embodiments of the present disclosure, performing a second statistical processing on the grayscale values of all pixels in a sub-block includes: obtaining at least one calibrated grayscale value; using the at least one calibrated grayscale value as a threshold to divide two or more grayscale value intervals; and counting the number of grayscale values of all pixels in the sub-block that fall into two or more gradient value intervals.
[0012] In some embodiments of the present disclosure, adjusting the first quantization parameter according to the flatness detection and / or grayscale value detection results to obtain the second quantization parameter of the unit to be encoded includes: for each sub-block of the unit to be encoded, based on a preset adjustment rule, adjusting the first quantization parameter of the sub-block according to the flatness level and / or grayscale value level of the sub-block to obtain the second quantization parameter of the sub-block; for all sub-blocks of the unit to be encoded, when the second quantization parameters of all sub-blocks do not meet the first preset condition, canceling the reduction adjustment of the first quantization parameter and re-determining the second quantization parameter in the order of the grayscale value detection levels of all sub-blocks from high to low until the second quantization parameters of all sub-blocks meet the first preset condition, wherein the first preset condition includes: the coding length corresponding to the second quantization parameters of all sub-blocks is less than or equal to the target code length of the unit to be encoded.
[0013] In some embodiments of the present disclosure, encoding the unit to be encoded based on the second quantization parameter includes: encoding two or more sub-blocks of the unit to be encoded at the same time according to the second quantization parameters of the sub-blocks until all sub-blocks of the unit to be encoded are encoded.
[0014] A second aspect embodiment of the present disclosure proposes an image encoding device, which includes: a determination module, used to determine a first quantization parameter of a unit to be encoded from multiple set quantization parameters based on a target code length of the unit to be encoded; a detection module, used to perform flatness detection and / or grayscale value detection on the unit to be encoded; an adjustment module, used to adjust the first quantization parameter according to the flatness detection and / or grayscale value detection results to obtain a second quantization parameter of the unit to be encoded, wherein the encoding code length corresponding to the second quantization parameter is less than or equal to the target code length; and an encoding module, used to encode the unit to be encoded based on the second quantization parameter.
[0015] The third aspect embodiment of the present disclosure proposes an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in the first aspect embodiment of the present disclosure.
[0016] The fourth aspect embodiment of the present disclosure proposes a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the method described in the first aspect embodiment of the present disclosure.
[0017] The fifth aspect embodiment of the present disclosure proposes a chip, which includes one or more interface circuits and one or more processors; the interface circuit is used to receive code instructions and transmit them to the processor, and the processor is used to run the code instructions to execute the method described in the first aspect embodiment of the present disclosure.
[0018] In summary, the image encoding method proposed in the present disclosure includes: based on the target code length of the unit to be encoded, determining the first quantization parameter of the unit to be encoded from two or more set quantization parameters; performing flatness detection and / or grayscale value detection on the unit to be encoded; adjusting the first quantization parameter according to the flatness detection and / or grayscale value detection results to obtain the second quantization parameter of the unit to be encoded, wherein the encoding code length corresponding to the second quantization parameter is less than or equal to the target code length; encoding the unit to be encoded based on the second quantization parameter. The method disclosed in the present disclosure adjusts the quantization parameter according to the characteristics of the content to be encoded to achieve bit rate control, and there is no need to traverse all quantization parameters in the process, which can shorten the encoding time and ensure better subjective quality of the image.
[0019] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0021] Figure 1 A schematic diagram of an application scenario provided by an embodiment of the present disclosure;
[0022] Figure 2 A flowchart of an image encoding method provided by an embodiment of the present disclosure;
[0023] Figure 3 A flowchart of an image encoding method provided by an embodiment of the present disclosure;
[0024] Figure 4 A flowchart of an image encoding method provided by an embodiment of the present disclosure;
[0025] Figure 5 A schematic diagram of the structure of an image encoding device provided by an embodiment of the present disclosure;
[0026] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0027] Embodiments of the present disclosure are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, and should not be construed as limiting the present disclosure.
[0028] The technology and industry in the multimedia field are constantly developing, which can meet people's demand for higher resolution of video images and provide a more convenient and comfortable Internet experience. As a result, the amount of video image data has increased significantly. How to effectively store these video image data and achieve fast transmission with high quality has become the focus. There are many video image coding standards (such as JPEG, H.26X and MPEG, etc.) that can compress image and video data. Among them, bit rate control is an important part of the image coding process. It is used to allocate a certain number of bits to the unit to be encoded, which will directly affect whether the image compression efficiency and subjective quality requirements can be met.
[0029] During the image encoding process, bit rate control is achieved by adjusting the quantization parameter written into the bit stream. The smaller the quantization parameter, the longer the corresponding encoding bit number and the higher the bit rate.
[0030] In the related art, each sub-block of the unit to be encoded is traversed in sequence, and each sub-block needs to traverse all quantization parameters to determine the minimum quantization parameter that meets the target bit rate of the sub-block. When adjusting the quantization parameter, some quantization parameters are roughly selected and traversed again, and the quantization parameters of the sub-block are slightly reduced according to the number of remaining bits in the block.
[0031] As described above, the related technology needs to spend a lot of time to traverse the quantization parameters, the encoding time is long, the compression efficiency is low, and the adjustment method of the quantization parameters is relatively rough, making it difficult to improve the subjective quality through bit rate control.
[0032] In order to solve the problems existing in the related technology, the present disclosure proposes an image encoding method. When adjusting the quantization parameters, the characteristics of the content to be encoded are taken into consideration to ensure better subjective quality as much as possible. At the same time, fewer quantization parameters need to be traversed, and multiple sub-blocks can be encoded at the same time during hardware design, which can reduce the hardware design area and shorten the encoding time.
[0033] Before introducing the detailed solution of the present disclosure, the scenario to which the solution of the present disclosure is applied is described first. Figure 1 FIG. 1 is an application scenario diagram of an image encoding method in an embodiment. Figure 1 As shown, the application scenario includes an electronic device 104, in which a camera module and several applications can be installed. The application can initiate an image acquisition instruction to acquire an image, and the camera module acquires the image 102. Among them, the camera module can include a front camera module and / or a rear camera module. Finally, the target image is sent to the target application. Among them, the electronic device 104 can be a smart phone, a tablet computer, a personal digital assistant, a wearable device, etc.
[0034] In some optional embodiments, the electronic device may also be a vehicle-mounted device or an Internet of Vehicles device, such as a smart car, etc. In the present disclosure, only a smart phone is taken as an example, but it does not limit the scope of the present disclosure.
[0035] A camera can be installed on an electronic device, and images can be acquired through the installed camera. Cameras can be divided into laser cameras, visible light cameras and other types according to the different images acquired. Laser cameras can acquire images formed by irradiating lasers onto objects, and visible light cameras can acquire images formed by irradiating visible light onto objects. Several cameras can be installed on an electronic device, and the installation locations are not limited. For example, a camera can be installed on the front panel of an electronic device, and two cameras can be installed on the back panel. The camera can also be installed inside the electronic device in an embedded manner, and then the camera can be opened by rotating or sliding. Specifically, a front camera and a rear camera can be installed on an electronic device. The front camera and the rear camera can acquire images from different perspectives. Generally, the front camera can acquire images from the front perspective of the electronic device, and the rear camera can acquire images from the back perspective of the electronic device.
[0036] It should be understood that in the present disclosure, the front camera or the rear camera is only used as an example to distinguish the shooting angles of different cameras, rather than to limit the functions of multiple cameras. The multiple cameras in the present disclosure can be rear cameras or front cameras at the same time, which is not limited in this disclosure.
[0037] An electronic device can have several applications installed. An application is software written for a certain purpose in an electronic device. An electronic device can use an application to provide services to users. When an application needs to capture an image, it will initiate an image capture instruction. The electronic device will call the camera module to capture the image according to the image capture instruction. An image capture instruction is an instruction used to trigger an image capture operation.
[0038] The electronic device is also provided with a processor, and the image encoding module in the processor can process the image captured by the camera module, for example, execute the image encoding method provided in the present disclosure.
[0039] Figure 2 The following is a flowchart of an image encoding method provided by an embodiment of the present disclosure. Figure 2 As shown, the image encoding method includes steps 201-204.
[0040] Step 201 : determining a first quantization parameter of a unit to be encoded from two or more set quantization parameters based on a target code length of the unit to be encoded.
[0041] In an embodiment of the present disclosure, the method also includes obtaining an input image, where the input image is an image to be encoded, dividing the image to be encoded into image blocks, dividing the image into a plurality of image blocks, and using the image blocks as encoding units. The method of the present disclosure can be used to encode the encoding units of the image to be encoded, and is applicable to each encoding unit of the image to be encoded.
[0042] In an embodiment of the present disclosure, the target code length of the unit to be encoded is the number of encoding bits allocated to the unit to be encoded. During encoding, the encoding length of the unit to be encoded cannot exceed the target code length of the unit to be encoded. The target code length of the unit to be encoded can be determined based on the target code length of the image to be encoded, or it can be set in advance, which is not limited by the present disclosure.
[0043] In an embodiment of the present disclosure, multiple quantization parameters are initially set, and the unit to be encoded is traversed to obtain the code length required for encoding the block under each set quantization parameter, and a suitable quantization parameter is selected as the first quantization parameter according to the target code length of the unit to be encoded.
[0044] Step 202: Perform flatness detection and / or grayscale value detection on the unit to be encoded.
[0045] In the embodiments of the present disclosure, the flatness and grayscale value of the unit to be encoded can reflect the image characteristics of the unit to be encoded, and the flatness detection of the unit to be encoded can obtain the edge characteristics of the unit to be encoded, and the grayscale value detection of the unit to be encoded can inversely obtain the brightness of the unit to be encoded.
[0046] In some embodiments, in flatness detection, the flatness level of the unit to be encoded can be determined by counting the pixel gradient values in the unit to be encoded. In grayscale value detection, the brightness and darkness level of the unit to be encoded can be determined by counting the pixel grayscale values in the unit to be encoded. The specific statistical methods and judgment conditions are not limited by the present disclosure.
[0047] In some embodiments, the unit to be encoded is cut into multiple smaller areas, and flatness detection and / or grayscale value detection are performed on the multiple areas in turn. If the unit to be encoded is an image block, the image block is further divided into multiple sub-blocks, all sub-blocks are traversed, and flatness detection and / or grayscale value detection are performed on the sub-blocks.
[0048] Step 203: adjust the first quantization parameter according to the flatness detection and / or gray value detection results to obtain a second quantization parameter of the unit to be encoded, wherein the encoding code length corresponding to the second quantization parameter is less than or equal to the target code length.
[0049] In the embodiment of the present disclosure, the first quantization parameter is adjusted according to the flatness detection and / or gray value detection results, and the image characteristics of the unit to be encoded are taken into consideration, so that the subjective quality of the image can be guaranteed. For example, for an area with a smaller gray value, the image is darker, and the quantization parameter is adjusted to reduce the area, so that the image of the darker area after encoding is clearer.
[0050] In some embodiments of the present disclosure, the flatness detection and / or grayscale value detection results are the flatness level and / or brightness level of the unit to be encoded, and the specific value for lowering or increasing the first quantization parameter is determined based on the flatness level and / or brightness level of the unit to be encoded.
[0051] In some embodiments of the present disclosure, the quantization parameters of multiple regions of the coding unit to be encoded can be adjusted in sequence according to the grayscale value detection results from small to large, and the adjustment can be stopped when the encoding code length corresponding to the adjusted quantization parameter is about to exceed the target code length of the coding unit to be encoded. Alternatively, all regions of the coding unit to be encoded can be traversed to adjust the quantization parameters of all regions of the coding unit to be encoded. If the encoding code length corresponding to the adjusted quantization parameter exceeds the target code length of the coding unit to be encoded, the adjustment of the quantization parameters for multiple regions can be canceled in sequence according to the grayscale value detection results from large to small until the encoding code length corresponding to the quantization parameter is less than or equal to the target code length of the coding unit to be encoded.
[0052] Step 204: Encode the unit to be encoded based on the second quantization parameter.
[0053] In the embodiment of the present disclosure, the second quantization parameter is used as the quantization parameter finally used for encoding, and the encoding code length corresponding to the second quantization parameter is less than or equal to the target code length of the unit to be encoded.
[0054] In some embodiments of the present disclosure, the second quantization parameter is a quantization parameter used for encoding each region of the unit to be encoded. For each region of the unit to be encoded, the quantization parameter corresponding to the region is written into the bitstream, and then each pixel value of the region is encoded.
[0055] In summary, according to the image coding method proposed in the present disclosure, based on the target code length of the unit to be encoded, a first quantization parameter of the unit to be encoded is determined from two or more set quantization parameters; flatness detection and / or grayscale value detection is performed on the unit to be encoded; according to the flatness detection and / or grayscale value detection results, the first quantization parameter is adjusted to obtain a second quantization parameter of the unit to be encoded, wherein the encoding code length corresponding to the second quantization parameter is less than or equal to the target code length; based on the second quantization parameter, the unit to be encoded is encoded, and the quantization parameter is adjusted according to the characteristics of the content to be encoded to achieve bit rate control, and there is no need to traverse all quantization parameters in the process, which can shorten the encoding time and ensure better subjective quality of the image.
[0056] based on Figure 2 The embodiment shown, Figure 3 A flowchart of an image encoding method proposed in the present disclosure is further shown. For ease of understanding, Figure 4 The present invention is a flowchart of an image encoding method disclosed in the present invention.
[0057] like Figure 4 As shown, the method includes the following steps.
[0058] Step 301: set two or more quantization parameters, wherein the values of the two or more quantization parameters are all less than or equal to the image bit width of the unit to be encoded.
[0059] In the embodiments of the present disclosure, the value range of the quantization parameter is [0, bitdepth], where bitdepth indicates the image bit width. For example, if the image bit width is 8, the value range of the quantization parameter is [0, 8]. Multiple quantization parameters are set, such as [0, 2, 4, 6], [1, 3, 5, 7], [2, 4, 6], etc. The number of set quantization parameters and their specific values can be adjusted in implementation according to the encoding effect, and the present disclosure is not limited thereto.
[0060] In some embodiments of the present disclosure, the method also includes: obtaining an image to be encoded and a target code length of the image to be encoded; dividing the image to be encoded into a preset number of image blocks; taking the image blocks as units to be encoded, and determining the target code length of the units to be encoded according to the target code length of the image to be encoded and the preset number.
[0061] In one embodiment, the image to be encoded and the target code length of the image to be encoded are obtained, the image to be encoded is divided into a plurality of image blocks with equal width and height, each image block is used as a coding unit, and each image block is executed as follows: Figure 4 The encoding process is shown.
[0062] In the embodiments of the present disclosure, each image block is used as a coding unit. First, the target code length of each image block is determined. The target code length is the number of allocated coding bits. During encoding, the coding length of each image block cannot exceed its corresponding target code length.
[0063] In one embodiment, each coding unit can be variable-length or fixed-length encoded according to actual needs. If fixed-length encoding is adopted, the target code length of each image block is the target code length of the image to be encoded divided by the number of all image blocks. If fixed-length encoding is adopted, the target code length of each image block is the remaining code length of the image to be encoded divided by the number of remaining image blocks, wherein the initial value of the remaining code length of the image to be encoded is the target code length of the image to be encoded, and the code length used for each coding unit is subtracted after each coding unit is encoded.
[0064] Step 302: determine a minimum quantization parameter that satisfies a first condition from two or more quantization parameters, wherein the first condition is that a code length corresponding to the quantization parameter is less than or equal to a target code length of the unit to be encoded.
[0065] In an embodiment of the present disclosure, each image block is taken as a coding unit, and based on setting multiple quantization parameters, each image block is traversed to obtain the coding length required for encoding the block under each set quantization parameter, so as to obtain the minimum quantization parameter that meets the target code length of the block, which is used as the initial quantization parameter for encoding each sub-block of the current block.
[0066] For example, initially set multiple quantization parameters [0, 2, 4, 6], and traverse the first image block. If the target code length of the first image block is 6 bits, the corresponding coding length when the quantization parameter is 0 is greater than 6 bits, which cannot meet the target code length of the image block. When the quantization parameters are 2, 4, and 6, the corresponding coding length is less than or equal to 6 bits, which meets the target code length of the image block, then the smallest quantization parameter is set to 2.
[0067] Step 303: divide the unit to be encoded into multiple sub-blocks, and use the minimum quantization parameter as the first quantization parameter of each sub-block of the unit to be encoded.
[0068] In other words, taking each image block as an encoding unit, for each image block, the image block is divided into multiple sub-blocks with equal width and height, and the minimum quantization parameter of the image block that satisfies the first condition is used as the initial quantization parameter of each sub-block, that is, the first quantization parameter.
[0069] Step 304: for each sub-block of the unit to be encoded, perform a flatness detection on the sub-block, and / or, for each sub-block of the unit to be encoded, perform a gray value detection on the sub-block.
[0070] In an embodiment of the present disclosure, for a currently encoded image block, each sub-block thereof is pre-traversed, a flatness detection is performed on each sub-block and / or a grayscale value detection is performed on each sub-block to obtain a flatness detection result and / or a grayscale value detection result of each sub-block.
[0071] In some embodiments of the present disclosure, performing flatness detection on a sub-block includes: determining gradient values of all adjacent pixels in the sub-block; performing a first statistical processing on the gradient values of all adjacent pixels in the sub-block; and determining a flatness level of the sub-block based on a result of the first statistical processing and a first preset rule, wherein the first preset rule includes two or more judgment conditions for the flatness level.
[0072] For example, the first preset rule includes three flatness level judgment conditions, which are very flat, relatively flat, and uneven. According to the result of the first statistical processing and the first preset rule, the flatness level of the sub-block is finally determined to be relatively flat.
[0073] In some embodiments of the present disclosure, performing a first statistical processing on the gradient values of all adjacent pixel points in a sub-block includes: determining a maximum gradient value, a minimum gradient value, and an average gradient value based on the gradient values of all adjacent pixel points in the sub-block; using the maximum gradient value, the minimum gradient value, and the average gradient value as thresholds to divide two or more gradient value intervals; and counting the number of gradient values of all adjacent pixel points in the sub-block that fall within two or more gradient value intervals.
[0074] In one embodiment, the difference between adjacent pixels in the sub-block is obtained, and the adjacent pixel difference is transformed into a non-negative number as a gradient value, wherein the non-negative number transformation is that if the difference is less than zero, the gradient value is 2 multiplied by the absolute value of the adjacent pixel difference minus 1, and if it is greater than or equal to zero, the gradient value is 2 multiplied by the adjacent pixel difference.
[0075] Furthermore, based on all the determined gradient values, the maximum gradient value, the minimum gradient value and the average gradient value are determined. The maximum gradient value is expressed as max_grad, the minimum gradient value is expressed as min_grad, and the average gradient value is expressed as ave_grad. Three gradient value intervals are divided. The first gradient value interval is expressed as range1, and the interval is [min_grad, (min_grad+ave_grad+1) / 2). The number of gradient values appearing in the first gradient value interval is counted and recorded as cnt_range1. The second gradient value interval is expressed as range2, and the interval is [(min_grad+ave_grad+1) / 2, (max_grad+ave_grad+1) / 2]. The number of gradient values appearing in the second gradient value interval is counted and recorded as cnt_range2. The third gradient value interval is expressed as range3, and the interval is ((max_grad+ave_grad+1) / 2, max_grad]. The number of gradient values appearing in the third gradient value interval is counted and recorded as cnt_range3.
[0076] Furthermore, the judgment conditions include: if max_grad is less than thresh_max, the sub-block is judged to be very flat, and the corresponding flatness level is expressed as flat_type1; if min_grad is greater than thresh_min, the sub-block is judged to be very uneven, and the corresponding flatness level is expressed as flat_type2; if cnt_range3 is the largest, the sub-block is judged to be uneven, and the corresponding flatness level is expressed as flat_type3; if cnt_range1 is the largest, the sub-block is judged to be relatively flat, and the corresponding flatness level is expressed as flat_type4, wherein thresh_max and thresh_min are manually calibrated parameters, respectively representing the maximum threshold and minimum threshold of the gradient value.
[0077] According to the above statistical results and judgment conditions, the flatness level of the sub-block is determined, and the flatness detection is performed on each sub-block of the currently encoded image block according to the above method to determine the flatness level of each sub-block.
[0078] It is understandable that the gradient value interval and the flatness level judgment conditions can be flexibly designed, and the above examples do not limit the present disclosure.
[0079] In some embodiments of the present disclosure, grayscale value detection on a sub-block includes: determining the grayscale values of all pixels in the sub-block; performing a second statistical processing on the grayscale values of all pixels in the sub-block; and determining the grayscale value level of the sub-block based on the result of the second statistical processing and a second preset rule, wherein the first preset rule includes two or more judgment conditions for grayscale value levels.
[0080] For example, the first preset rule includes three grayscale value level judgment conditions, and the three grayscale value levels are dark, medium, and bright. According to the result of the first statistical processing and the first preset rule, it is finally determined that the grayscale value level of the sub-block is medium.
[0081] In some embodiments of the present disclosure, performing a second statistical processing on the grayscale values of all pixels in a sub-block includes: obtaining at least one calibrated grayscale value; using the at least one calibrated grayscale value as a threshold to divide two or more grayscale value intervals; and counting the number of grayscale values of all pixels in the sub-block that fall into two or more gradient value intervals.
[0082] In one embodiment, three manually calibrated thresholds, including thresh1, thresh2, and thresh3, are obtained. According to these three thresholds, the numerical range [0, (1<<bitdepth)-1] is divided into four grayscale value intervals, including [0, thresh1), [thresh1, thresh2), [thresh2, thresh3), and [thresh3, (1<<bitdepth)-1], which respectively correspond to four levels: extremely dark level1, dark level2, medium level3, and bright level4. Here, 1<< means shifting one bit to the left. For example, when the bit width is 8 bits, the grayscale value range is from 0 to 255.
[0083] Further, the number of pixels falling in [0, thresh1), [thresh1, thresh2), [thresh2, thresh3), and [thresh3, (1<<bitdepth)-1] are respectively counted and recorded as cnt_1, cnt_2, cnt_3, and cnt_4. The level corresponding to the interval with the largest number of pixels is taken as the grayscale detection result of the sub-block. For example, if the number of pixels falling in [0, thresh1) is the largest, it is determined that the grayscale value level of the sub-block is extremely dark level1.
[0084] According to the above statistical results and judgment conditions, the flatness level of the sub-block is determined, and the flatness of each sub-block of the currently encoded image block is detected according to the above method to determine the flatness level of each sub-block.
[0085] It can be understood that the judgment conditions for the grayscale value interval and the grayscale value level can be flexibly designed, and the above examples do not limit the present disclosure.
[0086] Step 305: For each sub-block of the unit to be encoded, based on a preset adjustment rule, the first quantization parameter of the sub-block is adjusted according to the flatness level and / or grayscale value level of the sub-block to obtain the second quantization parameter of the sub-block.
[0087] In one embodiment, according to the flatness level and the grayscale value detection level, the specific QP of each sub-block is adjusted, expressed as qp_i = f(init_qp, level_i, flat_type_i), where level_i and flat_type_i respectively represent the flatness detection level and the grayscale value level of sub-block i, init_qp represents the initial quantization parameter value of the sub-block, and qp_i represents the adjusted quantization parameter value of sub-block i.
[0088] It should be noted that the range of the adjusted quantization parameter should be maintained within [0, bitdepth], and boundary processing can be performed using max(0, min(qp_i, bitdepth)).
[0089] Gray value detection\flatness detection flat_type1 flat_type2 flat_type3 flat_type4 Level 1 qp-3 qp-2 qp qp-1 Level2 qp-2 qp-1 qp qp-1 Level3 qp-1 qp+1 qp qp-1 Level 4 qp-1 qp+2 qp+1 qp
[0090] As shown in Table 1, the initial quantization parameter of the sub-block is adjusted according to the flatness level and / or the gray value level, specifically including 4x4=16 types of quantization parameter adjustment logic, wherein the flatness level includes very flat flat_type1, very uneven flat_type2, uneven flat_type3, and relatively flat flat_type4, and the gray value detection levels include extremely dark level1, dark level2, medium level3, and bright level4. After adjustment, the quantization parameter may remain unchanged, or the quantization parameter may increase or decrease.
[0091] It should be noted that the specific number of adjustment logics and the specific adjustment value range can be flexibly designed, and the above examples do not constitute a limitation to the present disclosure.
[0092] Step 306, for all sub-blocks of the unit to be encoded, when the second quantization parameters of all sub-blocks do not meet the first preset condition, cancel the reduction adjustment of the first quantization parameter in the order of the grayscale value detection levels of all sub-blocks from high to low, and re-determine the second quantization parameter until the second quantization parameters of all sub-blocks meet the first preset condition.
[0093] The first preset condition includes: the coding length corresponding to the second quantization parameter of all sub-blocks is less than or equal to the target code length of the unit to be encoded.
[0094] In one implementation, the quantization parameter adjusted in step 305 is traversed over each sub-block, and the number of bits encoded by each sub-block with the adjusted quantization parameter is calculated, and the sum is accumulated as the encoding code length of the image block to determine whether it is less than the target code length of the image block, such as Figure 4 As shown, if it is greater than the block target code length, the adjustment of the reduced quantization parameter of the sub-block is abandoned in the order of grayscale value levels from high to low, that is, the quantization parameter of the corresponding sub-block is restored to the initial quantization parameter, and the quantization parameter of each sub-block is reduced and adjusted. At the same time, the encoding code length of the image block is reduced by the number of increased bits brought about by the reduction of the quantization parameter of the sub-block, and it is judged again whether the encoding code length of the image block is less than the target code length of the image block. If it is still not satisfied, the quantization parameter of a sub-block is continuously abandoned in the order of grayscale value levels from high to low until the encoding code length of the image block is less than the target code length of the image block.
[0095] Step 307 : encoding two or more sub-blocks of the unit to be encoded according to the second quantization parameters of the sub-blocks at the same time until all sub-blocks of the unit to be encoded are encoded.
[0096] In an embodiment of the present disclosure, multiple sub-blocks of an image block are encoded simultaneously, the quantization parameters of the sub-blocks are first written into the bitstream, and then each pixel value is encoded, wherein the writing method is not limited by the present disclosure, for example, the writing method may be direct transmission, or the difference between the quantization parameters before and after writing, etc. The encoding method is not limited by the present disclosure, for example, the encoding method may be direct transmission, entropy coding, and other encoding methods.
[0097] In summary, the image encoding method proposed in the present disclosure has the following beneficial effects:
[0098] 1. Fewer quantization parameters need to be traversed, and multiple sub-blocks can be encoded simultaneously during hardware design, which can reduce hardware design area, shorten encoding time, and improve encoding efficiency;
[0099] 2. When adjusting the quantization parameters, consider the characteristics of the content to be encoded and try to ensure the subjective quality of the image;
[0100] 3. The encoding method disclosed in the present invention can achieve efficient compression of image or video data and save power consumption while ensuring subjective quality as much as possible.
[0101] Figure 5 FIG. 4 is a schematic diagram of the structure of an image encoding device 400 provided in an embodiment of the present disclosure. Figure 5 As shown, the image encoding device includes:
[0102] A determination module 410, configured to determine a first quantization parameter of the unit to be encoded from a plurality of set quantization parameters based on a target code length of the unit to be encoded;
[0103] A detection module 420, configured to perform flatness detection and / or gray value detection on the unit to be encoded;
[0104] An adjustment module 430 is used to adjust the first quantization parameter according to the flatness detection and / or gray value detection result to obtain a second quantization parameter of the unit to be encoded, wherein the encoding code length corresponding to the second quantization parameter is less than or equal to the target code length;
[0105] The encoding module 440 is configured to encode the unit to be encoded based on the second quantization parameter.
[0106] In some embodiments, the determination module 410 is also used to: obtain the image to be encoded and the target code length of the image to be encoded; divide the image to be encoded into a preset number of image blocks; use the image blocks as the units to be encoded, and determine the target code length of the units to be encoded according to the target code length of the image to be encoded and the preset number.
[0107] In some embodiments, the determination module 410 is specifically used to: set two or more quantization parameters, wherein the values of the two or more quantization parameters are all less than or equal to the image bit width of the unit to be encoded; determine the minimum quantization parameter that satisfies the first condition from the two or more quantization parameters, wherein the first condition is that the coding length corresponding to the quantization parameter is less than or equal to the target code length of the unit to be encoded; divide the unit to be encoded into multiple sub-blocks, and use the minimum quantization parameter as the first quantization parameter of each sub-block of the unit to be encoded.
[0108] In some embodiments, the detection module 420 is specifically used to: perform flatness detection on each sub-block of the unit to be encoded, and / or perform grayscale value detection on each sub-block of the unit to be encoded.
[0109] In some embodiments, performing flatness detection on a sub-block includes: determining gradient values of all adjacent pixels in the sub-block; performing a first statistical processing on the gradient values of all adjacent pixels in the sub-block; and determining a flatness level of the sub-block based on a result of the first statistical processing and a first preset rule, wherein the first preset rule includes two or more judgment conditions for the flatness level.
[0110] In some embodiments, performing a first statistical processing on the gradient values of all adjacent pixel points in a sub-block includes: determining a maximum gradient value, a minimum gradient value, and an average gradient value based on the gradient values of all adjacent pixel points in the sub-block; using the maximum gradient value, the minimum gradient value, and the average gradient value as thresholds to divide two or more gradient value intervals; and counting the number of gradient values of all adjacent pixel points in the sub-block that fall into two or more gradient value intervals.
[0111] In some embodiments, grayscale value detection on a sub-block includes: determining the grayscale values of all pixels in the sub-block; performing a second statistical processing on the grayscale values of all pixels in the sub-block; and determining the grayscale value level of the sub-block based on the result of the second statistical processing and a second preset rule, wherein the first preset rule includes two or more judgment conditions for grayscale value levels.
[0112] In some embodiments, performing a second statistical processing on the grayscale values of all pixels in a sub-block includes: obtaining at least one calibrated grayscale value; using at least one calibrated grayscale value as a threshold to divide two or more grayscale value intervals; and counting the number of grayscale values of all pixels in the sub-block that fall into two or more gradient value intervals.
[0113] In some embodiments, the adjustment module 430 is specifically used to: for each sub-block of the unit to be encoded, based on a preset adjustment rule, adjust the first quantization parameter of the sub-block according to the flatness level and / or grayscale value level of the sub-block to obtain the second quantization parameter of the sub-block; for all sub-blocks of the unit to be encoded, when the second quantization parameters of all sub-blocks do not meet the first preset condition, cancel the reduction adjustment of the first quantization parameter and redetermine the second quantization parameter in the order of the grayscale value detection levels of all sub-blocks from high to low until the second quantization parameters of all sub-blocks meet the first preset condition, wherein the first preset condition includes: the coding length corresponding to the second quantization parameters of all sub-blocks is less than or equal to the target code length of the unit to be encoded.
[0114] In some embodiments, the encoding module 440 is specifically configured to: simultaneously encode two or more sub-blocks of the unit to be encoded according to the second quantization parameters of the sub-blocks until all sub-blocks of the unit to be encoded are encoded.
[0115] Since the device provided in the embodiment of the present disclosure corresponds to the methods provided in the above-mentioned embodiments, the implementation of the method is also applicable to the device provided in the embodiment and will not be described in detail in this embodiment.
[0116] In summary, the image encoding device proposed in the present invention performs image encoding by adjusting quantization parameters through a determination module, a detection module, an adjustment module and an encoding module. When adjusting the quantization parameters, the characteristics of the content to be encoded are taken into consideration to ensure better subjective quality as much as possible. At the same time, the number of quantization parameters to be traversed is small, and multiple sub-blocks can be encoded simultaneously during hardware design, which can reduce the hardware design area, shorten the encoding time and improve the encoding efficiency.
[0117] In the embodiments provided in the present application, the methods and devices provided in the embodiments of the present application are introduced. In order to implement the functions in the methods provided in the embodiments of the present application, the electronic device may include a hardware structure and a software module, and implement the functions in the form of a hardware structure, a software module, or a hardware structure plus a software module. A function of the functions may be executed in the form of a hardware structure, a software module, or a hardware structure plus a software module.
[0118] Figure 6 1 is a block diagram of an electronic device 500 for implementing the above-mentioned image encoding method according to an exemplary embodiment. For example, the electronic device 500 may be a mobile phone, a computer, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0119] Reference Figure 6, the electronic device 500 may include one or more of the following components: a processing component 502 , a memory 504 , a power component 506 , a multimedia component 508 , an audio component 510 , an input / output (I / O) interface 512 , a sensor component 514 , and a communication component 516 .
[0120] The processing component 502 generally controls the overall operation of the electronic device 500, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 502 may include one or more processors 620 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 502 may include one or more modules to facilitate the interaction between the processing component 502 and other components. For example, the processing component 502 may include a multimedia module to facilitate the interaction between the multimedia component 508 and the processing component 502.
[0121] The memory 504 is configured to store various types of data to support operations on the electronic device 500. Examples of such data include instructions for any application or method operating on the electronic device 500, contact data, phone book data, messages, pictures, videos, etc. The memory 504 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0122] The power supply component 506 provides power to the various components of the electronic device 500. The power supply component 506 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 500.
[0123] The multimedia component 508 includes a screen that provides an output interface between the electronic device 500 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 508 includes a front camera and / or a rear camera. When the electronic device 500 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0124] The audio component 510 is configured to output and / or input audio signals. For example, the audio component 510 includes a microphone (MIC), and when the electronic device 500 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 504 or sent via the communication component 516. In some embodiments, the audio component 510 also includes a speaker for outputting audio signals.
[0125] I / O interface 512 provides an interface between processing component 502 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0126] The sensor assembly 514 includes one or more sensors for providing various aspects of status assessment for the electronic device 500. For example, the sensor assembly 514 can detect the open / closed state of the electronic device 500, the relative positioning of components, such as the display and keypad of the electronic device 500, and the sensor assembly 514 can also detect the position change of the electronic device 500 or a component of the electronic device 500, the presence or absence of user contact with the electronic device 500, the orientation or acceleration / deceleration of the electronic device 500, and the temperature change of the electronic device 500. The sensor assembly 514 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 514 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 514 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0127] The communication component 516 is configured to facilitate wired or wireless communication between the electronic device 500 and other devices. The electronic device 500 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, 4G LTE, 5G NR (NewRadio) or a combination thereof. In an exemplary embodiment, the communication component 516 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 516 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0128] In an exemplary embodiment, the electronic device 500 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0129] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 504 including instructions, and the instructions can be executed by a processor 520 of an electronic device 500 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0130] The embodiments of the present disclosure further provide a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the image encoding method described in the above embodiments of the present disclosure.
[0131] An embodiment of the present disclosure further provides a computer program product, including a computer program, which executes the image encoding method described in the above embodiment of the present disclosure when a processor is used to execute the computer program.
[0132] An embodiment of the present disclosure further proposes a chip, which includes one or more interface circuits and one or more processors; the interface circuit is used to receive code instructions and transmit them to the processor, and the processor is used to run the code instructions to execute the image encoding method described in the above embodiments of the present disclosure.
[0133] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0134] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0135] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present invention belong.
[0136] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processing module, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (control method), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or otherwise processing in a suitable manner if necessary, and then stored in a computer memory.
[0137] It should be understood that the various parts of the embodiments of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0138] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0139] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium. The above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0140] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
Claims
1. An image coding method, characterized in that: The method comprises: Determining, based on a target code length of the unit to be encoded, a first quantization parameter of the unit to be encoded from two or more set quantization parameters; Performing flatness detection and / or grayscale value detection on the unit to be encoded; According to the flatness detection and / or gray value detection result, the first quantization parameter is adjusted to obtain a second quantization parameter of the unit to be encoded, wherein the encoding code length corresponding to the second quantization parameter is less than or equal to the target code length; The unit to be encoded is encoded based on the second quantization parameter.
2. The method according to claim 1, characterized in that The method further comprises: Obtaining a to-be-encoded image and a target code length of the to-be-encoded image; Dividing the image to be encoded into a preset number of image blocks; The image blocks are used as units to be encoded, and the target code length of the units to be encoded is determined according to the target code length of the image to be encoded and the preset number.
3. The method according to claim 1, characterized in that The step of determining the first quantization parameter of the unit to be encoded from a plurality of set quantization parameters based on the target code length of the unit to be encoded includes: Setting two or more quantization parameters, wherein the values of the two or more quantization parameters are all less than or equal to the image bit width of the unit to be encoded; Determine a minimum quantization parameter that satisfies a first condition from the two or more quantization parameters, wherein the first condition is that a coding length corresponding to the quantization parameter is less than or equal to a target code length of the unit to be coded; The unit to be encoded is divided into a plurality of sub-blocks, and the minimum quantization parameter is used as a first quantization parameter of each sub-block of the unit to be encoded.
4. The method according to claim 3, characterized in that The performing flatness detection and / or gray value detection on the unit to be encoded includes: For each sub-block of the unit to be encoded, a flatness detection is performed on the sub-block, And / or, for each sub-block of the unit to be encoded, perform grayscale value detection on the sub-block.
5. The method according to claim 4, characterized in that The performing flatness detection on the sub-block comprises: Determine the gradient values of all adjacent pixels in the sub-block; Performing a first statistical processing on the gradient values of all adjacent pixel points in the sub-block; The flatness level of the sub-block is determined according to the result of the first statistical processing and a first preset rule, wherein the first preset rule includes two or more judgment conditions of the flatness level.
6. The method according to claim 5, characterized in that The performing first statistical processing on the gradient values of all adjacent pixels in the sub-block comprises: Based on the gradient values of all adjacent pixels in the sub-block, determining a maximum gradient value, a minimum gradient value, and an average gradient value; Using the maximum gradient value, the minimum gradient value and the average gradient value as thresholds to divide two or more gradient value intervals; The number of gradient values of all adjacent pixels in the sub-block falling within the two or more gradient value intervals is counted.
7. The method according to claim 4, characterized in that The grayscale value detection of the sub-block comprises: Determining the grayscale values of all pixels in the sub-block; Performing second statistical processing on the grayscale values of all pixels in the sub-block; The grayscale value level of the sub-block is determined according to the result of the second statistical processing and a second preset rule, wherein the first preset rule includes two or more judgment conditions of the grayscale value level.
8. The method according to claim 7, wherein the performing second statistical processing on the grayscale values of all pixels in the sub-block comprises: Obtaining at least one calibrated grayscale value; Using the calibrated at least one grayscale value as a threshold value to divide two or more grayscale value intervals; The number of grayscale values of all pixels in the sub-block falling within the two or more gradient value intervals is counted.
9. The method according to any one of claims 5 to 8, characterized in that: The adjusting the first quantization parameter according to the flatness detection and / or gray value detection result to obtain the second quantization parameter of the unit to be encoded includes: For each sub-block of the unit to be encoded, based on a preset adjustment rule, according to the flatness level and / or gray value level of the sub-block, a first quantization parameter of the sub-block is adjusted to obtain a second quantization parameter of the sub-block; For all sub-blocks of the unit to be encoded, when the second quantization parameters of all the sub-blocks do not meet the first preset condition, canceling the reduction adjustment of the first quantization parameter and re-determining the second quantization parameter in a descending order of the gray value detection levels of all the sub-blocks until the second quantization parameters of all the sub-blocks meet the first preset condition, The first preset condition includes: the coding length corresponding to the second quantization parameters of all sub-blocks is less than or equal to the target code length of the unit to be encoded.
10. The method according to claim 9, characterized in that The encoding the to-be-encoded unit based on the second quantization parameter includes: At the same time, for two or more sub-blocks of the unit to be encoded, the sub-blocks are encoded according to the second quantization parameters of the sub-blocks until all the sub-blocks of the unit to be encoded are encoded.
11. An image encoding device, characterized in that: The device comprises: A determination module, configured to determine a first quantization parameter of the unit to be encoded from a plurality of set quantization parameters based on a target code length of the unit to be encoded; A detection module, used to perform flatness detection and / or gray value detection on the unit to be encoded; an adjustment module, configured to adjust the first quantization parameter according to the flatness detection and / or gray value detection result to obtain a second quantization parameter of the unit to be encoded, wherein the encoding code length corresponding to the second quantization parameter is less than or equal to the target code length; An encoding module is used to encode the unit to be encoded based on the second quantization parameter.
12. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 10.
13. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-10.
14. A chip, characterized in that: The method comprises one or more interface circuits and one or more processors; the interface circuit is used to receive code instructions and transmit them to the processor, and the processor is used to run the code instructions to execute the method according to any one of claims 1 to 10.
