Image compression method and apparatus, image decompression method and apparatus, electronic device and storage medium
By obtaining the pixel parameters of the target image and the preset reading method, the compressed run-length encoding is formed, which solves the problem of high compression rate, simplicity and high precision in the existing technology that cannot satisfy different scenarios at the same time, realizes adaptive image compression, and improves compression ratio and accuracy.
Patent Information
- Application Number
- PCT/CN2023/138541
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-02-28
- Filing Date
- 2023-12-13
- Publication Date
- 2024-09-06
AI Technical Summary
Existing image compression methods cannot simultaneously meet the requirements of high compression ratio, simple compression method, and high compression accuracy in different scenarios. Moreover, the lossless compression rate is small or complex, and the lossy compression method will cause a loss of image accuracy in some scenarios.
By obtaining the pixel parameters of the target image, the first absolute difference value and the second absolute difference value are obtained based on the pixel parameters and the preset reading method, forming a compressed run length code, and converting it into a binary value that meets the preset conditions to achieve adaptive Compression method that improves compression ratio and maintains accuracy.
It achieves adaptive compression of target images in different scenarios, improves the compression rate, reduces the complexity of the compression method, and maintains the accuracy of the compressed image, meeting the requirements of high compression rate, simple compression method, and compression accuracy in different scenarios. need.
Smart Images

Figure CN2023138541_06092024_PF_FP
Abstract
Description
Image compression and decompression method, device, electronic device and storage medium This application claims priority to the Chinese patent application filed with the China Patent Office on February 28, 2023, with application number 202310227408.1 and invention name “Image compression and decompression method, device, electronic device and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field The present application belongs to the field of image processing technology, and in particular relates to an image compression and decompression method, device, electronic device and storage medium. Background Art At present, the main image compression methods include lossless compression methods and lossy compression methods. The current lossless compression method has a low compression rate when the pixel values of the image pixels are continuously non-zero, which cannot meet the needs of limited transmission bandwidth and storage capacity, or the lossless compression method is relatively complex, resulting in high compression and decompression time, which cannot meet the needs of platforms with limited computing power. In addition, once the current lossless compression method is selected, the same compression method is used for various scenarios, which cannot meet the compression requirements of different scenarios. At the same time, the lossy compression method will cause a large loss of image accuracy in some scenarios and cannot meet the accuracy requirements. The compression algorithm in the prior art has the problem that the same compression method is used for various scenes, and the compression rate of images of various scenes cannot be high, the compression method is simple, and the compression accuracy is high. Technical issues The embodiments of the present application provide an image compression and decompression method, device, and electronic device, which can solve the problem that the same compression method is used for target images of various scenes, and it cannot simultaneously meet the requirements of a high compression rate, a simple compression method, and high compression accuracy for target images of various scenes. Technical Solutions In a first aspect, an embodiment of the present application provides an image compression method, comprising: obtaining pixel parameters of a target image, the pixel parameters comprising pixel values of each pixel point of the target image; based on the pixel parameters and a preset reading method, obtaining a first absolute difference and a second absolute difference of the pixel values, the first absolute difference representing a threshold absolute difference corresponding to the target image, and the second absolute difference representing an absolute difference between the pixel values of the pixel points in the target image; when the target image is read using the preset reading method, if the second absolute difference is less than or equal to the first absolute difference, obtaining a first sub-code, and if the second absolute difference is greater than the first absolute difference, obtaining a second sub-code; the first sub-code and / or the second sub-code form a compressed run-length code, the compressed run-length code representing the run-length code of the pixel values of each pixel point of the target image corresponding to any scene; converting the compressed run-length code into a binary value of a preset number of bits that meets a preset condition to compress the target image. In one embodiment, obtaining the first absolute difference of the pixel value based on the pixel parameters and the preset reading method includes: obtaining the absolute difference of the pixel values of adjacent pixel points in sequence and obtaining the cumulative probability distribution value of the absolute difference based on the pixel parameters and the preset reading method; the cumulative probability distribution value is greater than or equal to a preset threshold, and the absolute difference corresponding to the cumulative probability distribution value is determined as the first absolute difference. In one of the embodiments, obtaining the second absolute difference of the pixel value based on the pixel parameters and the preset reading method includes: obtaining the average pixel value of each pixel point before the read pointer based on the pixel parameters and the preset reading method; performing an absolute difference operation between the pixel value of the pixel point corresponding to the read pointer and the average pixel value to determine the second absolute difference. In one embodiment, the first subcode includes the number of first continuous pixel values and the first continuous pixel value mean, and the second subcode includes the number of second continuous pixel values and the second continuous pixel value mean; when the target image is read in the preset reading mode, if the second absolute difference is less than or equal to the first absolute difference, the first subcode is obtained, and if the second absolute difference is greater than the first absolute difference, the second subcode is obtained, including: when the pixel values of each pixel point of the target image are read in sequence in the preset reading mode, the size of the second absolute difference and the first absolute difference is determined; if the second absolute difference is less than or equal to the first absolute difference, the number of each pixel point before the read pointer is determined as the first continuous pixel value number, and the preset operation value of the pixel value of each pixel point before the read pointer is determined as the first continuous pixel value operation value; if the second absolute difference is greater than the first absolute difference, the number of each pixel point before the read pointer is determined as the second continuous pixel value number, and the preset operation value of the pixel value of each pixel point before the read pointer is determined as the second continuous pixel value operation value. In one of the embodiments, when the target image is read using the preset reading method, if the second absolute difference is less than or equal to the first absolute difference, a first sub-code is obtained; if the second absolute difference is greater than the first absolute difference, a second sub-code is obtained; and the method further includes: when the target image is read using the preset reading method, if the second absolute difference is less than or equal to the first absolute difference and the second absolute difference is greater than zero, a third sub-code is obtained; if the second absolute difference is greater than the first absolute difference, a second sub-code is obtained; and if the second absolute difference is equal to zero, a fourth sub-code is obtained. In one embodiment, the first sub-code and / or the second sub-code forms a compressed run-length code, and further includes: the second sub-code, the third sub-code and the fourth sub-code form a compressed run-length code. In a second aspect, an embodiment of the present application provides an image decompression method, including: obtaining a compressed target image; converting the compressed target image into a binary value of a preset number of bits; converting the binary value into a compressed run-length code based on a preset condition; converting the compressed run-length code into a first sub-code and / or a second sub-code; based on the first sub-code and / or the second sub-code and a preset reading method, obtaining the decompressed target image. In a third aspect, an embodiment of the present application provides an image compression device, comprising: a first acquisition module, used to acquire pixel parameters of a target image, wherein the pixel parameters include pixel values of each pixel point of the target image; a second acquisition module, used to acquire a first absolute difference and a second absolute difference of the pixel values based on the pixel parameters and a preset reading method, wherein the first absolute difference represents a threshold absolute difference corresponding to the target image, and the second absolute difference represents an absolute difference between the pixel values of the pixel points in the target image; a third acquisition module, used to acquire a first sub-code if the second absolute difference is less than or equal to the first absolute difference when reading the target image using the preset reading method, and to acquire a second sub-code if the second absolute difference is greater than the first absolute difference; an encoding module, used to form a compressed run-length code with the first sub-code and / or the second sub-code, wherein the compressed run-length code represents the run-length code of the pixel values of each pixel point of the target image corresponding to any scene; a compression module, used to convert the compressed run-length code into a binary value of a preset number of bits that meets a preset condition to compress the target image. In a fourth aspect, an embodiment of the present application provides an image decompression device, comprising: a fourth acquisition module, used to acquire a compressed target image; a decompression module, used to decompress the compressed target image into a binary value of a preset number of bits; a first decoding module, used to decode the binary value into a compressed run-length code based on a preset condition; a second decoding module, used to decode the compressed run-length code into a first sub-code and / or a second sub-code; and a fifth acquisition module, used to acquire pixel parameters of the decompressed target image based on the first sub-code and / or the second sub-code and a preset reading method. In a fifth aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method described in any one of the first aspect or the second aspect is implemented. In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of the first aspect or the second aspect is implemented. In a seventh aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute any one of the contents of the first aspect or the method described in the second aspect. It can be understood that the beneficial effects of the second to seventh aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. Beneficial Effects Compared with the prior art, the embodiments of the present invention have the following beneficial effects: By obtaining pixel parameters of the target image, the pixel parameters include pixel values of each pixel point of the target image; based on the pixel parameters and the preset reading method, a first absolute difference and a second absolute difference of the pixel values are obtained, the first absolute difference represents the threshold absolute difference corresponding to the target image, and the second absolute difference represents the absolute difference between the pixel values of the pixel points in the target image. difference; when the target image is read in a preset reading mode, if the second absolute difference is less than or equal to the first absolute difference, the first sub-code is obtained, and if the second absolute difference is greater than the first absolute difference, the second sub-code is obtained; the first sub-code and / or the second sub-code form a compressed run-length code, and the compressed run-length code represents the run-length code of the pixel value of each pixel point of the target image corresponding to any scene; the compressed run-length code is converted into a binary value of a preset number of bits that meets the preset conditions to compress the target image; since the target image of any scene has a corresponding threshold absolute difference (i.e., the first absolute difference), the compressed run-length code of the target image is obtained based on the size relationship between the second absolute difference and the first absolute difference, so that the target images of different scenes are compressed using an adaptive compression method, the compression rate is improved, the complexity of the compression method is reduced, and the accuracy of the compressed target image is maintained, and at the same time, the requirements of high compression rate, simple compression method and compression accuracy of the target images of different scenes are met. BRIEF DESCRIPTION OF THE DRAWINGS In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work. FIG1 is a schematic diagram of an electronic device provided by an embodiment of the present application; FIG2 is a schematic flow chart of an image compression method provided in an embodiment of the present application; 3 is a schematic diagram of a process of obtaining a first absolute difference of pixel values based on pixel parameters and a preset reading method according to an embodiment of the present application; 4 is a schematic diagram of a process of obtaining a second absolute difference of pixel values based on pixel parameters and a preset reading method provided by another embodiment of the present application; 5 is a flowchart of another embodiment of the present application for obtaining a first sub-code if the second absolute difference is less than or equal to the first absolute difference and obtaining a second sub-code if the second absolute difference is greater than the first absolute difference when reading a target image in a preset reading manner; FIG6 is a schematic flow chart of an image decompression method provided by another embodiment of the present application; FIG7 is a schematic diagram of the structure of an image compression device provided in an embodiment of the present application; FIG8 is a schematic diagram of the structure of an image decompression device provided in an embodiment of the present application. Embodiments of the present invention In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application. It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof. It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations. In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance. References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways. Run-length encoding generally refers to Run Length Encoding (RLE), also known as run-length encoding, variable-length encoding, etc. It is a statistical encoding whose main technology is to detect repeated bit or character sequences and replace them with their number of occurrences. Variable-length coding refers to the coding of non-regular opcodes with variable lengths and scattered at different positions in the instruction word. Cumulative Distribution Function (CDF), also known as distribution function or cumulative probability distribution function, is used to describe the probability of a random variable falling on any interval and is considered a certain characteristic of the data. If the variable is a discrete variable, the cumulative probability distribution is a function obtained by summing the distribution laws, and the value of the cumulative distribution function is the cumulative probability distribution value. As shown in Figure 1, electronic equipment terminals integrated with depth cameras, such as mobile phones, mobile robots, sweepers, etc., can be used for face recognition, skeleton recognition, or 3D reconstruction and other functions. The depth camera terminal outputs a disparity map or a depth map containing 3D data of the application scene. After the depth camera terminal collects the 3D data of the application scene, it transmits it to the server for application layer processing. The 3D data needs to be compressed before transmission, and the server then decompresses it. It should be noted that in the embodiment of the present application, the image includes a depth map and a disparity map. The disparity map refers to a two-dimensional image that stores the disparity values of all pixels in a single view after matching. Each pixel position in the disparity map stores the disparity value of the pixel at that position in pixels. Taking the left view disparity map as an example, the disparity value at the pixel position is equal to the column coordinates of the matching point of the pixel on the right image minus its column coordinates on the left image; or the disparity value of the pixel at that position obtained after the view is matched with the reference view. The depth map refers to a two-dimensional image that stores the depth values of all pixels in a single view, where the depth is equal to the Z coordinate of the pixel in the camera coordinate system of the view, which is a spatial unit. Each pixel position in the depth map stores the depth value of the pixel at that position. Disparity maps and depth maps can be converted one-to-one. In the prior art, Microsoft proposed a lossless compression method for depth maps (Run length encoding and Variable Length encoding, RVL for short), which includes differential encoding, positive and negative number mapping, run length encoding and variable length encoding. The encoding scheme of the pixel value of the RVL method is: [number of consecutive zeros] [number of consecutive non-zeros] [continuous non-zero values]. If the pixel values of the depth map are consecutively zero for a large number of times, the compression rate of the RVL compression method is relatively large. However, under normal circumstances, there are relatively few scenes where the pixel values are consecutively zero, resulting in a low compression rate of the RVL compression method, which cannot meet the application requirements with limited transmission bandwidth and storage capacity. In another existing technology, Catid et al. open-sourced a depth map approximate lossless compression algorithm Zdepth on GitHub, which includes data quantization, zero coding, predictive coding, and entropy coding. However, the Zdepth compression method is highly complex, resulting in long compression and decompression time, and cannot meet the application requirements of platforms with limited computing power. Since the compression rate of the lossless compression method RVL is low, the Zdepth compression method is highly complex, and the lossy compression method will cause a large loss of accuracy in some scenarios, the compression method of the existing technology cannot adaptively select the compression algorithm according to the scenario and cannot meet the requirements of the application scenario. The image compression method of the present application obtains pixel parameters of a target image, wherein the pixel parameters include pixel values of each pixel point of the target image; based on the pixel parameters and a preset reading method, obtains a first absolute difference and a second absolute difference of the pixel values, wherein the first absolute difference represents a threshold absolute difference corresponding to a target image of any scene, and the second absolute difference represents an absolute difference between pixel values of pixel points in the target image; when the target image is read in the preset reading method, if the second absolute difference is less than or equal to the first absolute difference, obtains a first sub-code, and if the second absolute difference is greater than the first absolute difference, obtains a second sub-code; the first sub-code and / or the second sub-code form a compressed run-length code, and the compressed run-length code The code represents the run-length encoding of the pixel value of each pixel point of the target image corresponding to any scene; the compressed run-length encoding is converted into a binary value of a preset number of bits that meets the preset conditions to compress the target image; since the target image of any scene has a corresponding threshold absolute difference (i.e., the first absolute difference), the compressed run-length encoding of the target image is obtained based on the size relationship between the second absolute difference and the first absolute difference, thereby achieving an adaptive compression method for target images of different scenes, improving the compression rate, reducing the complexity of the compression method, maintaining the accuracy of the compressed target image, and at the same time meeting the requirements of high compression rate, simple compression method and maintaining compression accuracy for target images of different scenes. The technical solution of the present application is described below through specific embodiments. As shown in FIG. 2 , this embodiment provides an image compression method, which is applied to a terminal and includes: S100, obtaining pixel parameters of a target image, where the pixel parameters include pixel values of each pixel point of the target image. In one embodiment, the pixel parameters of the target image of any scene are obtained, and the pixel parameters include the pixel value of each pixel of the target image, so as to perform pixel data compression processing of the target image. If the target image is a depth map, the pixel value of each pixel is the depth value of the pixel. The pixel parameters of the target image also include pixel width W and pixel height H. For example, if the pixel width W≦256 and the pixel height H≦256, then the number of pixels of the entire target image S≦65535. S200, based on pixel parameters and a preset reading method, obtaining a first absolute difference and a second absolute difference of pixel values. Based on the pixel parameters and the preset reading method, the first absolute difference and the second absolute difference of the pixel value are obtained, which is conducive to encoding according to the threshold absolute difference (i.e., the first absolute difference) and the second absolute difference. In one embodiment, based on the pixel parameters and the preset reading method, the first absolute difference and the second absolute difference of the pixel value are obtained by Zigzag encoding, and the difference between the pixel values of each pixel point is converted into a positive number, which is conducive to encoding. The calculation formula of Zigzag coding is: Wherein, Zigzag(d) represents the Zigzag coding value, and d is the difference between the pixel values of the pixel points. In one embodiment, as shown in FIG3 , obtaining a first absolute difference of pixel values based on pixel parameters and a preset reading method includes: S211, based on the pixel parameters and the preset reading method, the absolute difference values of the pixel values of adjacent pixel points and the cumulative probability distribution value of the absolute difference values are obtained in sequence. Based on the pixel parameters and the preset reading method, the absolute difference δ of the pixel values of adjacent pixels is obtained in sequence, so as to facilitate the use of different preset reading methods according to the pixel parameters of the target image, select the preset reading method with a large compression rate, and improve the compression rate of the target image. In one embodiment, the preset reading method includes a first preset reading method, a second preset reading method, a third preset reading method, a fourth preset reading method, a fifth preset reading method, and a sixth preset reading method. Among them, the first preset reading method is a reading method for traversing each pixel point of the row, the second preset reading method is a reading method for traversing the row according to the preset number of pixel points at intervals, the third preset reading method is a reading method for traversing the pixel rows according to the preset number of pixel points at intervals, and traversing the row according to the preset number of pixel points at intervals when traversing the row, the fourth preset reading method is a reading method for traversing each pixel point of the column, the fifth preset reading method is a reading method for traversing the column according to the preset number of pixel points at intervals, and the sixth preset reading method is a reading method for traversing the pixel rows according to the preset number of pixel points at intervals, and traversing the row according to the preset number of pixel points at intervals when traversing the row. In this embodiment, there is no specific limit on the preset number, and the preset number is less than or equal to 10. For example, the preset number includes 1, 3, 5, 7, and 9, or the preset number includes 2, 4, 6, and 8. It can be understood that the compression rate of the compression method using the first preset reading method and the third preset reading method is lower than the compression rate of the compression method using the second preset reading method and the fourth preset reading method, and the compression rate of the compression method using the second preset reading method and the fourth preset reading method is lower than the compression rate of the compression method using the third preset reading method and the sixth preset reading method. Based on the frequency of different absolute differences, the cumulative probability distribution value of the absolute difference is obtained, which is convenient for accumulating the absolute difference according to different scenarios. The probability distribution value is calculated to select the compression method, thereby improving the compression rate of the target image. In one embodiment, a first preset reading method is adopted, that is, a reading method of traversing each pixel point of a row, and the absolute difference calculation is performed on the pixel values of adjacent pixels in turn. If the absolute difference value δ is 10, the frequency of the absolute difference value δ being 10 is counted once, and the frequency of the absolute difference value δ being 10 appearing again in subsequent readings is cumulatively counted. If another absolute difference value δ is 20, the frequency of the absolute difference value δ being 10 is counted once, and the frequency of the absolute difference value δ being 20 appearing again in subsequent readings is cumulatively counted until the pixel points of the entire target image are traversed and read, and the frequency of each absolute difference value δ appearing in the reading is cumulatively counted, and the cumulative value of the frequency of each absolute difference value δ is divided by the total number of absolute difference values δ to obtain the probability distribution of each absolute difference value δ, and the probability distribution of each absolute difference δ is cumulatively summed to obtain the cumulative probability distribution value CDF of the absolute difference. S212: If the cumulative probability distribution value is greater than or equal to a preset threshold, determine the absolute difference value corresponding to the cumulative probability distribution value as a first absolute difference value. In one embodiment, if the cumulative probability distribution value is greater than or equal to a preset threshold, the absolute difference corresponding to the cumulative probability distribution value is determined as the first absolute difference. Therefore, the first absolute difference represents the threshold absolute difference corresponding to the target image of any scene, which is conducive to compression according to the cumulative probability distribution value of the target image corresponding to any scene, thereby improving the compression rate of the target image. It should be noted that in this embodiment, the specific value of the preset threshold is not limited. The value of the specific preset threshold is set based on the requirements of the target image of any scene. For example, the preset threshold is greater than or equal to 0.9. If the cumulative probability distribution value is greater than or equal to 0.9, the absolute difference 8 corresponding to the cumulative probability distribution value of 0.9 is determined as the first absolute difference, and the first absolute difference (i.e., the threshold absolute difference) is 8. In one embodiment, as shown in FIG. 4 , obtaining a second absolute difference of pixel values based on pixel parameters and a preset reading method includes: S221, based on the pixel parameters and the preset reading method, obtaining the average pixel value of each pixel point before the reading pointer. In one embodiment, based on the pixel values of the pixels of the target image and a preset reading method, the average pixel value of each pixel before the reading pointer is obtained. S222, performing an absolute difference operation on the pixel value of the pixel point corresponding to the read pointer and the average pixel value to obtain a second absolute difference. The pixel value of the pixel point corresponding to the read pointer is calculated by the absolute difference with the average pixel value to obtain the second absolute difference value, so the second absolute difference value represents the absolute difference between the pixel values of the pixel points in the target image. In one embodiment, the pixel values of the four pixels are (10, 12, 15, 30), and the first preset reading method is adopted. When the read pointer points to 12, the average pixel value of each pixel point before the read pointer is obtained as 10, and the pixel value 12 of the pixel point corresponding to the read pointer is calculated by the absolute difference with the average pixel value 10 to obtain the second absolute difference value of 2; when the read pointer points to 15, the average pixel value of each pixel point before the read pointer is obtained as 11, and the pixel value 15 of the pixel point corresponding to the read pointer is calculated by the absolute difference with the average pixel value 11 The second absolute difference obtained by the difference operation is 4; when the read pointer points to 30, the average pixel value of each pixel point before the read pointer is 12 (the average pixel value is rounded), and the pixel value 30 of the pixel point corresponding to the read pointer is rounded to the average pixel value 15, and the second absolute difference is 15. S300, when reading the target image in a preset reading mode, if the second absolute difference is less than or equal to the first absolute difference, obtaining the first sub-code, and if the second absolute difference is greater than the first absolute difference, obtaining the second sub-code. When the target image is read in a preset reading mode, if the second absolute difference is less than or equal to the first absolute difference, the first subcode is obtained, and if the second absolute difference is greater than the first absolute difference, the second subcode is obtained. In the preset reading process, different run-length encodings can be performed based on the threshold absolute difference (i.e., the first absolute difference), thereby improving the compression rate of the target image. In one embodiment, the first subcode includes the number of first continuous pixel values and the mean of the first continuous pixel values, and the second subcode includes the number of second continuous pixel values and the mean of the second continuous pixel values. In one embodiment, as shown in FIG5 , when a target image is read in a preset reading manner, if the second absolute difference is less than or equal to the first absolute difference, a first sub-code is obtained; if the second absolute difference is greater than the first absolute difference, a second sub-code is obtained, including: S311, when sequentially reading pixel values of each pixel point of the target image in a preset reading manner, determining the magnitude of the second absolute difference value and the first absolute difference value. When the pixel values of each pixel point of the target image are read in sequence using a preset reading method, the size of the second absolute difference and the first absolute difference is judged, so as to facilitate different run-length encoding based on the judgment result during the reading process to improve the compression rate of the target image. S312, if the second absolute difference is less than or equal to the first absolute difference, the number of pixels before the reading pointer is determined as the first continuous pixel value number, and the preset operation value of the pixel value of each pixel before the reading pointer is determined as the first continuous pixel value operation value. If the second absolute difference is less than or equal to the first absolute difference, the number of each pixel point before the read pointer is determined as the first continuous pixel value number, and the preset operation value of the pixel value of each pixel point before the read pointer is determined as the first continuous pixel value operation value. The first continuous pixel value number and the first continuous pixel value mean form a first sub-code, so that the pixel value of the pixel point whose absolute difference is less than or equal to the threshold absolute difference can be compressed using the first sub-code, thereby improving the compression rate of the target image and maintaining the accuracy of the target image. The compression method is also very simple. In one embodiment, the preset operation value includes an arithmetic mean and a median, and a specific type of operation value is selected according to the compression requirements of the target image. S313, if the second absolute difference is greater than the first absolute difference, the number of pixels before the reading pointer is set as the second continuous pixel value number, and the preset operation value of the pixel value of each pixel before the reading pointer is determined as the second continuous pixel value operation value. If the second absolute difference is greater than the first absolute difference, the number of pixels before the pointer is read as the second continuous pixel The number of values is determined by reading the preset operation value of the pixel value of each pixel point before the pointer as the second continuous pixel value operation value. In this way, the pixel values of the pixel points whose absolute difference is greater than the threshold absolute difference can be compressed using the second sub-code, thereby improving the compression rate of the target image and maintaining the accuracy of the target image. The compression method is also very simple. In one embodiment, the pixel values of the four pixels are (10, 12, 15, 30). The first preset reading method is used. If the first absolute difference is 8, the number of the first continuous pixel values is 3, the average value of the first continuous pixel values is 12, and the first sub-code formed is [3]
[0012] , the number of the second consecutive pixel values is 1, the average of the second consecutive pixel values is 30, and the second sub-code formed is [1]
[0030] . In one embodiment, when the target image is read in a preset reading mode, if the second absolute difference is less than or equal to the first absolute difference, the first sub-code is obtained; if the second absolute difference is greater than the first absolute difference, the second sub-code is obtained, further comprising: When the target image is read in a preset reading mode, if the second absolute difference is less than or equal to the first absolute difference and the second absolute difference is greater than zero, the third subcode is obtained; if the second absolute difference is zero, the fourth subcode is obtained. This method is suitable for target images with relatively more zero pixel values, and improves the compression rate of the target image while maintaining accuracy. The third sub-code includes the number of third consecutive pixel values and the third consecutive pixel value operation value, and the fourth sub-code is the number of consecutive zero values. S400, the first sub-code and / or the second sub-code forms a compressed run-length code. Specifically, the method of forming the compressed run-length coding includes the first sub-code and the second sub-code forming the compressed run-length coding; the first sub-code forms the compressed run-length coding; or the second sub-code forms the compressed run-length coding. The compressed run-length coding represents the run-length coding of the pixel value of each pixel point of the target image corresponding to any scene, and can compress and save the pixel value of the entire target image according to the target image corresponding to the scene by using the compressed run-length coding, while maintaining the accuracy, improving the compression rate and reducing the complexity of the compression method. In one embodiment, the first sub-code [3]
[0012] and the second sub-code [1]
[0030] form the compressed run-length coding [3]
[0012] [1]
[0030] . In one embodiment, the first subcode and / or the second subcode form a compressed run-length code, further comprising: the second subcode, the third subcode and the fourth subcode form a compressed run-length code. In another embodiment, the first subcode and / or the second subcode form a compressed run-length code, further comprising: the second subcode, the third subcode or the fourth subcode forms a compressed run-length code. The method of the second subcode, the third subcode or the fourth subcode forming a compressed run-length code is suitable for a target image whose pixel values are relatively zero, and the compression rate of the target image is improved while maintaining the accuracy. S500, converting the compressed run-length code into a binary value of a preset number of bits that meets a preset condition, so as to compress the target image. In one embodiment, the compressed run-length code is converted into a binary value of a preset number of bits that meets a preset condition to compress the target image, which is conducive to converting the compressed run-length code of the target image into a binary value for storage. In one embodiment, the preset number of bits includes 16, 32, 64, 128, and 256. The specific number of bits used is set according to the usage scenario. This process is also called variable length coding. For example, the preset number of bits is 32, 4 bits are a group, the run-length code is converted into a binary value, and after the group of 32-bit binary values is filled after 8 storages, the initialized 32-bit binary value is stored again. In one embodiment, converting the compressed run-length code into a binary value of a preset number of bits that meets a preset condition includes: S510, converting a code of the compressed run-length code into a first binary value. S520, performing a 3-digit shift operation on the encoded first binary value in a preset direction to obtain a second binary value of the lowest 3 digits of the first binary value and a third binary value of 4 digits in the preset direction. S530, determining whether the third binary value is greater than zero or equal to zero. S540: If the third binary value is equal to zero, add 0 to the flag bit of the second binary value to form a fourth binary value. S550, if the third binary value is greater than zero, add 1 to the flag bit of the second binary value to form a fifth binary value, and continue to perform a 3-digit shift operation on the first binary value after performing a 3-digit shift operation in the preset direction until the 4-digit third binary value in the preset direction is equal to zero. S560, the fourth binary value and / or the fifth binary value forms an encoded sixth binary value. S570, the sixth binary values of the codes form a binary value of a preset number of bits. The preset direction includes a right direction or a left direction. The position of the flag bit is before or after the second binary value. For example, the values of the compressed run-length codes [3]
[0012] [1]
[0030] [2][4] are converted into binary values
[0011]
[1100] [1]
[11110]
[0010]
[0100] in sequence; the first binary value 0011 of code 3 is shifted rightward by 3 digits, i.e., 0011 is shifted rightward by 3 digits, and 3 zeros are added in front of the binary value 0 after the right shift by 3 digits, so as to obtain the second binary value 011 of the lowest 3 digits of the first binary value 0011, and obtain the third binary value 0000 of 4 digits in the right direction; it is determined whether the third binary value 0000 of 4 digits is greater than zero or equal to zero; since the third binary value 0000 of 4 digits is equal to zero, 0 is added in front of the flag bit of the second binary value 011 of 3 digits after the shift operation, so as to form the fourth binary value 0011 of 4 digits; the fourth binary value 0011 forms the sixth binary value 0011 of code 3. The first binary value 1100 of code 12 is shifted to the right by 3 digits, that is, 1100 is shifted to the right by 3 digits, and 3 zeros are added in front of the binary value 1 after the 3-digit shift to the right to obtain the second binary value 100 of the lowest 3 digits of the first binary value 1100, and the third binary value 0001 of 4 digits is obtained in the right direction; it is determined whether the third binary value 0001 of the 4-digit number is greater than zero or equal to zero; since the third binary value 0001 of the 4-digit number is greater than zero, 1 is added to the front flag bit of the second binary value 100 of the 3-digit number after the shift operation to form the fifth binary value 1100 of 4 digits; and the first binary value 0001 after the 3-digit shift operation in the preset direction is continued to be shifted to the preset direction by 3 digits to obtain the second binary value 100 of the lowest 3 digits of the first binary value 0001. The fourth binary value 1100 and the fourth binary value 0001 are shifted to the right to obtain the third binary value 0000 of the four-digit number; since the third binary value 0000 of the four-digit number is equal to zero, 0 is added to the front flag bit of the second binary value 001 of the three-digit number after the shift operation to form the fourth binary value 0001 of the four-digit number; the fourth binary value 1100 and the fourth binary value 0001 form the sixth binary value 1100 0001 of the code 12. Similarly, the sixth binary values of codes [1],
[0030] , [2], and [4] are obtained respectively, and the sixth binary values of codes [3],
[0012] , [1],
[0030] , [2], and [4] form a 32-bit binary value 0011 1100 0001 0001 1110 0010 0100. In one embodiment, when the number of bits of the sixth binary value of the compressed run-length coding is greater than the number of bits of the binary value of the preset number of bits, a plurality of binary values of the preset number of bits are sequentially formed to compress the target image. In a second aspect, as shown in FIG6 , this embodiment provides an image decompression method, which is applied to a server side and includes: S1100, obtaining a compressed target image. S1200, converting the compressed target image into a binary value of a preset number of bits. S1300, converting the binary value into a compressed run-length code based on a preset condition. S1400, converting the compressed run-length code into a first sub-code and / or a second sub-code. S1500, acquiring a decompressed target image based on the first sub-code and / or the second sub-code and a preset reading method. In one embodiment, a compressed target image is obtained, and the compressed target image is converted into a 32-bit binary value 0011 1100 0001 0001 1110 0010 0100, and the 32-bit binary value is converted into a compressed run-length code [3]
[0012] [1]
[0030] [2][4] based on a preset condition, and the compressed run-length code is converted into a first sub-code and / or a second sub-code, and based on the first sub-code and / or the second sub-code and a preset reading method, a decompressed target image is obtained. It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. Compared with the prior art, the present embodiment has the following beneficial effects: The image compression method of the present application obtains pixel parameters of a target image, wherein the pixel parameters include pixel values of each pixel point of the target image; based on the pixel parameters and a preset reading method, obtains a first absolute difference and a second absolute difference of the pixel values, wherein the first absolute difference represents a threshold absolute difference corresponding to a target image of any scene, and the second absolute difference represents an absolute difference between pixel values of pixel points in the target image; when the target image is read in the preset reading method, if the second absolute difference is less than or equal to the first absolute difference, obtains a first sub-code, and if the second absolute difference is greater than the first absolute difference, obtains a second sub-code; the first sub-code and / or the second sub-code form a compressed run-length code, wherein the compressed run-length code represents a run-length code of pixel values of each pixel point of the target image corresponding to any scene; converts the compressed run-length code into a binary value of a preset number of bits that meets a preset condition to compress the target image; since the target image of any scene has a corresponding The threshold absolute difference (i.e., the first absolute difference) is then used, and the compressed run-length coding of the target image is obtained based on the size relationship between the second absolute difference and the first absolute difference, thereby realizing the use of an adaptive compression method for target images of different scenes, improving the compression rate, reducing the complexity of the compression method, and maintaining the accuracy of the compressed target image. At the same time, it meets the requirements of low compression rate, simple compression method and maintaining compression accuracy for target images of different scenes. In a third aspect, as shown in FIG7 , this embodiment provides an image compression device, including: The first acquisition module 110 is used to acquire pixel parameters of the target image, where the pixel parameters include the pixel value of each pixel point of the target image. The second acquisition module 120 is used to obtain a first absolute difference and a second absolute difference of the pixel value based on the pixel parameters and the preset reading method, the first absolute difference represents the threshold absolute difference corresponding to the target image, and the second absolute difference represents the absolute difference between the pixel values of the pixel points in the target image. The third acquisition module 130 is used to acquire the first subcode if the second absolute difference is less than or equal to the first absolute difference when reading the target image in a preset reading manner, and acquire the second subcode if the second absolute difference is greater than the first absolute difference. The encoding module 140 is used for the first sub-encoding and / or the second sub-encoding to form a compressed run-length coding, where the compressed run-length coding represents the run-length coding of the pixel value of each pixel point of the target image corresponding to any scene. The compression module 150 is used to convert the compressed run-length code into a binary value of a preset number of bits that meets a preset condition, so as to compress the target image. In a fourth aspect, as shown in FIG8 , this embodiment provides an image decompression device, including: The fourth acquisition module 210 is used to acquire the compressed target image. The decompression module 220 is used to decompress the compressed target image into a binary value of a preset number of bits. The first decoding module 230 is used to decode the binary value into a compressed run-length code based on a preset condition. The second decoding module 240 is used to decode the compressed run-length code into the first sub-code and / or the second sub-code. The fifth acquisition module 250 is used to acquire pixel parameters of the decompressed target image based on the first sub-code and / or the second sub-code and a preset reading method. It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / modules are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit. Each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the above-mentioned method embodiment, and will not be repeated here. In a sixth aspect, this embodiment provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method described in any one of the first aspect or the second aspect is implemented. In one embodiment, the electronic device is a depth camera, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method described in any one of the first aspect or the second aspect is implemented. The depth camera also includes a collection module, a transmitting module, and a floodlight. In a seventh aspect, this embodiment provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of the first aspect or the second aspect is implemented. In an eighth aspect, this embodiment provides a computer program product. When the computer program product runs on a terminal device, the terminal device executes any one of the above-mentioned first aspect or the method described in the second aspect. In the ninth aspect, the present embodiment provides an image processing system, comprising a terminal and a processing end, wherein the terminal is used to execute any of the methods described in the first aspect and send the compressed target image to the processing end, and the processing end is used to receive the compressed target image and execute the method described in the second aspect. It can be understood that the beneficial effects of the second to ninth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. The image compression and decompression method provided in the embodiment of the present application can be applied to terminal devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), etc. The embodiment of the present application does not impose any restrictions on the specific type of the terminal device. If the integrated unit is implemented in the form of 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 present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, it can implement the above-mentioned methods. Steps of the embodiment: The computer program includes computer program code, and the computer program code may be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include at least: any entity or device capable of carrying computer program codes to a camera / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk, or an optical disk. In some jurisdictions, according to legislation and patent practice, a computer-readable medium cannot be an electric carrier signal or a telecommunication signal. In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments. Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application. In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment. The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for compressing an image, characterized in that: include: Acquire pixel parameters of a target image, wherein the pixel parameters include pixel values of each pixel point of the target image; Based on the pixel parameters and a preset reading method, a first absolute difference and a second absolute difference of the pixel values are obtained, wherein the first absolute difference represents a threshold absolute difference corresponding to the target image, and the second absolute difference represents an absolute difference between pixel values of the pixel points in the target image; When the target image is read in the preset reading mode, if the second absolute difference is less than or equal to the first absolute difference, a first sub-code is obtained; if the second absolute difference is greater than the first absolute difference, a second sub-code is obtained; The first sub-code and / or the second sub-code form a compressed run-length code, wherein the compressed run-length code represents a run-length code of a pixel value of each pixel point of the target image corresponding to any scene; The compressed run-length code is converted into a binary value of a preset number of bits that meets a preset condition, so as to compress the target image.
2. The method according to claim 1, characterized in that The obtaining, based on the pixel parameter and the preset reading mode, the first absolute difference of the pixel value comprises: Based on the pixel parameters and a preset reading method, the absolute differences of the pixel values of adjacent pixel points are sequentially obtained, and the cumulative probability distribution value of the absolute differences is obtained; If the cumulative probability distribution value is greater than or equal to a preset threshold, the absolute difference value corresponding to the cumulative probability distribution value is determined as the first absolute difference value.
3. The method according to claim 1, characterized in that The obtaining, based on the pixel parameter and the preset reading mode, the second absolute difference of the pixel value comprises: Based on the pixel parameters and the preset reading method, an average pixel value of each pixel point before the reading pointer is obtained; An absolute difference operation is performed between the pixel value of the pixel point corresponding to the read pointer and the average pixel value to determine a second absolute difference.
4. The method according to claim 1, characterized in that The first subcode includes the number of first continuous pixel values and a first continuous pixel value operation value, and the second subcode includes the number of second continuous pixel values and a second continuous pixel value operation value; The method of reading the target image in the preset reading mode, if the second absolute difference is less than or equal to the first absolute difference, obtaining the first sub-code, and if the second absolute difference is greater than the first absolute difference, obtaining the second sub-code, includes: When the pixel values of each pixel point of the target image are read in sequence by using the preset reading method, it is determined that the magnitude of the second absolute difference and the first absolute difference; If the second absolute difference is less than or equal to the first absolute difference, the number of each pixel point before the read pointer is determined as the first number of continuous pixel values, and the preset operation value of the pixel value of each pixel point before the read pointer is determined as the first continuous pixel value operation value; If the second absolute difference is greater than the first absolute difference, the number of each pixel point before the read pointer is set to the second number of continuous pixel values, and the preset operation value of the pixel value of each pixel point before the read pointer is determined as the second continuous pixel value operation value.
5. The method according to claim 1, characterized in that The method further comprises: when the target image is read in the preset reading mode, if the second absolute difference is less than or equal to the first absolute difference, obtaining the first sub-code; and if the second absolute difference is greater than the first absolute difference, obtaining the second sub-code. When the target image is read using the preset reading method, if the second absolute difference is less than or equal to the first absolute difference and the second absolute difference is greater than zero, a third sub-code is obtained; if the second absolute difference is equal to zero, a fourth sub-code is obtained.
6. The method according to claim 5, characterized in that The first sub-code and / or the second sub-code form a compressed run-length code, and further comprises: The second subcode, the third subcode and the fourth subcode form a compressed run-length code.
7. A method for decompressing an image, characterized in that: include: Obtain the compressed target image; Converting the compressed target image into a binary value of a preset number of bits; Converting the binary value into a compressed run-length code based on a preset condition; Converting the compressed run-length code into a first subcode and / or a second subcode; Based on the first sub-code and / or the second sub-code and a preset reading method, the decompressed target image is acquired.
8. An image compression device, characterized in that: include: A first acquisition module, used to acquire pixel parameters of a target image, wherein the pixel parameters include a pixel value of each pixel point of the target image; a second acquisition module, configured to acquire a first absolute difference and a second absolute difference of the pixel value based on the pixel parameter and a preset reading method, wherein the first absolute difference represents a threshold absolute difference corresponding to the target image, and the second absolute difference represents an absolute difference between pixel values of the pixel points in the target image; a third acquisition module, configured to acquire a first sub-code when the target image is read in the preset reading mode if the second absolute difference is less than or equal to the first absolute difference, and acquire a first sub-code when the second absolute difference is greater than the first absolute difference. An absolute difference is obtained to obtain the second sub-code; An encoding module, configured to form a compressed run-length encoding by the first sub-encoding and / or the second sub-encoding, wherein the compressed run-length encoding represents the run-length encoding of the pixel values of each pixel point of the target image corresponding to any scene; The compression module is used to convert the compressed run-length code into a binary value of a preset number of bits that meets a preset condition, so as to compress the target image.
9. An image decompression device, characterized in that: include: A fourth acquisition module, used to acquire a compressed target image; A decompression module, used for decompressing the compressed target image into a binary value of a preset number of bits; A first decoding module, configured to decode the binary value into a compressed run-length code based on a preset condition; A second decoding module, used for decoding the compressed run-length code into a first sub-code and / or a second sub-code; A fifth acquisition module is used to acquire pixel parameters of the decompressed target image based on the first sub-code and / or the second sub-code and a preset reading method.
10. 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 computer program, the method according to any one of claims 1 to 6 or claim 7 is implemented.
Citation Information
Patent Citations
Image compression method and apparatus
CN105979265A
Image processing method and system
CN110460855A
Method and encoder relating to encoding of pixel values to accomplish lossless compression of digital image
CN111885385A
Video coding method and device, equipment and storage medium
CN114760481A
Quantization method, coding apparatus, and computer-readable recording medium storing quantization program
US20150063443A1
Cited By
DCT coefficient processing circuit and method for image compression
CN119232953A
