Image coding method and device, electronic equipment and storage medium
By adjusting the preset bit value attributes of the color space data, the encoding of images with alpha channels was achieved, which solved the problem that existing encoders do not support alpha channel compression encoding, reduced the transmission bit rate, and improved the user experience.
Patent Information
- Application Number
- CN202310092183.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-17
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2043-01-17
AI Technical Summary
Existing encoders do not support image compression encoding with alpha channels, resulting in significant grayscale loss, and high encoding bitrates are not suitable for use in bandwidth-constrained audio-visual conferencing scenarios.
By separating the color space data and alpha channel data of the image to be encoded, adjusting the numerical attributes of a preset bit in at least one channel of the color space data, composite color space data is obtained, and encoding is performed based on this. The encoded data includes only color space channel data in form, and implicitly carries alpha channel data.
Image encoding with an alpha channel was achieved without modifying the encoder, reducing the image transmission bitrate, saving bandwidth, and improving the user experience of audio and video conferencing.
Smart Images

Figure CN116112679B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image encoding / decoding method, apparatus, electronic device, and storage medium. Background Technology
[0002] To enable the use of virtual avatars in remote video conferencing, the current method is to perform background matting. However, background matting places high demands on the performance of the receiving device, is difficult to handle image edges, and requires a separate transmission of the mask image.
[0003] Images with alpha channels can effectively solve the above problems, and most current rendering engines support rendering images with alpha channels. Therefore, it becomes possible to transmit images or videos, such as virtual avatars, based on images with alpha channels.
[0004] However, mainstream encoders do not support compressed encoding of images with alpha channels. Compressed encoding will result in a significant loss of grayscale values in the alpha channel, and high encoding bitrates are not suitable for use in bandwidth-constrained audio-visual conferencing scenarios. Summary of the Invention
[0005] This invention provides an image encoding and decoding method, apparatus, electronic device, and storage medium to solve the defects of existing technologies in image encoding with transparency channels, such as large grayscale value loss, high bit rate, and unsuitability for bandwidth-limited transmission scenarios.
[0006] This invention provides an image encoding method, comprising:
[0007] Separate the color space data and transparency channel data of the image to be encoded;
[0008] Based on the transparency channel data, the numerical attributes of a preset bit in at least one channel of the color space data are adjusted to obtain composite color space data.
[0009] Based on the composite color space data, the image to be encoded is encoded to obtain encoded data.
[0010] According to an image encoding method provided by the present invention, the step of adjusting the numerical attributes of a preset bit of at least one channel data in the color space data based on the transparency channel data to obtain composite color space data includes:
[0011] Target channel data is determined from the color space data, and the values in the target channel data correspond one-to-one with the pixels of the image to be encoded;
[0012] Based on the transparency channel data, the numerical attributes of the preset position of the target channel data are adjusted to obtain composite color space data.
[0013] According to an image encoding method provided by the present invention, the step of adjusting the numerical attributes of a preset bit of the target channel data based on the transparency channel data to obtain composite color space data includes:
[0014] At least one auxiliary channel data is determined from the color space data, wherein the total amount of data in the at least one auxiliary channel data is the same as the amount of data in the target channel data;
[0015] Based on the transparency channel data, the numerical attributes of preset positions of the target channel data and the at least one auxiliary channel data are adjusted to obtain the composite color space data.
[0016] According to an image encoding method provided by the present invention, the preset bit is the least significant bit of the channel data.
[0017] This invention provides an image decoding method, comprising:
[0018] Decode the encoded data to obtain the composite color space data of the decoded image;
[0019] Based on the numerical attribute of a preset bit in at least one channel of the composite color space data, the transparency channel data of the decoded image is restored.
[0020] The decoded image is reconstructed based on the composite color space data and the transparency channel data.
[0021] According to an image decoding method provided by the present invention, the step of restoring the transparency channel data of the decoded image based on the numerical attribute of a preset bit of at least one channel data in the composite color space data includes:
[0022] Based on the numerical attributes of the preset bits of the target channel data in the composite color space data, the transparency channel data of the decoded image is restored.
[0023] The values in the target channel data correspond one-to-one with the pixels of the decoded image.
[0024] According to an image decoding method provided by the present invention, the step of restoring the transparency channel data of the decoded image based on the numerical attribute of a preset bit of the target channel data in the composite color space data includes:
[0025] If the numerical attribute of any pixel in the decoded image corresponding to a preset position in the target channel data is consistent with the numerical attribute of any pixel in a preset position in at least one auxiliary channel data in the composite color space data, the value of any pixel in the transparency channel data is determined based on the numerical attribute.
[0026] The total amount of data in the at least one auxiliary channel is the same as the amount of data in the target channel.
[0027] According to an image decoding method provided by the present invention, the step of restoring the transparency channel data of the decoded image based on the numerical attribute of a preset bit of the target channel data in the composite color space data further includes:
[0028] If the numerical attribute of any pixel in the target channel data is inconsistent with the numerical attribute of any pixel in the preset position of at least one auxiliary channel data, the value of any pixel in the transparency channel data is determined based on the value of the neighboring pixels of any pixel in the transparency channel data.
[0029] According to an image decoding method provided by the present invention, the preset bit is the least significant bit of the channel data.
[0030] The present invention also provides an image encoding apparatus, comprising:
[0031] The separation unit is used to separate the color space data and transparency channel data of the image to be encoded.
[0032] A composite unit is used to adjust the numerical attribute of a preset bit in at least one channel of the color space data based on the transparency channel data to obtain composite color space data.
[0033] The encoding unit is used to encode the image to be encoded based on the composite color space data to obtain encoded data.
[0034] The present invention also provides an image decoding apparatus, comprising:
[0035] The decoding unit is used to decode the encoded data to obtain the composite color space data of the decoded image;
[0036] The transparency channel data unit is used to restore the transparency channel data of the decoded image based on the numerical attribute of a preset bit of at least one channel data in the composite color space data.
[0037] The image restoration unit is used to restore the decoded image based on the composite color space data and the transparency channel data.
[0038] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement any of the image encoding or image decoding methods described above.
[0039] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the image encoding method or image decoding method as described above.
[0040] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements any of the image encoding or image decoding methods described above.
[0041] The image encoding and decoding method, apparatus, electronic device, and storage medium provided by this invention adjust the numerical attributes of a preset bit in at least one channel of color space data by using the transparency channel data of the image to be encoded to obtain composite color space data. Based on the composite color space data, the image to be encoded is encoded. Thus, image encoding with a transparency channel is achieved without modifying the encoder. The resulting encoded image only includes color space channel data in form. Transmission based on this can reduce the image transmission bit rate, save bandwidth, and improve the user experience in audio and video conferencing scenarios. Attached Figure Description
[0042] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0043] Figure 1 This is a flowchart illustrating the image encoding method provided by the present invention;
[0044] Figure 2 This is a flowchart illustrating the image decoding method provided by the present invention;
[0045] Figure 3 This is a schematic diagram of the image encoding device provided by the present invention;
[0046] Figure 4 This is a schematic diagram of the image decoding device provided by the present invention;
[0047] Figure 5 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0048] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0049] When implementing background customization, related technologies generally use images with a transparency channel, i.e., an alpha channel, to transmit images or videos such as virtual avatars. However, current image compression coding technologies result in significant loss of grayscale values in the alpha channel, and high coding bitrates are not suitable for use in bandwidth-constrained audio-visual conferencing scenarios.
[0050] To address the aforementioned problems, this invention proposes an image encoding method to achieve image compression encoding with a transparency channel and reduce the transmission bit rate to adapt to bandwidth-constrained transmission scenarios. Figure 1 This is a flowchart illustrating the image encoding method provided by the present invention, as shown below. Figure 1 As shown, the method includes:
[0051] Step 110: Separate the color space data and transparency channel data of the image to be encoded;
[0052] Here, the image to be encoded is an image with an alpha channel. The image to be encoded can be an RGBA (Red, Green, Blue, Alpha, transparency) image, or it can be a YUVA (Y represents brightness, U and V represent color difference, Alpha, transparency) image.
[0053] Considering that mainstream encoders do not support compression encoding of images with alpha channels, this embodiment of the invention proposes to separate the channel data of the image to be encoded, thereby obtaining the color space data of the image to be encoded, such as RGB data or YUV data, and the alpha channel data.
[0054] For example, separating an image to be encoded in RGBA format yields RGB data and alpha channel data. Further, if the image to be encoded consists of N pixels, each corresponding to one RGBA data point, and each pixel's RGBA data is separated into RGB data and alpha channel data, then N sets of separated RGB and alpha data are obtained. This can take the following form:
[0055]
[0056] Step 120: Based on the transparency channel data, adjust the numerical attribute of a preset bit in at least one channel of the color space data to obtain composite color space data;
[0057] Specifically, to adapt to mainstream encoders, this embodiment of the invention proposes representing the transparency channel data by the numerical attribute of a preset bit in at least one channel data in the color space data, thereby obtaining composite color space data. The channel data to be adjusted here can be one or more channels in the color space data. For example, the preset bit of the Y channel data in YUV format color space data can be adjusted to obtain composite color space data. Furthermore, the numerical attribute referred to here can be an even or odd value, a prime number, a composite number, or a preset fixed value, such as 0 or 1; this embodiment of the invention does not specifically limit this.
[0058] Understandably, channel data in color space is typically represented by multiple hexadecimal digits. Using a specific bit in the channel data as a preset bit and adjusting its numerical properties will not significantly alter the value of that channel data. For example, using the least significant bit in the channel data as a preset bit and adjusting its parity ensures that the least significant bit covers the value of the corresponding transparency channel while minimizing the impact of reusing channel data on the original channel data.
[0059] Furthermore, the reason why numerical attributes can be used to represent alpha channel data is that in video conferencing scenarios or similar situations, the pixel values of the alpha channel in an image exhibit a certain pattern. Typically, some areas are transparent, and some areas are opaque; there is no intermediate value between transparent and opaque, meaning the alpha channel data value is either 0 or 255. Therefore, a preset numerical attribute can be used to represent the alpha channel data. For example, for an alpha channel data value of 0, the preset bit can be adjusted to an even number; for an alpha channel data value of 255, the preset bit can be adjusted to an odd number. Similarly, for an alpha channel data value of 0, the preset bit can be adjusted to a composite number; for an alpha channel data value of 255, the preset bit can be adjusted to a prime number.
[0060] The resulting composite color space data contains a numerical attribute of a preset bit in at least one channel data, representing the transparency channel data. Without significantly affecting the channel data itself, it also carries the transparency channel data of that pixel, thus realizing the reuse of channel data in the color space data.
[0061] Step 130: Encode the image to be encoded based on the composite color space data to obtain encoded data.
[0062] Specifically, composite color space data, which includes the color space data and alpha channel data of the image to be encoded, is essentially still data in color space format, and therefore can be compressed and encoded using common encoders such as the H.264 encoder. This yields the encoded data of the image to be encoded.
[0063] Furthermore, after encoding is completed, the encoded data can be transmitted from the sending end to the receiving end to achieve image transmission. It is understandable that the transmitted encoded data is obtained by encoding data in color space format, thus enabling normal transmission in bandwidth-constrained scenarios. Since the composite color space data implicitly carries alpha channel data through data multiplexing, the receiving end can decode the composite color space data after receiving the encoded data and reconstruct the alpha channel data from it. Therefore, image transmission with an alpha channel is achieved.
[0064] The method provided in this invention adjusts the numerical attributes of a preset bit in at least one channel of color space data using the transparency channel data of the image to be encoded to obtain composite color space data. Based on the composite color space data, the image to be encoded is then encoded. Thus, image encoding with a transparency channel is achieved without modifying the encoder. The resulting encoded image only includes the channel data of the color space data. Transmission based on this reduces the image transmission bitrate, saves bandwidth, and improves the user experience in audio and video conferencing scenarios.
[0065] Based on the above embodiments, step 120 includes:
[0066] Target channel data is determined from the color space data, and the values in the target channel data correspond one-to-one with the pixels of the image to be encoded;
[0067] Based on the transparency channel data, the numerical attributes of the preset position of the target channel data are adjusted to obtain composite color space data.
[0068] Specifically, at least one channel can be selected from the color space data as the target channel data. Here, the target channel data carries the alpha channel data of that pixel. It is understood that the image to be encoded consists of multiple pixels, and each pixel's data includes color space data and a corresponding alpha channel. Therefore, the selected target channel data must correspond one-to-one with the pixels of the image to be encoded. For example, in the YUV420 color space format, the ratio of the Y, U, and V components is 4:2:0, meaning the Y channel data corresponds one-to-one with the pixels of the image to be encoded. In this case, the Y channel data can be preferred as the target channel data. It is understood that selecting channel data that corresponds one-to-one with the pixels of the image to be encoded as the target channel data ensures that the alpha channel data of each pixel can be carried by the target channel data.
[0069] After determining the target channel data, the alpha channel data can be represented by the numerical attribute of a preset bit in the target channel data. For example, the parity value of the preset bit can be used to represent the alpha channel data. The specific steps are as follows: When the alpha channel data represents transparency, adjust the parity value of the preset bit in the target channel data. If the preset bit value is even, it remains unchanged; if it is odd, the preset bit is adjusted to an even value. For example, a bitwise OR operation with 0x01 can be performed on the preset bit to obtain an even value. When the alpha channel data represents opacity, adjust the parity value of the preset bit in the target channel data. If the preset bit value is odd, it remains unchanged; if it is even, the preset bit is adjusted to an odd value. For example, a bitwise OR operation with 0x01 can be performed on the preset bit to obtain an odd value. The composite color space data obtained from the above steps, where the target channel data represents the channel data of its own color space data, and the parity value of its preset bit represents the alpha channel data.
[0070] In related technologies, encoding and compressing the image to be encoded, such as compressing YUV420 format data using H264, is lossy compression. Furthermore, the selected target channel data carries alpha channel data. When lossy encoding occurs, the preset values of the target channel data carrying the alpha channel data may change. In this case, the method of reflecting the alpha channel data of a pixel through the numerical attribute of the preset value will become ineffective.
[0071] To address this issue, based on any of the above embodiments, step 120, which involves adjusting the numerical attributes of a preset bit in the target channel data based on the transparency channel data to obtain composite color space data, includes:
[0072] At least one auxiliary channel data is determined from the color space data, wherein the total amount of data in the at least one auxiliary channel data is the same as the amount of data in the target channel data;
[0073] Based on the transparency channel data, the numerical attributes of preset positions of the target channel data and the at least one auxiliary channel data are adjusted to obtain the composite color space data.
[0074] Specifically, from the channel data contained in the color space data, at least one auxiliary channel data can be identified to assist the target channel data, carrying the corresponding alpha channel data together. It is understood that the auxiliary channel data and the target channel data cannot be the same channel data, and in order to ensure that the alpha channel data of each pixel is carried together with the target channel data by the auxiliary channel data, the number of the aforementioned at least one auxiliary channel data must be consistent with the number of target channel data.
[0075] In other words, if there is a channel in the color space data that corresponds one-to-one with a pixel (excluding the target channel), that channel can be directly used as an auxiliary channel. However, if there is no channel in the color space data that corresponds one-to-one with a pixel (excluding the target channel), at least two channels are needed as auxiliary channels to ensure that all values in the auxiliary channels correspond one-to-one with pixels. For example, if the image to be encoded is in YUV420 format, and the Y channel is used as the target channel, then both the UV and Y channels need to be used as auxiliary channels. That is, the Y channel is divided into four equal parts. The parity values of the preset bits corresponding to the pixels in the first two divisions of the Y channel correspond to the parity values of the preset bits in the U channel, and the parity values of the pixels in the last two divisions of the Y channel correspond to the parity values of the preset bits in the V channel.
[0076] In this case, the value of the alpha channel of each pixel is represented by the numerical attribute of a preset position in the target channel data of the composite color space data, and the numerical attribute of a preset position in at least one auxiliary channel data. Furthermore, in the composite color space data, the numerical attributes of the preset positions representing the alpha channel value of the same pixel are consistent between the target channel data and the auxiliary channel data.
[0077] Therefore, if the encoding compression is lossy, causing the numerical attributes of the target channel data and the auxiliary channel data corresponding to the same pixel to be inconsistent after decoding and restoration of the encoded data, the receiving end can directly determine that the transparency value determined by the numerical attributes of the pixel is unreliable and needs to be corrected. In this way, the reliability of image transmission with transparency channel can be guaranteed.
[0078] Based on any of the above embodiments, the preset bit is the least significant bit of the channel data.
[0079] Specifically, a preset bit is selected in the channel data of the color space data, and its numerical attribute is modified to represent the corresponding transparency channel data. It can be understood that the channel data of the image to be encoded is represented in multi-digit hexadecimal notation. Rather than adjusting the higher-order bits of the channel data, using the lowest-order bit as the preset bit minimizes the impact on the overall channel data value when adjusting its numerical attribute.
[0080] After the image to be encoded is transmitted, the transmitting end can send the encoded image data to the receiving end. Upon receiving the encoded data, the receiving end needs to decode it to reconstruct the image.
[0081] Figure 2 This is a flowchart illustrating the image decoding method provided by the present invention, as shown below. Figure 2 As shown, an image decoding method includes:
[0082] Step 210: Decode the encoded data to obtain the composite color space data of the decoded image;
[0083] Specifically, after receiving the encoded data, the receiving end decodes it using an image decoder to obtain the composite color space data of the decoded image. This image decoder can be an H.264 decoder or other general-purpose decoders. It is understood that the image decoder used for decoding corresponds to the image encoder used for encoding in the aforementioned image encoding method.
[0084] The composite color space data obtained through decoding allows the numerical attribute of a preset bit in at least one channel to be used to characterize the transparency channel value of the corresponding pixel. Therefore, the composite color space data obtained after decoding encoded data, although formally color space data, actually encompasses transparency channel data through data multiplexing. In other words, the composite color space data not only provides the color space data of the decoded image but also its transparency channel data.
[0085] It is understandable that the reason why the decoded composite color space data can carry transparency channel data is that before encoding, the value attributes of at least one preset bit of the color space data of the image to be encoded are adjusted using the transparency channel data of the image to be encoded. In other words, the composite color space data corresponding to the encoded data before encoding involves data reuse of channel data. The specific encoding method can be seen in the above embodiments, and will not be repeated here.
[0086] Step 220: Based on the numerical attribute of a preset bit in at least one channel data in the composite color space data, restore the transparency channel data of the decoded image;
[0087] Specifically, during image encoding, the transparency channel data of a pixel is represented by adjusting the numerical values of preset bits in at least one channel of the image's color space data. Therefore, when decoding the composite color space data, the transparency channel data of the decoded image must also be reconstructed based on the numerical values of the preset bits in at least one channel. The method for reconstructing the transparency channel data of the decoded image is also determined by the correspondence between the numerical values of the preset bits of the channel data and the transparency channel data of the image. It can be understood that this correspondence is consistent with the correspondence between the transparency channel data of the image and the numerical values of the preset bits of the channel data in the color space data when the image is to be encoded. For example, when decoding an image, if the transparency channel data is transparent, the parity value of the preset bits of the channel data in the color space is adjusted to an even number. Therefore, when reconstructing the transparency channel data of the decoded image, if the parity value of the preset bits of the channel data is even, the transparency channel data of the decoded image is transparent.
[0088] Furthermore, image encoding involves adjusting at least one channel of the color space data. Therefore, restoring the transparency channel data of the decoded image also corresponds to restoring one or more channels of the color space data. It's understandable that these one or more channels are the same as the one or more channels in the image being encoded; the specific channels selected can be pre-agreed upon by the sender and receiver. For example, if the image is adjusted using the Y channel data in the color space data during encoding, then restoring the transparency channel data of the decoded image is also done based on the Y channel data in the color space data.
[0089] Step 230: Based on the composite color space data and the transparency channel data, reconstruct the decoded image.
[0090] Specifically, the decoded image can be restored based on the color space data and alpha channel data in the composite color space data. Here, restoring the decoded image involves fusing the color space data and alpha channel data of the decoded image to obtain an image with an alpha channel, i.e., the decoded image.
[0091] The method provided in this invention decodes encoded data to obtain composite color space data. Based on the numerical attributes of a preset bit in at least one channel of the composite color space data, the transparency channel data of the decoded image is restored. Finally, the decoded image is restored using the composite color space data and the transparency channel data. This eliminates the need to additionally receive the transparency channel data, thus achieving image decoding with a transparency channel. Transmission based on this reduces the image transmission bitrate, saves bandwidth, and improves the user experience in audio and video conferencing scenarios.
[0092] Based on any of the above embodiments, step 220 includes:
[0093] Based on the numerical attributes of the preset bits of the target channel data in the composite color space data, the transparency channel data of the decoded image is restored.
[0094] The values in the target channel data correspond one-to-one with the pixels of the decoded image.
[0095] Specifically, the target channel data here is the channel data obtained by the receiving end decoding the received encoded data. It corresponds to adjusting the numerical attributes of preset bits in the target channel data based on the transparency channel data during encoding. The decoded target channel data also carries the transparency channel data and its own channel data for that pixel. It can be understood that when restoring the transparency channel data, the mapping between the numerical attributes of the preset bits in the target channel data and the transparency channel data in the decoded image is also used to restore the transparency channel data of the decoded image. For example, during image encoding, if the transparency channel data of the image is transparent and the parity value of the preset bits in the target channel data is even, then when restoring the decoded image, if the parity value of the preset bits in the target channel data is even, the transparency channel data of the decoded image will be transparent.
[0096] It's understandable that a decoded image consists of multiple pixels, each containing color space data and a corresponding alpha channel. Therefore, the selected target channel data must correspond one-to-one with the pixels in the decoded image. For example, in the YUV420 color space, the ratio of the Y, U, and V components is 4:2:0, meaning the Y channel data corresponds one-to-one with the pixels in the decoded image. In this case, the Y channel data can be preferred as the target channel data. Choosing the channel data that corresponds one-to-one with the pixels in the decoded image as the target channel data ensures that the alpha channel data of each pixel can be reconstructed from the corresponding target channel data.
[0097] In related technologies, encoding and compressing the image to be encoded, such as compressing YUV420 data using H264, is lossy compression. Furthermore, the selected target channel data carries alpha channel data. When lossy encoding occurs on the image to be encoded, the preset values of the target channel data carrying the alpha channel data may change. In this case, the method of restoring the alpha channel data of that pixel through the numerical attributes of the preset values will fail.
[0098] To address this issue, based on any of the above embodiments, the step of restoring the transparency channel data of the decoded image based on the numerical attributes of a preset bit in the target channel data of the composite color space data includes:
[0099] If the numerical attribute of any pixel in the decoded image corresponding to a preset position in the target channel data is consistent with the numerical attribute of any pixel in a preset position in at least one auxiliary channel data in the composite color space data, the value of any pixel in the transparency channel data is determined based on the numerical attribute.
[0100] The total amount of data in the at least one auxiliary channel is the same as the amount of data in the target channel.
[0101] Specifically, from the channel data of the color space data, at least one channel data is determined as auxiliary channel data to assist the target channel data, carrying together the alpha channel data corresponding to that pixel. For example, if the parity value of the preset bit of the target channel data is even, and the parity value of the preset bit of the auxiliary channel data is also even, then the alpha channel data of the current pixel is transparent; if the parity value of the preset bit of the target channel data is odd, and the parity value of the preset bit of the auxiliary channel data is also odd, then the alpha channel data of the current pixel is opaque.
[0102] It is understandable that the auxiliary channel data and the target channel data cannot be the same channel data. Furthermore, in order to ensure that the transparency channel data of each pixel is carried along with the auxiliary channel data and the target channel data, the number of at least one auxiliary channel data must be consistent with the number of target channel data.
[0103] In other words, if there is a channel in the color space data other than the target channel that corresponds one-to-one with a pixel, that channel can be directly used as an auxiliary channel. However, if there is no channel in the color space data other than the target channel that corresponds one-to-one with a pixel, then at least two channels are needed as auxiliary channels to ensure that all values in the auxiliary channels correspond one-to-one with pixels. For example, if the image to be encoded is in YUV420 format, and the Y channel data is used as the target channel data, then both the UV and Y channels need to be used as auxiliary channels. That is, the Y channel data is divided into four equal parts. The parity values of the preset positions corresponding to the pixels in the first two equal parts of the Y channel data can correspond to the parity values of the preset positions in the U channel, and the parity values of the pixels in the last two equal parts of the Y channel data can correspond to the parity values of the preset positions in the V channel.
[0104] In this case, the value of the alpha channel of each pixel is represented by the numerical attribute of a preset position in the target channel data of the composite color space data, and the numerical attribute of a preset position in at least one auxiliary channel data. Furthermore, the alpha channel data of the decoded image can only be reconstructed based on the numerical attribute of the preset position if the numerical attributes of the preset positions in the target channel data and auxiliary channel data representing the alpha channel value of the same pixel are consistent.
[0105] If the encoding compression is lossy, it may cause the numerical attributes of the target channel data and the auxiliary channel data corresponding to the same pixel to be inconsistent after the encoding data is decoded and restored. In this case, the receiving end can directly determine that the transparency value determined by the numerical attribute of the pixel is unreliable and needs to be corrected. This can ensure the reliability of image transmission with transparency channel.
[0106] To address this problem, based on any of the above embodiments, the step of restoring the transparency channel data of the decoded image based on the numerical attributes of a preset bit in the target channel data of the composite color space data further includes:
[0107] If the numerical attribute of any pixel in the target channel data is inconsistent with the numerical attribute of any pixel in the preset position of at least one auxiliary channel data, the value of any pixel in the transparency channel data is determined based on the value of the neighboring pixels of any pixel in the transparency channel data.
[0108] Specifically, if the numerical attributes of the target channel data and auxiliary channel data corresponding to the same pixel are inconsistent after decoding the encoded data, it means that the transparency channel value of that pixel determined based on the numerical attributes is unreliable. In this case, the transparency channel value of that pixel can be determined by referring to the transparency channel values of its neighboring pixels that have already been restored. For example, the principle that the transparency channel data of neighboring pixels are similar can be applied to determine the number of neighboring pixels with transparency channel values of 0 and the number with transparency channel values of 255. If the number of neighboring pixels with values of 0 is greater than the number of neighboring pixels with values of 255, then the transparency channel value of that pixel is determined to be 0; otherwise, the transparency channel value of that pixel is determined to be 255.
[0109] The method provided in this invention restores the transparency channel data based on the values of neighboring pixels in the transparency channel data under lossy conditions, thereby ensuring the accuracy and reliability of the transparency channel data restoration.
[0110] Based on any of the above embodiments, the preset bit is the least significant bit of the channel data.
[0111] Specifically, a preset bit is selected in the channel data of the color space data, and its numerical attribute is modified to represent the corresponding transparency channel data. It can be understood that the channel data of the decoded image is represented using multi-digit hexadecimal notation. Rather than adjusting the higher-order bits of the channel data, using the lowest-order bit as the preset bit minimizes the impact on the overall channel data value when adjusting its numerical attribute.
[0112] Based on any of the above embodiments, the present invention also provides an image encoding method, which can be implemented through the following steps:
[0113] First, separate the color space data and alpha channel data of the image to be encoded. Specifically, this can be done by separating the input RGBA format image to be encoded into RGB data and alpha channel data respectively. The length of the image to be encoded is denoted as H, and the width is denoted as W.
[0114] Since current encoding devices, such as H.264 encoders, generally use YUV format image data for image encoding, it is necessary to convert the RGB data obtained from separating the image to be encoded into YUV data. The conversion from RGB data to YUV data can be achieved using the following formula:
[0115]
[0116] Therefore, the converted YUV data can represent the color space data of the image to be encoded. The lengths of the Y channel data and the Alpha channel data are both equal to the product of the image length H and the image width W. YUV format data also includes YUV420, YUV444, and other formats. This embodiment of the invention uses YUV420 format data, where the ratio of the Y component, U component, and V component is 4:2:0.
[0117] Next, the Y channel data can be used as the target channel data, and the UV channel data as the auxiliary channel data. When the alpha channel data is transparent, the parity value of the least significant bit of the Y and UV channel data is adjusted to an even number; when the alpha channel data is opaque, the parity value of the least significant bit of the Y and UV channel data is adjusted to an odd number, thus obtaining the composite color space data.
[0118] Next, based on the composite color space data, the image to be encoded is encoded to obtain encoded data.
[0119] Furthermore, the present invention also provides an image decoding method, which can be implemented through the following steps:
[0120] First, the receiving end obtains the encoded data transmitted by the sending end.
[0121] Next, the encoded data is decoded to obtain the composite color space data of the decoded image.
[0122] Then, based on the parity values of the least significant bits of the target channel data and auxiliary channel data in the obtained composite color space data, the transparency channel data is restored. The restoration steps can be as follows: if the parity value of the least significant bit of the Y channel data is even, and the parity value of the least significant bit of the UV channel data is also even, then the transparency channel data of the current pixel is transparent; if the parity value of the least significant bit of the Y channel data is odd, and the parity value of the least significant bit of the UV channel data is also odd, then the transparency channel data of the current pixel is opaque; if the parity value of the least significant bit of the Y channel data is inconsistent with the parity value of the least significant bit of the auxiliary channel data, the transparency channel data of the pixel can be determined based on the transparency channel data of the neighboring pixels.
[0123] The YUV and Alpha channel data of the decoded image obtained through the above steps can be directly fused to obtain a YUVA format image. Alternatively, the YUV data can be converted to RGB data using the following formula:
[0124]
[0125] Finally, the RGB data and Alpha channel data of the decoded image are fused to obtain an RGBA format image, which is an image with transparency. This image can then be rendered by the rendering engine according to different background images customized by the user, making it easy to customize the background and replace different backgrounds in the images of audio-visual conferences.
[0126] Based on any of the above embodiments Figure 3 This is a schematic diagram of the image encoding device provided by the present invention, as shown below. Figure 3 As shown, the device includes:
[0127] Separation unit 310 is used to separate the color space data and transparency channel data of the image to be encoded;
[0128] The composite unit 320 is used to adjust the numerical attribute of a preset bit of at least one channel data in the color space data based on the transparency channel data to obtain composite color space data.
[0129] The encoding unit 330 is used to encode the image to be encoded based on the composite color space data to obtain encoded data.
[0130] The apparatus provided in this invention adjusts the numerical attributes of a preset bit in at least one channel of color space data using the transparency channel data of the image to be encoded to obtain composite color space data. Based on the composite color space data, the image to be encoded is encoded. Thus, image encoding with a transparency channel is achieved without modifying the encoder. The resulting encoded image only includes color space channel data in form. Transmission based on this can reduce the image transmission bit rate, save bandwidth, and improve the user experience in audio and video conferencing scenarios.
[0131] Based on any of the above embodiments, the composite unit is further used for:
[0132] Target channel data is determined from the color space data, and the values in the target channel data correspond one-to-one with the pixels of the image to be encoded;
[0133] Based on the transparency channel data, the numerical attributes of the preset position of the target channel data are adjusted to obtain composite color space data.
[0134] Based on any of the above embodiments, the composite unit is further used for:
[0135] At least one auxiliary channel data is determined from the color space data, wherein the total amount of data in the at least one auxiliary channel data is the same as the amount of data in the target channel data;
[0136] Based on the transparency channel data, the numerical attributes of preset positions of the target channel data and the at least one auxiliary channel data are adjusted to obtain the composite color space data.
[0137] Based on any of the above embodiments, the composite unit is further configured to: the preset bit is the least significant bit of the channel data.
[0138] Based on any of the above embodiments Figure 4 This is a schematic diagram of the image decoding device provided by the present invention, as shown below. Figure 4 As shown, the device includes:
[0139] Decoding unit 410 is used to decode the encoded data to obtain the composite color space data of the decoded image;
[0140] Transparency channel data unit 420 is used to restore the transparency channel data of the decoded image based on the numerical attribute of a preset bit of at least one channel data in the composite color space data.
[0141] The image restoration unit 430 is used to restore the decoded image based on the composite color space data and the transparency channel data.
[0142] The apparatus provided in this invention decodes encoded data to obtain composite color space data. Based on the numerical attributes of preset bits in at least one channel of the composite color space data, the transparency channel data of the decoded image is restored. Finally, the decoded image is restored using the composite color space data and the transparency channel data. This eliminates the need to additionally receive the transparency channel data, enabling image decoding with a transparency channel. Furthermore, the transparency channel data is determined by the numerical attributes of preset bits in multiple channel data. Decoding based on this allows for timely detection of encoding compression loss and the restoration of more accurate transparency channel data, thus more accurately restoring the decoded image.
[0143] Based on any of the above embodiments, the transparency channel data unit is further used for:
[0144] Based on the numerical attributes of the preset bits of the target channel data in the composite color space data, the transparency channel data of the decoded image is restored.
[0145] The values in the target channel data correspond one-to-one with the pixels of the decoded image.
[0146] Based on any of the above embodiments, the transparency channel data unit is further used for:
[0147] If the numerical attribute of any pixel in the decoded image corresponding to a preset position in the target channel data is consistent with the numerical attribute of any pixel in a preset position in at least one auxiliary channel data in the composite color space data, the value of any pixel in the transparency channel data is determined based on the numerical attribute.
[0148] The total amount of data in the at least one auxiliary channel is the same as the amount of data in the target channel.
[0149] Based on any of the above embodiments, the transparency channel data unit is further used for:
[0150] If the numerical attribute of any pixel in the target channel data is inconsistent with the numerical attribute of any pixel in the preset position of at least one auxiliary channel data, the value of any pixel in the transparency channel data is determined based on the value of the neighboring pixels of any pixel in the transparency channel data.
[0151] Based on any of the above embodiments, the transparency channel data unit is further configured such that the preset bit is the least significant bit of the channel data.
[0152] Figure 5 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 5 As shown, the electronic device may include a processor 510, a communication interface 520, a memory 530, and a communication bus 540, wherein the processor 510, the communication interface 520, and the memory 530 communicate with each other via the communication bus 540. The processor 510 can call logical instructions in the memory 530 to execute an image encoding method, which includes: separating color space data and transparency channel data of the image to be encoded; adjusting the numerical attributes of a preset bit in at least one channel of the color space data based on the transparency channel data to obtain composite color space data; and encoding the image to be encoded based on the composite color space data to obtain encoded data.
[0153] The processor 510 can also call logic instructions in the memory 530 to execute an image decoding method, the method comprising: decoding encoded data to obtain composite color space data of a decoded image; restoring transparency channel data of the decoded image based on the numerical attributes of a preset bit of at least one channel data in the composite color space data; and restoring the decoded image based on the composite color space data and the transparency channel data.
[0154] Furthermore, the logical instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0155] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the image encoding method provided by the above methods. The method includes: separating color space data and transparency channel data of an image to be encoded; adjusting the numerical attributes of a preset bit of at least one channel data in the color space data based on the transparency channel data to obtain composite color space data; and encoding the image to be encoded based on the composite color space data to obtain encoded data.
[0156] When the computer program is executed by the processor, the computer can also execute the image decoding method provided by the above methods, which includes: decoding the encoded data to obtain composite color space data of the decoded image; restoring the transparency channel data of the decoded image based on the numerical attribute of a preset bit of at least one channel data in the composite color space data; and restoring the decoded image based on the composite color space data and the transparency channel data.
[0157] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When executed by a processor, the computer program implements the image encoding method provided by the above methods. The method includes: separating color space data and transparency channel data of an image to be encoded; adjusting the numerical attributes of a preset bit of at least one channel data in the color space data based on the transparency channel data to obtain composite color space data; and encoding the image to be encoded based on the composite color space data to obtain encoded data.
[0158] When executed by a processor, the computer program also implements an image decoding method to perform the methods described above, the method comprising: decoding encoded data to obtain composite color space data of a decoded image; restoring transparency channel data of the decoded image based on the numerical attributes of a preset bit of at least one channel data in the composite color space data; and restoring the decoded image based on the composite color space data and the transparency channel data.
[0159] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0160] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0161] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An image encoding method, characterized in that, include: Separate the color space data and transparency channel data of the image to be encoded; Based on the transparency channel data, the numerical attributes of a preset bit in at least one channel of the color space data are adjusted to obtain composite color space data. Based on the composite color space data, the image to be encoded is encoded to obtain encoded data; The step of adjusting the numerical attributes of a preset bit in at least one channel of the color space data based on the transparency channel data to obtain composite color space data includes: Target channel data is determined from the color space data, and the values in the target channel data correspond one-to-one with the pixels of the image to be encoded; At least one auxiliary channel data is determined from the color space data, wherein the total amount of data in the at least one auxiliary channel data is the same as the amount of data in the target channel data; Based on the transparency channel data, the numerical attributes of the target channel data and the at least one auxiliary channel data are adjusted at preset positions to obtain the composite color space data; The preset bit is the least significant bit of the channel data; the numerical attribute includes any one of parity, prime / composite numbers, and two preset fixed values.
2. An image decoding method, characterized in that, include: Decode the encoded data to obtain the composite color space data of the decoded image; Based on the numerical attribute of a preset bit in at least one channel of the composite color space data, the transparency channel data of the decoded image is restored. Based on the composite color space data and the transparency channel data, the decoded image is reconstructed; The step of restoring the transparency channel data of the decoded image based on the numerical attribute of a preset bit in at least one channel of the composite color space data includes: Based on the numerical attributes of the preset bits of the target channel data in the composite color space data, the transparency channel data of the decoded image is restored. The values in the target channel data correspond one-to-one with the pixels of the decoded image; The step of restoring the transparency channel data of the decoded image based on the numerical attributes of the preset bits of the target channel data in the composite color space data includes: If the numerical attribute of any pixel in the decoded image corresponding to a preset position in the target channel data is consistent with the numerical attribute of any pixel in a preset position in at least one auxiliary channel data in the composite color space data, the value of any pixel in the transparency channel data is determined based on the numerical attribute. The total amount of data in the at least one auxiliary channel is the same as the amount of data in the target channel. If the numerical attribute of any pixel in the target channel data is inconsistent with the numerical attribute of any pixel in the preset position of at least one auxiliary channel data, the value of any pixel in the transparency channel data is determined based on the value of the neighboring pixels of any pixel in the transparency channel data. The preset bit is the least significant bit of the channel data; the numerical attribute includes any one of parity, prime / composite numbers, and two preset fixed values.
3. An image encoding device, characterized in that, include: The separation unit is used to separate the color space data and transparency channel data of the image to be encoded. A composite unit is used to adjust the numerical attribute of a preset bit in at least one channel of the color space data based on the transparency channel data to obtain composite color space data. The encoding unit is used to encode the image to be encoded based on the composite color space data to obtain encoded data; The composite unit is specifically used for: Target channel data is determined from the color space data, and the values in the target channel data correspond one-to-one with the pixels of the image to be encoded; At least one auxiliary channel data is determined from the color space data, wherein the total amount of data in the at least one auxiliary channel data is the same as the amount of data in the target channel data; Based on the transparency channel data, the numerical attributes of the target channel data and the at least one auxiliary channel data are adjusted at preset positions to obtain the composite color space data; The preset bit is the least significant bit of the channel data; the numerical attribute includes any one of parity, prime / composite numbers, and two preset fixed values.
4. An image decoding device, characterized in that, include: The decoding unit is used to decode the encoded data to obtain the composite color space data of the decoded image; The transparency channel data unit is used to restore the transparency channel data of the decoded image based on the numerical attribute of a preset bit of at least one channel data in the composite color space data. The image restoration unit is used to restore the decoded image based on the composite color space data and the transparency channel data; The restored transparency channel data unit is specifically used for: Based on the numerical attributes of the preset bits of the target channel data in the composite color space data, the transparency channel data of the decoded image is restored. The values in the target channel data correspond one-to-one with the pixels of the decoded image; The restored transparency channel data unit is also specifically used for: If the numerical attribute of any pixel in the decoded image corresponding to a preset position in the target channel data is consistent with the numerical attribute of any pixel in a preset position in at least one auxiliary channel data in the composite color space data, the value of any pixel in the transparency channel data is determined based on the numerical attribute. The total amount of data in the at least one auxiliary channel is the same as the amount of data in the target channel. If the numerical attribute of any pixel in the target channel data is inconsistent with the numerical attribute of any pixel in the preset position of at least one auxiliary channel data, the value of any pixel in the transparency channel data is determined based on the value of the neighboring pixels of any pixel in the transparency channel data. The preset bit is the least significant bit of the channel data; the numerical attribute includes any one of parity, prime / composite numbers, and two preset fixed values.
5. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the image encoding method as described in claim 1, or the image decoding method as described in claim 2.
6. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the image encoding method as described in claim 1, or the image decoding method as described in claim 2.
Citation Information
Patent Citations
Graphics interchange format (GIF) file processing method and device for digital television system
CN102231836A