Image lossless coding method, decoding method, equipment and storage medium
By calculating the channel difference of image pixels and using a threshold interval coding strategy, the problem of high hardware resource consumption is solved, achieving efficient lossless image compression and fast transmission.
Patent Information
- Application Number
- CN202510962365.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-11
- Publication Date
- 2025-11-28
AI Technical Summary
Existing lossless image compression methods require significant hardware resources, resulting in high hardware requirements and low bandwidth utilization, making it difficult to meet the demand for rapid transmission of high-quality images.
By calculating the pixel value difference between each channel of the pixel to be encoded and the channel of the previous pixel, selecting the maximum absolute value, and determining the encoding strategy based on the threshold range, the system can flexibly choose to encode the original pixel value or the channel component difference, thereby reducing hardware resource requirements and improving the compression ratio.
It enables fast encoding and decoding without multi-line pixel buffering, reducing hardware resource requirements and improving the compression rate and bandwidth utilization of image transmission.
Smart Images

Figure CN121037564A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to an image lossless encoding method, a decoding method, a device and a storage medium. BACKGROUND
[0002] In an application scenario with high requirements for image quality, a lossless encoding method is generally used to realize image encoding. The image lossless encoding is an encoding method that retains all information of an image, and the decoded image is completely identical to the original image.
[0003] For example, in a display scenario such as a multi-screen splicer or a Light-Emitting Diode (LED) display, high-quality images need to be spliced and displayed. With the increase of image resolution, the storage and transmission of images require more and more hardware. In order to ensure the timely display of image data, it is necessary to realize image compression with less hardware resources while ensuring that the amount of information carried by the image is lossless, thereby reducing the transmission bandwidth to a certain extent.
[0004] The image lossless compression method in the related art still needs to occupy a large amount of hardware resources. How to reduce the hardware resources required by the image lossless compression is a technical problem to be solved by those skilled in the art. SUMMARY
[0005] To solve the above technical problems, the present application provides at least an image lossless encoding method, an image lossless decoding method, a device and a storage medium.
[0006] The first aspect of the present application provides an image lossless encoding method, which comprises: obtaining a to-be-encoded pixel in an original image; if the to-be-encoded pixel is not a first pixel in a pixel row where the to-be-encoded pixel is located, calculating pixel value differences between each channel of the to-be-encoded pixel and each channel of a previous pixel, to obtain a plurality of channel component difference values corresponding to the to-be-encoded pixel; selecting a maximum value in absolute values of the plurality of channel component difference values to obtain a maximum absolute value; determining an encoding strategy matched with the to-be-encoded pixel based on a threshold interval where the maximum absolute value is located; wherein the encoding strategy is used to limit encoding of the original pixel value or encoding of the channel component difference value, and / or the encoding strategy is used to limit a bit width occupied by each channel in an encoded pixel value obtained after encoding; encoding pixel values of each channel of the to-be-encoded pixel using the encoding strategy to obtain an encoded pixel value corresponding to the to-be-encoded pixel; and obtaining an encoded image corresponding to the original image based on the encoded pixel value of each to-be-encoded pixel.
[0007] In an embodiment, before determining the encoding strategy matching the pixel to be encoded based on the threshold interval where the maximum absolute value is located, the method further comprises: dividing the pixel value range corresponding to the original image based on the image type to which the original image belongs to obtain a plurality of threshold intervals, each threshold interval being marked with an encoding manner of encoding the original pixel value or encoding the channel component difference value, and / or being marked with the bit width occupied by each channel; determining the encoding strategy matching the pixel to be encoded based on the threshold interval where the maximum absolute value is located, comprising: determining the threshold interval where the maximum absolute value is located to obtain a target threshold interval; obtaining the encoding manner and / or the bit width occupied by each channel marked in the target threshold interval to obtain the encoding strategy matching the pixel to be encoded.
[0008] In an embodiment, the threshold intervals include a maximum threshold interval and other threshold intervals, the minimum value of the maximum threshold interval being greater than the maximum value of the other threshold intervals, the maximum value of the maximum threshold interval occupying a maximum bit width corresponding to the channel components, and the values in the other threshold intervals occupying bit widths smaller than the maximum bit width; encoding the pixel values of each channel of the pixel to be encoded using the encoding strategy to obtain the encoded pixel values corresponding to the pixel to be encoded, comprising: if the maximum absolute value is in the maximum threshold interval, converting the original pixel values of each channel of the pixel to be encoded into the encoded pixel values corresponding to the pixel to be encoded, and taking the maximum bit width corresponding to the channel components as the bit width occupied by the encoded pixel values; and if the maximum absolute value is in the other threshold intervals, converting the channel component difference values corresponding to each channel of the pixel to be encoded into the encoded pixel values corresponding to the pixel to be encoded, and taking the bit width occupied by each channel marked in the other threshold intervals as the bit width occupied by the encoded pixel values.
[0009] In an embodiment, the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel is calculated to obtain a plurality of channel component difference values corresponding to the pixel to be encoded, comprising: obtaining the intermediate value and the total number of pixel values of the pixel value range corresponding to the original image; for a channel whose original pixel value is greater than the intermediate value, performing difference calculation on the original pixel value of the channel and the total number of pixel values, and updating the difference calculation result as the new pixel value corresponding to the channel; based on the new pixel value or the original pixel value corresponding to each channel, calculating the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel to obtain a plurality of channel component difference values corresponding to the pixel to be encoded.
[0010] In an embodiment, the method further comprises: if the pixel to be encoded is the first pixel in the pixel row where the pixel to be encoded is located, the original pixel value of the pixel to be encoded remains unchanged to obtain the encoded pixel value corresponding to the pixel to be encoded.
[0011] The second aspect of the present application provides a lossless image decoding method, the method comprises: obtaining a to-be-decoded pixel in an encoded image, the encoded image is obtained based on a lossless image encoding method, and the to-be-decoded pixel is not marked with an encoding strategy adopted if the to-be-decoded pixel is not a first pixel of a pixel row in which the to-be-decoded pixel is located; if the to-be-decoded pixel is not the first pixel of the pixel row in which the to-be-decoded pixel is located, obtaining a decoding strategy corresponding to the encoding strategy adopted by the to-be-decoded pixel, decoding the to-be-decoded pixel based on the decoding strategy to obtain an original pixel value corresponding to the to-be-decoded pixel; and obtaining an original image corresponding to the encoded image based on the original pixel value of each to-be-decoded pixel.
[0012] In an embodiment, the method further comprises: if the to-be-decoded pixel is the first pixel of the pixel row in which the to-be-decoded pixel is located, converting an encoded pixel value of the to-be-decoded pixel into an original pixel value corresponding to the to-be-decoded pixel.
[0013] In an embodiment, the decoding of the to-be-decoded pixel based on the decoding strategy to obtain the original pixel value corresponding to the to-be-decoded pixel comprises: if the encoding strategy adopted by the to-be-decoded pixel indicates that the to-be-decoded pixel converts the original pixel value to obtain the encoded pixel value, directly converting the encoded pixel value to obtain the original pixel value corresponding to the to-be-decoded pixel; and if the encoding strategy adopted by the to-be-decoded pixel indicates that the to-be-decoded pixel converts a channel component difference value to obtain the encoded pixel value, converting the encoded pixel value to obtain a channel component difference value corresponding to the to-be-decoded pixel, and calculating a sum between each channel component difference value of each channel of the to-be-decoded pixel and an original pixel value of each channel of a previous pixel to obtain the original pixel value corresponding to the to-be-decoded pixel.
[0014] The third aspect of the present application provides a lossless image encoding device, the device comprises: a difference value calculation module, configured to obtain a to-be-encoded pixel in an original image, and calculate a pixel value difference between each channel of the to-be-encoded pixel and each channel of a previous pixel to obtain a plurality of channel component difference values corresponding to the to-be-encoded pixel if the to-be-encoded pixel is not a first pixel of a pixel row in which the to-be-encoded pixel is located;
[0015] A maximum value selection module is configured to select a maximum value in absolute values of the plurality of channel component difference values to obtain a maximum absolute value.
[0016] An encoding strategy determination module is configured to determine an encoding strategy matched with the to-be-encoded pixel based on a threshold interval in which the maximum absolute value is located, wherein the encoding strategy is used to limit encoding of the original pixel value or encoding of the channel component difference value, and / or the encoding strategy is used to limit a bit width occupied by each channel in an encoded pixel value obtained after encoding.
[0017] The encoding module is used to encode the pixel values of each channel of the pixel to be encoded using an encoding strategy, thereby obtaining the encoded pixel value corresponding to the pixel to be encoded, and obtaining the encoded image corresponding to the original image based on the encoded pixel value of each pixel to be encoded.
[0018] The fourth aspect of this application provides an image lossless decoding apparatus, the apparatus comprising: a pixel acquisition module, used to acquire pixels to be decoded in an encoded image, wherein the encoded image is obtained based on an image lossless encoding method and does not employ any encoding strategy for the pixel to be decoded that is the first pixel of a row;
[0019] The decoding module is used to obtain the decoding strategy corresponding to the encoding strategy adopted by the pixel to be decoded if the pixel to be decoded is not the first pixel of the pixel row in which the pixel to be decoded is located, and to decode the pixel to be decoded based on the decoding strategy to obtain the original pixel value corresponding to the pixel to be decoded.
[0020] The original image generation module is used to combine the original pixel values of each pixel to be decoded to obtain the original image corresponding to the encoded image.
[0021] The fifth aspect of this application provides an electronic device, including a memory and a processor, wherein the processor is configured to execute program instructions stored in the memory to implement the above-described lossless image encoding method or lossless image decoding method.
[0022] The sixth aspect of this application provides a computer-readable storage medium having program instructions stored thereon, which, when executed by a processor, implement the above-described lossless image encoding method or lossless image decoding method.
[0023] The above scheme calculates the pixel value differences between each channel of the pixel to be encoded and each channel of the previous pixel to obtain the multiple channel component differences corresponding to the pixel to be encoded; selects the maximum value among the absolute values of the multiple channel component differences to obtain the maximum absolute value; determines the encoding strategy matching the pixel to be encoded based on the threshold range of the maximum absolute value; encodes the pixel values of each channel of the pixel to be encoded using the encoding strategy to obtain the encoded pixel value corresponding to the pixel to be encoded; and obtains the encoded image corresponding to the original image based on the encoded pixel value of each pixel to be encoded. This scheme can achieve encoding within a single pixel row of the original image, without the need for caching multiple pixel rows during the encoding and decoding process, reducing the demand on hardware resources, enabling fast transmission of the original image, and matching a more suitable encoding strategy for the pixel to be encoded, minimizing the data size corresponding to the encoded pixel value obtained in the final encoding, and improving the compression ratio of the original image.
[0024] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this application. Attached Figure Description
[0025] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the technical solutions of this application.
[0026] Figure 1 This is a schematic diagram illustrating the transmission and display of images in an LED splicing display scenario, as shown in an exemplary embodiment of this application.
[0027] Figure 2 This is a schematic diagram illustrating the implementation environment of the solution in an exemplary embodiment of this application;
[0028] Figure 3 This is a flowchart illustrating an exemplary embodiment of the image lossless encoding method of this application;
[0029] Figure 4 This is a schematic diagram illustrating the parameters of the encoding strategy corresponding to each threshold interval, as shown in an exemplary embodiment of this application;
[0030] Figure 5 This is a flowchart illustrating another exemplary embodiment of the image lossless encoding method of this application;
[0031] Figure 6 This is a flowchart illustrating an exemplary embodiment of the image lossless decoding method of this application;
[0032] Figure 7 This is a block diagram illustrating an image lossless encoding apparatus according to an exemplary embodiment of this application;
[0033] Figure 8 This is a block diagram illustrating an image lossless decoding apparatus according to an exemplary embodiment of this application;
[0034] Figure 9 This is a schematic diagram of the structure of an electronic device shown in an exemplary embodiment of this application;
[0035] Figure 10 This is a schematic diagram illustrating the structure of a computer-readable storage medium, as shown in an exemplary embodiment of this application. Detailed Implementation
[0036] The embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0037] In the following description, specific details such as particular system architectures, interfaces, and technologies are presented for illustrative purposes rather than for limiting purposes, in order to provide a thorough understanding of this application.
[0038] In this document, the term "and / or" is merely a description of the association information of related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following related objects have an "or" relationship. Furthermore, "many" in this document means two or more. Moreover, the term "at least one" in this document means any combination of at least two of any one or more of a plurality of elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0039] Taking LED splicing display scenarios as an example, please refer to [link to relevant documentation]. Figure 1 , Figure 1 This is a schematic diagram illustrating the transmission and display of images in an LED splicing display scenario, as shown in an exemplary embodiment of this application. Figure 1 As shown, the host computer is the computer software used to control and manage the LED splicing display system. Its main functions include interface design, logic code writing, and serial communication to ensure the normal operation and efficient management of the LED display screen. The transmitting card acts as the encoding end, transmitting the encoded image data to the receiving card. The receiving card acts as the decoding end, decoding and displaying the received image data. The receiving card and the LED light board it drives are housed in the same enclosure.
[0040] The sending and receiving cards are connected via gigabit network. Based on the bandwidth of gigabit network, a single network port can transmit 650,000 pixels per unit time without data compression. As the spacing between LED light panels becomes smaller and the resolution of a single cabinet becomes larger, the number of cabinets that a single network cable can support becomes smaller. For example, a 640×360 cabinet with a 0.9 pitch can only support 2 (460800) LEDs. At this time, the bandwidth utilization of the network port is about 70%, resulting in a significant bandwidth waste.
[0041] Currently, most transmitting and receiving cards transmit raw 24-bit RGB data (RGB888). While this method is the simplest and most direct, it suffers from low gigabit network utilization when dealing with enclosures with a pitch of 0.9mm or less. For example, a transmitting box with 8 interfaces can theoretically carry a maximum of 5.2 million (650,000 x 8) data, but due to low bandwidth utilization, it can only actually carry 3.6864 million (460,800 x 8) data, thus only utilizing 70% of the transmitting box's capacity and indirectly increasing the engineering deployment cost.
[0042] In related technologies, in order to reduce transmission bandwidth and improve bandwidth utilization, run-length encoding (by finding blocks with the same pixel values) is generally used. It belongs to intra-frame multi-line encoding, which involves buffering multiple rows of pixels. This not only requires hardware resources to buffer multiple rows of pixels, but also affects the real-time performance of image display, and the algorithm complexity is high.
[0043] To address the aforementioned technical problems, this application provides at least one lossless image encoding method, lossless image decoding method, device, and storage medium.
[0044] The lossless image encoding method and lossless image decoding method provided in the embodiments of this application are described below.
[0045] Please refer to Figure 2 , Figure 2 This is a schematic diagram illustrating an implementation environment of the scheme according to an exemplary embodiment of this application. The implementation environment may include an encoding end 210 and a decoding end 220, which are interconnected.
[0046] The encoding end 210 and the decoding end 220 can be smartphones, tablets, laptops, desktop computers, cameras, physical servers, cloud servers, etc., but are not limited to these.
[0047] In one example, the encoding end 210 encodes the original image to obtain an encoded image, and sends the encoded image to the decoding end 220. The decoding end 220 decodes the encoded image to obtain the original image. Of course, the decoding end 220 can store the original image locally, or transmit it to a display window for display, or transmit it to other terminals.
[0048] Please see Figure 3 , Figure 3 This is a flowchart illustrating an exemplary embodiment of the image lossless encoding method of this application. This image lossless encoding method can be applied to... Figure 2 The implementation environment is shown, and the code in that implementation environment is specifically executed.
[0049] like Figure 3 As shown, the image lossless encoding method includes at least steps S310 to S340, which are described in detail below:
[0050] Step S310: Obtain the pixel to be encoded in the original image. If the pixel to be encoded is not the first pixel of the pixel row in which it is located, calculate the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel to obtain the difference of multiple channel components corresponding to the pixel to be encoded.
[0051] A pixel is typically composed of multiple channels, each storing different information.
[0052] For example, the original image's channel type includes RGB channels, representing red, green, and blue respectively. Each channel stores information about the corresponding color in the image. Specifically, the red channel stores information about all the red components in the image, the green channel stores information about the green components, and the blue channel stores information about the blue components.
[0053] For example, the channel type of the original image includes YUV channels, which represent luminance (or Luma) and two chrominance (or Chroma) components, respectively. The luminance component represents the brightness of the image, and the chrominance components describe the color difference information of blue and red.
[0054] Of course, a pixel can also consist of a single channel. For example, a grayscale image has only one channel, which stores the image's brightness information.
[0055] This application does not limit the number or type of channels in the original image.
[0056] The pixel in the original image that needs to be encoded is determined to obtain the pixel to be encoded. For example, the pixels in the original image are traversed sequentially (e.g., row by row), and each traversed pixel is used as the pixel to be encoded. If the pixel to be encoded is not the first pixel of a row, the previous pixel is obtained, and the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel is calculated to obtain the multi-channel component difference corresponding to the pixel to be encoded.
[0057] The original image consists of multiple rows of pixels, and the first pixel of a row refers to the first pixel in the row.
[0058] Taking an original image with RGB channels as an example, the pixel to be encoded is the second pixel P2 in the current pixel row, where P2 = (R2, G2, B2), and R2, G2, and B2 represent the pixel values of P2's R, G, and B channels, respectively. Then, obtain the first pixel P1 in the current pixel row to get the previous pixel corresponding to P2, where P1 = (R1, G1, B1). Similarly, R1, G1, and B1 represent the pixel values of P1's R, G, and B channels, respectively. Calculate the pixel value difference between P1 and P2, obtaining the pixel value difference for the R channel as DR2 = R2 - R1, the pixel value difference for the G channel as DG2 = G2 - G1, and the pixel value difference for the B channel as DB2 = B2 - B1. Finally, the difference of each channel component corresponding to the pixel to be encoded, P2, is represented as D2 = (DR2, DG2, DB2). Similarly, the component differences for each channel corresponding to the 3rd pixel and the component differences for each channel corresponding to the 4th pixel can be calculated.
[0059] In some implementations, if the pixel to be encoded is the first pixel of the row in which the pixel to be encoded is located, then the original pixel value of the pixel to be encoded remains unchanged, and the encoded pixel value corresponding to the pixel to be encoded is obtained.
[0060] Step S320: Select the maximum value among the absolute values of the differences between multiple channel components to obtain the maximum absolute value.
[0061] Calculate the absolute value of the component difference for each channel, then compare the magnitudes of the absolute values and select the maximum value among the multiple absolute values to obtain the maximum absolute value.
[0062] For example, the component difference of each channel corresponding to the nth channel is represented as Dn = (DRn, DGn, DBn). The absolute values of the component differences of each channel are calculated as abs(DRn), abs(DGn), and abs(DBn). Then, the maximum value among the three absolute values is selected to obtain the maximum absolute value, which is represented as max(absD).
[0063] Step S330: Based on the threshold range where the maximum absolute value is located, determine the encoding strategy that matches the pixel to be encoded; wherein, the encoding strategy is used to limit the encoding of the original pixel value or the encoding of the channel component difference, and / or the encoding strategy is used to limit the bit width occupied by each channel in the encoded pixel value obtained after encoding.
[0064] Different encoding strategies are set for different threshold intervals. The threshold interval in which the maximum absolute value of the pixel to be encoded is located is determined, and the encoding strategy corresponding to the threshold interval is used as the encoding strategy to match the pixel to be encoded.
[0065] The encoding strategy is used to define the encoding rules used when transmitting data from the original image. For example, the encoding strategy may include the encoding method used to encode the pixels to be encoded (such as encoding the original pixel values or encoding the channel component differences, etc.); the encoding strategy may also be used to define the bit width occupied by each channel in the encoded pixel values.
[0066] It should be noted that the different threshold interval division methods and the corresponding encoding strategies for different threshold intervals can be flexibly set according to the type of the original image and the image encoding requirements of the application scenario.
[0067] Step S340: Use an encoding strategy to encode the pixel values of each channel of the pixel to be encoded to obtain the encoded pixel value corresponding to the pixel to be encoded. Based on the encoded pixel value of each pixel to be encoded, obtain the encoded image corresponding to the original image.
[0068] After obtaining the encoding strategy, the pixel values of each channel of the pixel to be encoded are encoded using the encoding strategy, and the encoded data of each channel is used as the encoded pixel value corresponding to the pixel to be encoded.
[0069] For example, based on the threshold range where the maximum absolute value is located, the determined encoding method is to perform binary conversion on the original pixel values of each channel of the pixel to be encoded to obtain the encoded pixel value; or, the determined encoding method is to perform binary conversion on the pixel value difference of each channel of the pixel to be encoded to obtain the encoded pixel value.
[0070] For example, based on the threshold range where the maximum absolute value is located, the bit width occupied by the encoded pixel value of each channel is determined to be 8 bits; or, the bit width occupied by the encoded pixel value of each channel is determined to be 7 bits.
[0071] Then, by combining the encoded pixel value corresponding to each pixel to be encoded, the encoded image of the original image is obtained.
[0072] Through the above embodiments, the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel can be calculated. Based on the magnitude of the maximum absolute value of the differences among the multiple channel components corresponding to the pixel to be encoded, the encoding strategy matching the pixel to be encoded can be flexibly determined. This can achieve encoding within a single pixel row of the original image, eliminating the need for caching multiple pixel rows during encoding and decoding, reducing the demand on hardware resources, enabling fast transmission of the original image, and matching a more suitable encoding strategy for the pixel to be encoded. This minimizes the data size corresponding to the encoded pixel value obtained in the final encoding and improves the compression rate of the original image.
[0073] The following describes some embodiments of this application in detail.
[0074] In some implementations, step S310 calculates the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel to obtain the difference of multiple channel components corresponding to the pixel to be encoded, including steps S311 to S313.
[0075] Step S311: Obtain the median value of the pixel value range and the total number of pixel values corresponding to the original image.
[0076] For example, if the pixel value range of the original image is 0 to 255, then the midpoint of the pixel value range is 127, and the total number of pixel values is 256.
[0077] Step S312: For channels where the original pixel value is greater than the median value, calculate the difference between the original pixel value and the total number of pixel values of the channel, and update the new pixel value corresponding to the channel with the result of the difference calculation.
[0078] For example, if the median value of the pixel value range is 127, the total number of pixel values is 256, and the original pixel value of the current channel is 240, since 240 is greater than 127, then the difference between 240 and 256 is taken to obtain a new pixel value of -16 for the current channel.
[0079] The above embodiments update the values of each channel of the pixel to be encoded and the values of each channel of the previous pixel.
[0080] Step S313: Based on the new pixel value or original pixel value corresponding to each channel, calculate the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel, and obtain the multiple channel component differences corresponding to the pixel to be encoded.
[0081] For example, if the median value of the pixel value range is 127, the total number of pixel values is 256, the original pixel value of the current channel of the pixel to be encoded is 240, and the original pixel value of the corresponding channel of the previous pixel is 20, then the channel component difference of the current channel of the pixel to be encoded = (240-256)-20 = -36.
[0082] For example, if the median value of the pixel value range is 127, the total number of pixel values is 256, the original pixel value of the current channel of the pixel to be encoded is 10, and the original pixel value of the corresponding channel of the previous pixel is 255, then the channel component difference of the current channel of the pixel to be encoded = 10 - (255 - 256) - 20 = 11.
[0083] It should be noted that the above embodiments are only illustrative. In actual application scenarios, if the range of pixel values corresponding to the original image is different, the intermediate value and the total number of pixel values will be different. The calculation method can be flexibly adjusted according to the actual situation.
[0084] Through the above embodiments, the original pixel values that are greater than the median value can be treated as negative numbers (e.g., 255 can be treated as -1 and 240 as -16) to reduce the value of the final calculated channel component difference, thereby reducing the amount of encoded data in subsequent encoding.
[0085] In some implementations, before determining the encoding strategy matching the pixel to be encoded based on the threshold interval where the maximum absolute value is located, the method further includes: dividing the range of pixel values corresponding to the original image based on the image type to which the original image belongs, to obtain multiple threshold intervals, each threshold interval being marked with encoding the original pixel value or encoding the channel component difference, and / or marked with the bit width occupied by each channel.
[0086] Since images of different image types have different pixel formats, the range of pixel values corresponding to the original image is divided according to the image type to which the original image belongs.
[0087] The following embodiments use RGB888 as an example to illustrate the concept. It should be noted that other image formats, such as RGB565, YUV444, YUV422, YUV420, etc., can be adjusted accordingly based on the ideas of this application.
[0088] Based on the image type of the original image, determine the channel corresponding to a single pixel and the bit width of each channel. For example, if the original image is RGB888, it contains three channels: R, G, and B, and the bit width of each channel is 8 bits.
[0089] Based on the channel corresponding to a single pixel in the original image and the bit width corresponding to each channel, the range of pixel values in the original image is divided to obtain multiple threshold intervals. Each threshold interval is marked with an encoding method for encoding the original pixel value or encoding the channel component difference, and / or marked with the bit width occupied by each channel. The marked encoding method and / or the bit width occupied by each channel constitute the encoding strategy corresponding to that threshold interval.
[0090] For example, see Figure 4 , Figure 4 This is an exemplary embodiment of the present application illustrating the parameter configuration of the encoding strategy corresponding to each threshold interval, such as... Figure 4 As shown, there are four threshold intervals: the first threshold interval is [64, 255), the second threshold interval is [32, 64), the third threshold interval is [4, 32), and the fourth threshold interval is [0, 4). The first threshold interval is the maximum threshold interval, and its maximum value occupies the maximum bit width corresponding to the channel component (i.e., 8 bits). Therefore, to save encoding and decoding computational resources, the encoding method for the first threshold interval is to encode the original pixel value. Thus, the R, G, and B channels each occupy 8 bits (e.g., ...). Figure 4 The first threshold interval uses 0 to 7 bits for the B channel, 8 to 15 bits for the G channel, and 16 to 23 bits for the R channel. The maximum value in the second threshold interval uses 6 bits, which is less than the maximum width of 8 bits. Therefore, to reduce the size of the encoded data, the second threshold interval is encoded by encoding the channel component differences. Since the channel component differences can be positive or negative, the R, G, and B channels each use 7 bits. Similarly, the third threshold interval is encoded by encoding the channel component differences, with the R, G, and B channels each using 6 bits. The fourth threshold interval is encoded by encoding the channel component differences, with the R, G, and B channels each using 3 bits.
[0091] Optionally, to distinguish the encoding methods used in different threshold intervals, a flag bit can be set to mark the encoding method, resulting in an encoding flag. For example, the four threshold intervals mentioned above correspond to four different cases, requiring 2 bits for marking. Therefore, an additional 2 bits are allocated to the flag bit. In this case, due to the added flag bit, the amount of data in the compressed encoded pixel values corresponding to the first threshold interval will be greater than the original data amount, while the amount of data in the compressed encoded pixel values corresponding to other threshold intervals will be less than the original data amount. In particular, the amount of data in the compressed fourth threshold interval will be less than half of the original.
[0092] For example, if the maximum absolute value is represented as max(absD) greater than or equal to 64, the encoding flag is set to 0 (00 in binary); if the maximum absolute value is represented as max(absD) greater than or equal to 32, the encoding flag is set to 1 (01 in binary); if the maximum absolute value is represented as max(absD) greater than or equal to 4, the encoding flag is set to 2 (10 in binary); if the maximum absolute value is represented as max(absD) greater than or equal to 0, the encoding flag is set to 3 (11 in binary).
[0093] The encoding markers are generated in the manner described above, and the encoded pixel values of the pixels to be encoded are generated based on the encoding markers.
[0094] If the encoding flag is 0, the encoding is performed in the form of "encoding flag + original pixel value"; otherwise, the encoding is performed in the form of "encoding flag + channel component difference".
[0095] Optionally, to further reduce the size of the compressed data, pixels encoded according to the original pixel values may not be marked with flag bits. For pixels without flag bits, the encoder and decoder will encode them according to the original pixel values by default, thereby further reducing the size of the final encoded image without increasing the computational resources required for encoding and decoding.
[0096] It should be noted that the above embodiments are only illustrative. In actual application scenarios, different threshold ranges can be divided for different original images and different encoding requirements, and different encoding strategy parameters can be used for different threshold ranges.
[0097] Based on the above embodiments, step S330 determines the encoding strategy that matches the pixel to be encoded based on the threshold range where the maximum absolute value is located, including steps S331 to S332.
[0098] Step S331: Determine the threshold interval where the maximum absolute value is located to obtain the target threshold interval.
[0099] Step S332: Obtain the encoding method of the marker corresponding to the target threshold interval and / or the bit width occupied by each channel to obtain the encoding strategy for matching the pixel to be encoded.
[0100] For example, if the maximum value of the absolute value of the difference between each channel component of the pixel to be encoded is in Figure 4 If the first threshold interval is specified, the encoding method is to encode the original pixel value, and each channel of the encoded pixel occupies a bit width of 8 bits; if the maximum value of the absolute value of the difference between the components of each channel of the pixel to be encoded is within the range specified, the encoding method is to encode the original pixel value, and each channel of the encoded pixel occupies a bit width of 8 bits. Figure 4 If the second threshold interval is used, the encoding method is to encode the channel component difference, and the bit width of each channel of the pixel after encoding is 7 bits.
[0101] Based on the encoding method of the marker corresponding to the target threshold range and / or the bit width occupied by each channel, the encoding strategy for matching the pixel to be encoded is obtained, and the pixel values of each channel of the pixel to be encoded are encoded according to the encoding strategy.
[0102] For example, the threshold range includes the maximum threshold range (e.g., Figure 4 The first threshold interval) and other threshold intervals (such as Figure 4 The second threshold interval, the third threshold interval, and the fourth threshold interval), the minimum value of the maximum threshold interval is greater than the maximum value of the other threshold intervals, and the bit width occupied by the maximum value of the maximum threshold interval is the maximum bit width corresponding to the channel component.
[0103] If the maximum absolute value is within the maximum threshold range, then the pixel values of each channel of the pixel to be encoded are encoded according to the encoding strategy, including: converting the original pixel values of each channel of the pixel to be encoded into the encoded pixel values corresponding to the pixel to be encoded, and using the maximum bit width corresponding to the channel component as the bit width occupied by the encoded pixel value; if the maximum absolute value is within other threshold ranges, then the pixel values of each channel of the pixel to be encoded are encoded according to the encoding strategy, including: converting the channel component differences corresponding to each channel of the pixel to be encoded into the encoded pixel values corresponding to the pixel to be encoded, and using the bit width occupied by each channel marked in other threshold ranges as the bit width occupied by the encoded pixel value.
[0104] Converting the original pixel value or channel component difference into the encoded pixel value corresponding to the pixel to be encoded means converting the original pixel value or channel component difference into binary. For example, if the original pixel value is 254, the converted encoded pixel value is 11111110.
[0105] Specifically, since the channel component difference may be negative or positive, when performing binary conversion on the channel component difference, it is necessary to convert the negative channel component difference to a positive number (and then convert the positive number to a negative number during decoding) in order to obtain the encoded pixel value.
[0106] by Figure 4 Taking the fourth threshold range as an example, during encoding, 4 is added to each channel component difference to convert negative channel component differences into positive ones. That is, the channel component differences whose absolute values originally fall within the fourth threshold range include -3, -2, -1, 0, 1, 2, and 3. After adding 4 to each channel component difference, we get 1, 2, 3, 4, 5, 6, and 7, which correspond to the binary codes 001, 010, 011, 100, 101, 110, and 111, respectively. Of course, during decoding, 4 needs to be subtracted from the encoded pixel value for correct decoding.
[0107] Please see Figure 5 , Figure 5 This is a flowchart illustrating another exemplary embodiment of the image lossless encoding method of this application, such as... Figure 5 As shown, it includes steps S510 to S550.
[0108] Step S510: Obtain the pixels to be encoded in the original image.
[0109] Step S520: Determine whether the pixel to be encoded is the first pixel of a row. If yes, proceed to step S530; otherwise, proceed to steps S540 to S550.
[0110] Step S530: Transmit the original pixel value of the pixel to be encoded to the decoding end.
[0111] Step S540: Calculate the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel.
[0112] Step S550: Based on the threshold range where the maximum value among the absolute values of multiple channel component differences is located, determine whether to encode the original pixel value or to encode the channel component differences, and transmit the encoded pixel value obtained after encoding to the decoding end.
[0113] Repeat the above steps until one row of pixels is encoded. Then repeat the above steps for the next row of pixels in the original image to obtain the encoded image.
[0114] Please see Figure 6 , Figure 6 This is a flowchart illustrating an exemplary embodiment of an image lossless decoding method according to this application. This image lossless decoding method can be applied to... Figure 2 The implementation environment is shown, and the actual execution is performed by the decoding end within that implementation environment. For example... Figure 2 As shown, the image lossless decoding method includes at least steps S610 to S630, which are described in detail below:
[0115] Step S610: Obtain the pixel to be decoded in the encoded image. The encoded image is obtained based on the lossless image encoding method of any one of claims 1 to 5, and the encoding strategy adopted is not used for the pixel to be decoded that is the first pixel of the row.
[0116] Step S620: If the pixel to be decoded is not the first pixel of the pixel row in which it is located, then obtain the decoding strategy corresponding to the encoding strategy used by the pixel to be decoded, and decode the pixel to be decoded based on the decoding strategy to obtain the original pixel value corresponding to the pixel to be decoded.
[0117] If the pixel to be decoded is the first pixel of the row in which it is located, then the encoded pixel value of the pixel to be decoded is converted into the original pixel value corresponding to the pixel to be decoded.
[0118] Step S630: Combine the original pixel values of each pixel to be decoded to obtain the original image corresponding to the encoded image.
[0119] For example, if the encoding strategy used by the pixel to be decoded indicates that the pixel to be decoded will convert the original pixel value into an encoded pixel value, then the encoded pixel value will be directly converted into the original pixel value corresponding to the pixel to be decoded; if the encoding strategy used by the pixel to be decoded indicates that the pixel to be decoded will convert the channel component difference into an encoded pixel value, then the encoded pixel value will be converted into the channel component difference corresponding to the pixel to be decoded, and the sum of the channel component differences of each channel of the pixel to be decoded and the original pixel values of each channel of the previous pixel will be calculated to obtain the original pixel value corresponding to the pixel to be decoded.
[0120] Since the channel component differences can be negative or positive, during the binary conversion of the channel component differences in the encoding process, negative channel component differences need to be converted to positive numbers (and positive numbers need to be converted to negative numbers during decoding) to obtain the encoded pixel value. Therefore, during decoding, the channel component differences need to be restored based on the encoded pixel value. For example, based on the bit width occupied by each channel or based on the encoding mark, the value to be subtracted from the encoded pixel value is determined to perform difference calculation on the encoded pixel value, obtaining the original channel component differences. Then, the original channel component differences are summed with the original pixel value of the previous pixel to obtain the original pixel value corresponding to the pixel to be decoded.
[0121] Through the above embodiments, the original image is decoded without loss of information.
[0122] Figure 7 This is a block diagram illustrating an image lossless encoding apparatus according to an exemplary embodiment of this application. Figure 7 As shown, the exemplary image lossless encoding device 700 includes:
[0123] The difference calculation module 710 is used to obtain the pixel to be encoded in the original image. If the pixel to be encoded is not the first pixel of the pixel row in which the pixel to be encoded is located, the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel is calculated to obtain the difference of multiple channel components corresponding to the pixel to be encoded.
[0124] The maximum value selection module 720 is used to select the maximum value among the absolute values of the differences between multiple channel components to obtain the maximum absolute value.
[0125] The encoding strategy determination module 730 is used to determine an encoding strategy that matches the pixel to be encoded based on the threshold range where the maximum absolute value is located; wherein, the encoding strategy is used to limit the encoding of the original pixel value or the encoding of the channel component difference, and / or the encoding strategy is used to limit the bit width occupied by each channel in the encoded pixel value after encoding;
[0126] The encoding module 740 is used to encode the pixel values of each channel of the pixel to be encoded using an encoding strategy, to obtain the encoded pixel value corresponding to the pixel to be encoded, and to obtain the encoded image corresponding to the original image based on the encoded pixel value of each pixel to be encoded.
[0127] Figure 8 This is a block diagram illustrating an image lossless decoding apparatus as shown in an exemplary embodiment of this application. Figure 8 As shown, the exemplary image lossless decoding device 800 includes:
[0128] The pixel acquisition module 810 is used to acquire the pixels to be decoded in the encoded image. The encoded image is obtained based on the lossless image encoding method and does not adopt any encoding strategy for the pixels to be decoded that are not the first pixels of a row.
[0129] The decoding module 820 is used to obtain the decoding strategy corresponding to the encoding strategy adopted by the pixel to be decoded if the pixel to be decoded is not the first pixel of the pixel row in which the pixel to be decoded is located, and to decode the pixel to be decoded based on the decoding strategy to obtain the original pixel value corresponding to the pixel to be decoded.
[0130] The original image generation module 830 is used to combine the original pixel values of each pixel to be decoded to obtain the original image corresponding to the encoded image.
[0131] It should be noted that the image lossless encoding device and the image lossless encoding method provided in the above embodiments belong to the same concept, and the image lossless decoding device and the image lossless decoding method provided in the above embodiments belong to the same concept. The specific methods by which each module and unit performs its operations have been described in detail in the method embodiments and will not be repeated here. In practical applications, the image lossless encoding device and image lossless decoding device provided in the above embodiments can be configured to perform the above functions by different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. This is not a limitation here.
[0132] Please see Figure 9 , Figure 9 This is a schematic diagram of an embodiment of the electronic device of this application. The electronic device 900 includes a memory 901 and a processor 902. The processor 902 is used to execute program instructions stored in the memory 901 to implement the steps in any of the above-described lossless image encoding or lossless image decoding method embodiments. In a specific implementation scenario, the electronic device 900 may include, but is not limited to, a microcomputer or a server. In addition, the electronic device 900 may also include mobile devices such as laptops and tablets, which are not limited here.
[0133] Specifically, processor 902 controls itself and memory 901 to implement the steps in any of the above-described lossless image encoding or lossless image decoding methods. Processor 902 can also be referred to as a Central Processing Unit (CPU). Processor 902 may be an integrated circuit chip with signal processing capabilities. Processor 902 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor can be a microprocessor or any conventional processor. Furthermore, processor 902 can be implemented using integrated circuit chips.
[0134] Please see Figure 10 , Figure 10This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present application. The computer-readable storage medium 1000 stores program instructions 1010 that can be executed by a processor. The program instructions 1010 are used to implement the steps in any of the above-described lossless image encoding method or lossless image decoding method embodiments.
[0135] In some embodiments, the functions or modules of the apparatus provided in this disclosure can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0136] The description of the various embodiments above tends to emphasize the differences between the various embodiments. The similarities or similarities between them can be referred to, and for the sake of brevity, they will not be repeated here.
[0137] In the several embodiments provided in this application, it should be understood that the disclosed methods and apparatus can be implemented in other ways. For example, the apparatus implementations described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0138] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or 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.) or processor to execute all or part of the steps of the methods in the various embodiments of this application. 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.
Claims
1. A lossless image encoding method, characterized in that, The method includes: Obtain the pixel to be encoded in the original image. If the pixel to be encoded is not the first pixel of the pixel row in which it is located, calculate the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel to obtain the multiple channel component differences corresponding to the pixel to be encoded. The maximum absolute value is obtained by selecting the maximum value among the absolute values of the differences between the multiple channel components; Based on the threshold range where the maximum absolute value is located, an encoding strategy matching the pixel to be encoded is determined; wherein, the encoding strategy is used to limit the encoding of the original pixel value or the encoding of the channel component difference, and / or the encoding strategy is used to limit the bit width occupied by each channel in the encoded pixel value obtained after encoding; The pixel values of each channel of the pixel to be encoded are encoded using the aforementioned encoding strategy to obtain the encoded pixel value corresponding to the pixel to be encoded. Based on the encoded pixel value of each pixel to be encoded, the encoded image corresponding to the original image is obtained.
2. The method according to claim 1, characterized in that, Before determining the encoding strategy matching the pixel to be encoded based on the threshold range where the maximum absolute value is located, the method further includes: Based on the image type to which the original image belongs, the range of pixel values corresponding to the original image is divided to obtain multiple threshold intervals. Each threshold interval is marked with an encoding method that encodes the original pixel values or the channel component differences, and / or is marked with the bit width occupied by each channel. The step of determining the encoding strategy matching the pixel to be encoded based on the threshold range where the maximum absolute value is located includes: Determine the threshold interval in which the maximum absolute value lies to obtain the target threshold interval; Obtain the encoding method of the marker corresponding to the target threshold range and / or the bit width occupied by each channel to obtain the encoding strategy for matching the pixel to be encoded.
3. The method according to claim 2, characterized in that, The threshold interval includes a maximum threshold interval and other threshold intervals. The minimum value of the maximum threshold interval is greater than the maximum value of the other threshold intervals. The bit width occupied by the maximum value of the maximum threshold interval is the maximum bit width corresponding to the channel component. The bit width occupied by the values in the other threshold intervals is less than the maximum bit width. The step of encoding the pixel values of each channel of the pixel to be encoded using the encoding strategy to obtain the encoded pixel value corresponding to the pixel to be encoded includes: If the maximum absolute value is within the maximum threshold range, then the original pixel values of each channel of the pixel to be encoded are converted into the encoded pixel values corresponding to the pixel to be encoded, and the maximum bit width corresponding to the channel component is used as the bit width occupied by the encoded pixel value. If the maximum absolute value is within the other threshold range, then the channel component difference corresponding to each channel of the pixel to be encoded is converted into the encoded pixel value corresponding to the pixel to be encoded, and the bit width occupied by each channel marked in the other threshold range is used as the bit width occupied by the encoded pixel value.
4. The method according to claim 1, characterized in that, The step of calculating the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel to obtain the multiple channel component differences corresponding to the pixel to be encoded includes: Obtain the median value of the pixel value range and the total number of pixel values corresponding to the original image; For channels whose original pixel values are greater than the intermediate value, a difference is calculated between the original pixel values and the total number of pixel values in the channel, and the result of the difference calculation is updated to the new pixel value corresponding to the channel. Based on the new or original pixel value corresponding to each channel, the pixel value difference between each channel of the pixel to be encoded and each channel of the previous pixel is calculated to obtain the multiple channel component differences corresponding to the pixel to be encoded.
5. The method according to claim 1, characterized in that, The method further includes: If the pixel to be encoded is the first pixel of the pixel row in which it is located, then the original pixel value of the pixel to be encoded remains unchanged, and the encoded pixel value corresponding to the pixel to be encoded is obtained.
6. A lossless image decoding method, characterized in that, The method includes: Obtain the pixels to be decoded in the encoded image, wherein the encoded image is obtained based on the lossless image encoding method of any one of claims 1 to 5, and the encoding strategy adopted for the pixels to be decoded that are not the first pixels of a row; If the pixel to be decoded is not the first pixel of the pixel row in which it is located, then the decoding strategy corresponding to the encoding strategy adopted by the pixel to be decoded is obtained, and the pixel to be decoded is decoded based on the decoding strategy to obtain the original pixel value corresponding to the pixel to be decoded. By combining the original pixel values of each pixel to be decoded, the original image corresponding to the encoded image is obtained.
7. The method according to claim 6, characterized in that, The method further includes: If the pixel to be decoded is the first pixel of the pixel row in which it is located, then the encoded pixel value of the pixel to be decoded is converted into the original pixel value corresponding to the pixel to be decoded.
8. The method according to claim 6, characterized in that, The step of decoding the pixel to be decoded based on the decoding strategy to obtain the original pixel value corresponding to the pixel to be decoded includes: If the encoding strategy adopted by the pixel to be decoded indicates that the pixel to be decoded will convert the original pixel value into an encoded pixel value, then the encoded pixel value will be directly converted into the original pixel value corresponding to the pixel to be decoded. If the encoding strategy adopted by the pixel to be decoded indicates that the pixel to be decoded converts the channel component difference into an encoded pixel value, then the encoded pixel value is converted into the channel component difference corresponding to the pixel to be decoded, and the sum of the channel component difference of each channel of the pixel to be decoded and the original pixel value of each channel of the previous pixel is calculated to obtain the original pixel value corresponding to the pixel to be decoded.
9. An electronic device, characterized in that, The electronic device includes a memory and a processor, the processor being configured to execute program instructions stored in the memory to implement the steps of the image lossless encoding method as described in any one of claims 1-5 or the image lossless decoding method as described in any one of claims 6-8.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program instructions that can be executed by a processor to implement the steps of the image lossless encoding method as described in any one of claims 1-5 or the image lossless decoding method as described in any one of claims 6-8.