Image compression method, device, computer equipment, storage medium and program product
By detecting flat subsequences and identifying edge regions in image compression, the problems of insufficient image edge quality and high space occupancy cost in traditional methods are solved, and high-quality image compression and the effect of reducing space occupancy cost is achieved.
Patent Information
- Application Number
- CN202411678585.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-11-22
AI Technical Summary
Traditional image compression methods are difficult to maintain image quality when processing image edge areas, and completely retaining pixel information of one or more rows will lead to high space occupancy costs.
By detecting a flat subsequence that meets a specific condition in the current tile of the image, the number of bits required for information recording is determined, and the key information of the flat subsequence is recorded based on the number of bits. If the preset proximity and matching conditions are met, the current tile is determined as an edge area and a larger number of coded bits are assigned to it.
It effectively ensures the image quality of the compressed image edge area, while reducing the cost of space occupation. By identifying and processing edge areas, the clarity after image compression is improved.
Smart Images

Figure CN119211554B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image compression method, apparatus, computer equipment, storage medium and program product. Background Art
[0002] Image compression can effectively reduce the size of image data, which is beneficial to image storage, image transmission and other downstream services, so images are usually compressed. Traditional image compression methods mainly use specific compression algorithms to compress images, and usually do not consider whether there is an edge area of the object in the image, resulting in quality problems in the edge area of the image after compression; and even if the edge area is considered, when identifying the edge area of the object in the image, in order to avoid the problem of low accuracy caused by only using the pixel information of the current row for identification, the pixel information of the previous row or multiple rows is usually retained, so that when detecting the current row, the pixel information of the current row and the pixel information of the previous row or multiple rows are combined to determine whether the current row belongs to the edge area.
[0003] However, in traditional image compression methods, if the edge area of the object is not considered, quality problems will occur in the edge area of the image after compression. If the edge area of the object is considered and the pixel information of the previous row or multiple rows is completely retained, it will result in a high space occupancy cost. Summary of the invention
[0004] Based on this, it is necessary to provide an image compression method, device, computer equipment, storage medium and program product to address the above technical problems, which can not only ensure the image quality of the edge area of the compressed image, but also effectively reduce the cost of space occupancy.
[0005] In a first aspect, the present application provides an image compression method, the method comprising:
[0006] Detecting an area satisfying a target condition in a current image block of an image, and obtaining a flat subsequence consisting of pixel values in the area; wherein the target condition is that there is an area in the current image block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current image block is greater than the preset threshold;
[0007] Determining a first number of bits required for information recording according to the flat subsequence, and recording key information of the flat subsequence according to the first number of bits; the key information includes sequence existence, a starting position of the flat subsequence, and a starting pixel value;
[0008] determining whether a starting position of the flat subsequence and a starting position of the flat subsequence in a previous block meet a preset proximity condition, and determining whether a starting pixel value of the flat subsequence and a starting pixel value of the flat subsequence in the previous block meet a preset matching condition; the previous block is at least one previous image block that has been encoded before the current block, and the number of bits required to record key information of the previous block is the first number of bits;
[0009] If the preset proximity condition and the preset matching condition are met, the current image block is determined as an edge area, and a second number of bits required for encoding is allocated to the edge area; the second number of bits is greater than the number of bits allocated to the non-edge area;
[0010] The current picture block is encoded according to the second bit number to obtain an encoding result of the current picture block.
[0011] In one of the embodiments, detecting an area satisfying the target condition in the current image block and obtaining a flat subsequence consisting of pixel values in the area comprises:
[0012] In the current block of the image, a sliding window is used to detect whether there is an area where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold;
[0013] If there is an area whose pixel value is smaller than the preset threshold, detecting whether the difference between the maximum pixel value and the minimum pixel value of the entire current image block is greater than the preset threshold;
[0014] If it is greater than the preset threshold, the region meets the target condition, and the pixel values in the region are grouped into a flat subsequence.
[0015] In one embodiment, determining the first number of bits required for information recording according to the flat subsequence comprises:
[0016] The number of first sub-bits required for recording sequence existence allocation;
[0017] Allocating a required number of second sub-bits for recording the starting position of the flat sub-sequence;
[0018] According to the pixel value size of the flat subsequence, allocating a required number of third sub-bits for recording the starting pixel value of the flat subsequence;
[0019] The first sub-bit number, the second sub-bit number and the third sub-bit number are summed to obtain a first bit number required for information recording.
[0020] In one embodiment, the determining whether the starting position of the flat subsequence and the starting position of the flat subsequence in the previous image block meet a preset proximity condition, and determining whether the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous image block meet a preset matching condition comprises:
[0021] Calculating the distance between the starting position of the flat subsequence and the starting position of the flat subsequence in the previous block, and determining whether the distance is less than a preset distance;
[0022] a pixel difference between the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous block, and determining whether the pixel difference is less than a first preset difference;
[0023] If the preset proximity condition and the preset matching condition are met, determining the current image block as an edge area includes:
[0024] If the distance is less than or equal to the preset distance, and the pixel difference is less than or equal to the first preset difference, the current image block is determined as an edge area.
[0025] In one embodiment, the method further comprises:
[0026] Determining whether a starting position of the flat subsequence in the current image block and a starting position of the flat subsequence in the previous image block are offset in the same direction;
[0027] If the preset proximity condition and the preset matching condition are met, determining the current image block as an edge area includes:
[0028] If the starting point positions are offset in the same direction and meet the preset proximity condition and the preset matching condition, the current image block is determined as an edge area.
[0029] In one embodiment, the method further comprises:
[0030] Calculating the length of the flat subsequence in the current image block to obtain a first length;
[0031] Calculating the length of the flat subsequence in the previous block to obtain a second length; or, the key information of the previous block and the key information of the current block both include length information, determining the length of the flat subsequence in the previous block according to the recorded length information to obtain the second length;
[0032] Determining that a difference between the first length and the second length is less than or equal to a second preset difference;
[0033] If the starting point positions are offset in the same direction and meet the preset proximity condition and the preset matching condition, determining the current image block as an edge area includes:
[0034] If the difference is less than or equal to the second preset difference, the starting positions are offset in the same direction, and the preset proximity condition and the preset matching condition are satisfied, the current image block is determined as an edge area.
[0035] In a second aspect, the present application further provides an image compression device, the device comprising:
[0036] a detection module, configured to detect an area satisfying a target condition in a current image block of an image, and obtain a flat subsequence consisting of pixel values in the area; wherein the target condition is that there is an area in the current image block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current image block is greater than the preset threshold;
[0037] a recording module, configured to determine a first number of bits required for information recording according to the flat subsequence, and record key information of the flat subsequence according to the first number of bits; the key information includes sequence existence, a starting position of the flat subsequence, and a starting pixel value;
[0038] a first judgment module, configured to judge whether a starting position of the flat subsequence and a starting position of the flat subsequence in a previous block meet a preset proximity condition, and judge whether a starting pixel value of the flat subsequence and a starting pixel value of the flat subsequence in the previous block meet a preset matching condition; the previous block is at least one previous image block that has been encoded before the current block, and the number of bits required to record key information of the previous block is the first number of bits;
[0039] an allocation module, configured to determine the current image block as an edge area if the preset proximity condition and the preset matching condition are met, and allocate a second number of bits required for encoding to the edge area; the second number of bits is greater than the number of bits allocated to the non-edge area;
[0040] The encoding module is used to encode the current picture block according to the second bit number to obtain an encoding result of the current picture block.
[0041] In one of the embodiments, the detection module is further used to detect, using a sliding window, whether there is an area in the current block of the image where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold; if there is an area less than the preset threshold, then detect whether the difference between the maximum pixel value and the minimum pixel value of the entire current block is greater than the preset threshold; if it is greater than the preset threshold, the area meets the target condition, and the pixel values in the area are organized into a flat subsequence.
[0042] In one of the embodiments, the recording module is further used to allocate a first sub-bit number required for recording the existence of a sequence; allocate a second sub-bit number required for recording the starting position of the flat sub-sequence; allocate a third sub-bit number required for recording the starting pixel value of the flat sub-sequence according to the pixel value size of the flat sub-sequence; and sum the first sub-bit number, the second sub-bit number and the third sub-bit number to obtain the first bit number required for information recording.
[0043] In one embodiment, the first judgment module is further used to calculate the distance between the starting position of the flat subsequence and the starting position of the flat subsequence in the previous image block, and judge whether the distance is less than a preset distance; the pixel difference between the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous image block, and judge whether the pixel difference is less than a first preset difference;
[0044] The allocation module is further configured to determine the current image block as an edge area if the distance is less than or equal to the preset distance and the pixel difference is less than or equal to the first preset difference.
[0045] In one embodiment, the device further comprises:
[0046] A second judgment module is used to judge whether the starting position of the flat subsequence in the current image block and the starting position of the flat subsequence in the previous image block are offset in the same direction;
[0047] The allocation module is further configured to determine the current image block as an edge area if the starting point positions are offset in the same direction and meet the preset proximity condition and the preset matching condition.
[0048] In one embodiment, the device further comprises:
[0049] a calculation module, configured to calculate the length of the flat subsequence in the current block to obtain a first length; calculate the length of the flat subsequence in the previous block to obtain a second length; or, when both the key information of the previous block and the key information of the current block include length information, determine the length of the flat subsequence in the previous block according to the recorded length information to obtain the second length;
[0050] A third judging module, configured to judge whether the difference between the first length and the second length is less than or equal to a second preset difference;
[0051] The allocation module is further configured to determine the current image block as an edge area if the difference is less than or equal to the second preset difference, the starting positions are offset in the same direction, and the preset proximity condition and the preset matching condition are satisfied.
[0052] In a third aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the image compression method when executing the computer program.
[0053] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the image compression method are implemented.
[0054] In a fifth aspect, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the image compression method are implemented.
[0055] The above-mentioned image compression method, apparatus, computer equipment, storage medium and program product detect an area satisfying a target condition in a current block of an image, and obtain a flat subsequence composed of pixel values in the area; wherein the target condition is that there is an area in the current block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current block is greater than the preset threshold; the first number of bits required for information recording is determined according to the flat subsequence, and key information of the flat subsequence is recorded according to the first number of bits; the key information includes sequence existence, the starting position of the flat subsequence and the starting pixel value; the starting position of the flat subsequence is determined Whether the starting position of the flat subsequence in the previous block meets the preset proximity condition, and whether the starting pixel value of the flat subsequence meets the starting pixel value of the flat subsequence in the previous block meets the preset matching condition; the previous block is at least one image block in the previous row that has been encoded before the current block, and the number of bits required to record the key information of the previous block is the first number of bits; if the preset proximity condition and the preset matching condition are met, the current block is determined to be an edge area, and the second number of bits required for encoding is allocated to the edge area; the second number of bits is greater than the number of bits allocated to the non-edge area; the current block is encoded according to the second number of bits to obtain the encoding result of the current block. Therefore, the image compression method of the present application not only considers the edge area of the object in the image, so that the image clarity can be ensured in the edge area after image compression, but also considers the key information of the flat subsequence of the previous block when identifying whether the current block is an edge area, which can not only further effectively improve the clarity of the edge area after compression, but also save the key information of the flat subsequence of the previous block, and the space occupation cost is low. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 A diagram showing an application environment of an image compression method in an embodiment;
[0057] Figure 2 is a schematic flow chart of an image compression method in one embodiment;
[0058] Figure 3 is a schematic flow chart of an image compression method in another embodiment;
[0059] Figure 4 is a structural block diagram of an image compression device in one embodiment;
[0060] Figure 5 is a structural block diagram of an image compression device in another embodiment;
[0061] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0062] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0063] It should be noted that in the following description, the terms "first, second and third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first, second and third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0064] The image compression method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The image compression method can be executed by the terminal 102 or the server 104, or by the terminal 102 and the server 104. Taking the execution of the image compression method by the terminal 102 as an example, the terminal 102 detects the area that meets the target condition in the current block of the image, and obtains a flat subsequence composed of pixel values in the area; wherein the target condition is that there is an area in the current block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current block is greater than the preset threshold; determine the first number of bits required for information recording according to the flat subsequence, and record the key information of the flat subsequence according to the first number of bits; the key information includes the existence of the sequence, the starting position of the flat subsequence and the starting pixel value; judge the starting position of the flat subsequence and the flat subsequence in the previous block Whether the starting position of the column meets the preset proximity condition, and whether the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous block meet the preset matching condition; the previous block is at least one image block in the previous row that has been encoded before the current block, and the number of bits required to record the key information of the previous block is the first number of bits; if the preset proximity condition and the preset matching condition are met, the current block is determined as an edge area, and the second number of bits required for encoding is allocated to the edge area; the second number of bits is greater than the number of bits allocated to the non-edge area; the current block is encoded according to the second number of bits to obtain the encoding result of the current block. After the encoding of the entire image is completed using the above-mentioned image compression method, the encoding result of the entire image can be stored in the server 104, or sent to a friend through the server 104.
[0065] Among them, the terminal 102 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, an Internet of Things device and a portable wearable device. The Internet of Things device can be a smart speaker, a smart TV, a smart air conditioner and a smart car device, etc.
[0066] Server 104 can be an independent physical server or a service node in a blockchain system. A peer-to-peer network is formed between the service nodes in the blockchain system. The peer-to-peer protocol is an application layer protocol running on the Transmission Control Protocol (TCP). In addition, server 104 can also be a server cluster composed of multiple physical servers, and can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
[0067] In one embodiment, Figure 2 As shown, an image compression method is provided, which can be Figure 1 The method is performed by a server or a terminal in the embodiment, or by a server and a terminal in collaboration. Figure 1 The following steps are used as an example to illustrate the terminal execution in:
[0068] S202: Detect an area that meets the target condition in the current image block, and obtain a flat subsequence consisting of pixel values in the area.
[0069] Among them, the image can be a single captured image, such as a person image, a landscape image, an object image, a building image and other types of images; it can also be a video frame in a video. Therefore, by using the image compression method of the present application, the video can also be compressed.
[0070] The target condition is that there is an area in the current block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current block is greater than the preset threshold.
[0071] The current block may be any image block in the current row of the image that is currently to be compressed, and its size may be N×1, where N represents the width of the image block and 1 represents the height of the image block. The current row may refer to a row that is currently to be compressed, and its width may be the width of the image and its height may be 1.
[0072] A flat subsequence may be a sequence of pixel values in a specific region, wherein the difference between the maximum pixel value and the minimum pixel value in the region is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value in the current image block where the region is located is greater than the preset threshold.
[0073] In one embodiment, the terminal uses a sliding window to detect whether there is an area in the current block of the image where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold; if there is an area less than the preset threshold, it detects whether the difference between the maximum pixel value and the minimum pixel value of the entire current block is greater than the preset threshold; if it is greater than the preset threshold, the area meets the target condition, and the pixel values in the area are organized into a flat subsequence.
[0074] For example, when processing an image block, first determine whether there is a flat subsequence, where the flat subsequence needs to meet the set target conditions. For example, in the current block, in one of the sub-regions, the difference between the maximum pixel value and the minimum pixel value is less than or equal to the preset threshold; at the same time, the entire block is not flat, that is, the difference between the maximum pixel value and the minimum pixel value in the block is greater than the preset threshold, then the sub-region is called a flat sub-region.
[0075] It should be pointed out that, for the previous block of the current block, when image compression is performed on it, the previous block also belongs to the current block, and the method of S202 is also used to detect the area that meets the target condition, and obtain a flat subsequence composed of pixel values in the area that meets the target condition in the previous block.
[0076] S204, determining a first number of bits required for information recording according to the flat subsequence, and recording key information of the flat subsequence according to the first number of bits.
[0077] The key information may include sequence existence, the starting position and starting pixel value of the flat subsequence; in addition, the length information of the flat subsequence may also be included.
[0078] When recording the key information of the flat subsequence, the number of bits to be occupied by the key information when recording is first determined, and then the key information of the flat subsequence is recorded in a corresponding storage space, such as a corresponding address space of a memory, according to the number of bits. It should be noted that recording the key information of the flat subsequence may be storing the key information of the flat subsequence using a first number of bits, such as using 13 bits to store the key information of the flat subsequence.
[0079] In one embodiment, when the terminal fails to detect an area that meets the target condition, it may also record relevant information of the current image block, such as recording the sequence existence of the current image block.
[0080] In one embodiment, the terminal allocates a first sub-bit number required for recording the existence of a sequence; allocates a second sub-bit number required for recording the starting position of a flat sub-sequence; allocates a third sub-bit number required for recording the starting pixel value of the flat sub-sequence according to the pixel value size of the flat sub-sequence; and sums the first sub-bit number, the second sub-bit number, and the third sub-bit number to obtain the first bit number required for information recording.
[0081] For example, taking a block of size 16×1 as an example, if no flat subsequence is detected, it is represented by 1-bit "0"; if a flat subsequence is detected, it is represented by 1-bit "1"; in addition, considering that the starting position of the flat subsequence must be a number between 0-15, it can be represented by 4 bits; the pixel value of the flat subsequence is generally 8 bits or 10 bits, if it is 8 bits, then the information size that needs to be saved in each block is 1 bit + 4 bits + 8 bits = 13 bits. If the traditional solution is adopted, for a block of size 16×1, the information size that needs to be saved is 16×8 = 128 bits, while the solution of this application only needs to introduce 13 bits of information, which is equivalent to one tenth of the data volume of the traditional solution.
[0082] S206, determining whether the starting position of the flat subsequence and the starting position of the flat subsequence in the previous block meet a preset proximity condition, and determining whether the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous block meet a preset matching condition.
[0083] The previous block may be at least one image block in the previous row that has been coded before the current block. In addition, the previous block is a block at a position corresponding to the current block in the previous row, such as a block directly above the current block and in the previous row. It should be noted that the previous block is a block in the previous row, so it can also be called a previous block. For example, it can be an image block that has been coded before the current block and belongs to the previous row (i.e., the previous row or rows). The number of bits required to record the key information of the previous block is the first number of bits.
[0084] In one embodiment, the terminal calculates the distance between the starting position of the flat subsequence and the starting position of the flat subsequence in the previous image block, and determines whether the distance is less than a preset distance; and calculates the pixel difference between the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous image block, and determines whether the pixel difference is less than a first preset difference.
[0085] For example, it is determined whether the starting pixel value of the flat subsequence of the current block is sufficiently similar to the starting pixel value of the flat subsequence of the block at the corresponding position in the previous row or multiple rows, that is, the difference in pixel values is less than or equal to a certain threshold; and it is determined whether the starting position of the flat subsequence of the current block is sufficiently close to the starting position of the flat subsequence of the block at the corresponding position in the previous row or multiple rows, that is, the difference in starting positions is less than or equal to a certain threshold.
[0086] S208: If the preset proximity condition and the preset matching condition are met, the current image block is determined as an edge area, and a second number of bits required for encoding is allocated to the edge area.
[0087] The second number of bits is greater than the number of bits allocated to the non-edge area.
[0088] In one embodiment, if the distance is less than or equal to a preset distance and the pixel difference is less than or equal to a first preset difference, the current image block is determined as an edge area, and the second number of bits required for encoding is allocated to the edge area.
[0089] When judging whether the current block is an edge area, the texture direction can also be combined for judgment, such as vertical stripes, stripes from the upper left to the lower right, and stripes from the upper right to the lower left. Specifically: the terminal determines whether the starting position of the flat subsequence in the current block and the starting position of the flat subsequence in the previous block are offset in the same direction; if the starting positions are offset in the same direction and meet the preset proximity conditions and preset matching conditions, the current block is determined to be an edge area. Therefore, by combining the texture direction to judge whether the current block is an edge area, the accuracy of edge area judgment can be further improved.
[0090] For example, it is determined whether the starting position of the flat subsequence of the current image block and the starting position of the flat subsequence of the corresponding image block in one or more rows above are offset in the same direction. For example, if the starting position of the n-2 row is 2, the starting position of the n-1 row is 3, and the starting position of the current row is 4, then if other conditions are met, the current image block can be determined to be an edge area.
[0091] Considering that the length of the edge area of the object in the image is relatively close within several lines, for example, the width of the edge of the trunk of an image containing trees is relatively close within several lines, the length information can also be added for judgment, as follows:
[0092] When judging whether the current block is an edge area, the judgment can also be made in combination with the length information, including or excluding the texture direction. Specifically: the terminal calculates the length of the flat subsequence in the current block to obtain a first length; calculates the length of the flat subsequence in the previous block to obtain a second length; or, the key information of the previous block and the key information of the current block both include length information, and the length of the flat subsequence in the previous block is determined according to the recorded length information to obtain the second length; it is judged that the difference between the first length and the second length is less than or equal to the second preset difference; if the difference is less than or equal to the second preset difference, the starting position is offset in the same direction, and the preset proximity condition and the preset matching condition are met, the current block is determined to be an edge area; or, if the difference is less than or equal to the second preset difference, the preset proximity condition and the preset matching condition are met, the current block is determined to be an edge area.
[0093] The length of the flat subsequence in the previous block may be calculated when needed, or may be saved together with the starting position and starting pixel value of the flat subsequence in the previous block and obtained when needed.
[0094] In one embodiment, after calculating the first length of the flat subsequence in the current tile, the number of bits of the first length can also be determined, and then the first number of bits required for information recording is determined based on the above-mentioned first sub-bit number, second sub-bit number, third sub-bit number and the number of bits of the first length, thereby saving the key information including the first length.
[0095] For example, when saving the related information of the flat subsequence, the length information of the flat subsequence is also saved; it is determined whether the difference between the length of the flat subsequence of the current block and the length of the flat subsequence of the previous block corresponding to the above rows is less than a certain threshold. If it is less than the certain threshold and the above-mentioned conditions are also met, the current block can be determined to be an edge area.
[0096] The second number of bits can be determined in the following manner: when the terminal determines that the current image block is an edge area, the terminal can use a coding algorithm to allocate more bits to the current image block to obtain a second number of bits; wherein the second number of bits is greater than the number of bits allocated to the non-edge area, thereby effectively improving the image quality of the edge area when encoding the edge area.
[0097] S210, encode the current picture block according to the second bit number to obtain an encoding result of the current picture block.
[0098] Among them, encoding the blocks can effectively reduce the data size of the blocks. After each block in the image is encoded, the data size of the image can be effectively reduced, achieving the purpose of image compression, and data storage, transmission and other downstream services can be performed.
[0099] In one embodiment, when encoding, the terminal may use GRC encoding or bit plane encoding to encode the current block according to the second bit number to obtain the encoding result of the current block. In addition, other blocks of the image may also be encoded using the method of S202-S210.
[0100] As an example, combining Figure 3 The details are as follows:
[0101] When processing the previous row (i.e., the preceding row), the existence, starting position, and starting pixel value of the flat subsequence of the block in the previous row are recorded; when processing the blocks in the current row, it is determined whether the block a in the current row (i.e., the block currently being processed) has a flat subsequence. If so, key information of the flat subsequence of the block a is recorded, including at least the starting position and starting pixel value of the flat subsequence; it is determined whether the starting position and starting pixel value of the flat subsequence of the block a match the relevant information of the block at the corresponding position in the previous row. If so, the block a is an edge area; a certain number of bits are allocated to the block a; and the block a is encoded based on the allocated number of bits.
[0102] In the above embodiment, an area satisfying a target condition is detected in a current block of an image, and a flat subsequence consisting of pixel values in the area is obtained; wherein the target condition is that there is an area in the current block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current block is greater than the preset threshold; a first number of bits required for information recording is determined according to the flat subsequence, and key information of the flat subsequence is recorded according to the first number of bits; the key information includes sequence existence, a starting position of the flat subsequence, and a starting pixel value; and a difference between the starting position of the flat subsequence and a flat subsequence in a previous block is determined. whether the starting position of the flat subsequence satisfies the preset proximity condition, and whether the starting pixel value of the flat subsequence satisfies the preset matching condition with the starting pixel value of the flat subsequence in the previous block; the previous block is at least one image block in the previous row that has been encoded before the current block, and the number of bits required to record the key information of the previous block is the first number of bits; if the preset proximity condition and the preset matching condition are met, the current block is determined to be an edge area, and the second number of bits required for encoding is allocated to the edge area; the second number of bits is greater than the number of bits allocated for the non-edge area; the current block is encoded according to the second number of bits to obtain the encoding result of the current block. Therefore, the image compression method of the present application not only considers the edge area of the object in the image, so that the image clarity can be ensured in the edge area after image compression, but also considers the key information of the flat subsequence of the previous block when identifying whether the current block is an edge area, which can not only further effectively improve the clarity of the edge area after compression, but also save the key information of the flat subsequence of the previous block, and the space occupation cost is low.
[0103] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0104] Based on the same inventive concept, the embodiment of the present application also provides an image compression device for implementing the above-mentioned image compression method. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above-mentioned method, so the specific limitations in one or more image compression device embodiments provided below can refer to the limitations on the image compression method above, and will not be repeated here.
[0105] In one embodiment, Figure 4 As shown, an image compression device is provided, including: a detection module 402, a recording module 404, a first judgment module 406, an allocation module 408 and an encoding module 410, wherein:
[0106] The detection module 402 is used to detect an area that meets a target condition in the current image block of the image, and obtain a flat subsequence composed of pixel values in the area; wherein the target condition is that there is an area in the current image block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current image block is greater than the preset threshold;
[0107] A recording module 404 is used to determine a first number of bits required for information recording according to the flat subsequence, and record key information of the flat subsequence according to the first number of bits; the key information includes sequence existence, a starting position of the flat subsequence, and a starting pixel value;
[0108] The first judgment module 406 is used to judge whether the starting position of the flat subsequence and the starting position of the flat subsequence in the previous block meet a preset proximity condition, and judge whether the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous block meet a preset matching condition; the previous block is at least one previous image block that has been encoded before the current block, and the number of bits required to record the key information of the previous block is a first number of bits;
[0109] The allocation module 408 is used to determine the current block as an edge area if the preset proximity condition and the preset matching condition are met, and allocate a second number of bits required for encoding to the edge area; the second number of bits is greater than the number of bits allocated to the non-edge area;
[0110] The encoding module 410 is used to encode the current picture block according to the second bit number to obtain an encoding result of the current picture block.
[0111] In one of the embodiments, the detection module 402 is further used to detect, in the current block of the image, whether there is an area where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold value by using a sliding window; if there is an area less than the preset threshold value, then detect whether the difference between the maximum pixel value and the minimum pixel value of the entire current block is greater than the preset threshold value; if it is greater than the preset threshold value, the area meets the target condition, and the pixel values in the area are organized into a flat subsequence.
[0112] In one embodiment, the recording module 404 is further used to allocate a first sub-bit number required for recording the existence of the sequence; allocate a second sub-bit number required for recording the starting position of the flat sub-sequence; allocate a third sub-bit number required for recording the starting pixel value of the flat sub-sequence according to the pixel value size of the flat sub-sequence; and sum the first sub-bit number, the second sub-bit number and the third sub-bit number to obtain the first bit number required for information recording.
[0113] In one embodiment, the first determination module 406 is further configured to calculate the distance between the starting position of the flat subsequence and the starting position of the flat subsequence in the previous image block, and determine whether the distance is less than a preset distance; and the pixel difference between the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous image block, and determine whether the pixel difference is less than a first preset difference;
[0114] The allocation module 408 is further configured to determine the current image block as an edge area if the distance is less than or equal to a preset distance and the pixel difference is less than or equal to a first preset difference.
[0115] In one embodiment, if Figure 5 As shown, the device also includes:
[0116] A second determination module 412 is used to determine whether the starting position of the flat subsequence in the current block and the starting position of the flat subsequence in the previous block are offset in the same direction;
[0117] The allocation module 408 is further configured to determine the current image block as an edge area if the starting point positions are offset in the same direction and meet a preset proximity condition and a preset matching condition.
[0118] In one embodiment, if Figure 5 As shown, the device also includes:
[0119] The calculation module 414 is used to calculate the length of the flat subsequence in the current block to obtain a first length; calculate the length of the flat subsequence in the previous block to obtain a second length; or, when both the key information of the previous block and the key information of the current block include length information, determine the length of the flat subsequence in the previous block according to the recorded length information to obtain the second length;
[0120] A third determination module 416, configured to determine whether the difference between the first length and the second length is less than or equal to a second preset difference;
[0121] The allocation module 408 is further configured to determine the current image block as an edge area if the difference is less than or equal to a second preset difference, the starting positions are offset in the same direction, and a preset proximity condition and a preset matching condition are satisfied.
[0122] In the above embodiment, an area satisfying a target condition is detected in a current block of an image, and a flat subsequence consisting of pixel values in the area is obtained; wherein the target condition is that there is an area in the current block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current block is greater than the preset threshold; a first number of bits required for information recording is determined according to the flat subsequence, and key information of the flat subsequence is recorded according to the first number of bits; the key information includes sequence existence, a starting position of the flat subsequence, and a starting pixel value; and a difference between the starting position of the flat subsequence and a flat subsequence in a previous block is determined. whether the starting position of the flat subsequence satisfies the preset proximity condition, and whether the starting pixel value of the flat subsequence satisfies the preset matching condition with the starting pixel value of the flat subsequence in the previous block; the previous block is at least one image block in the previous row that has been encoded before the current block, and the number of bits required to record the key information of the previous block is the first number of bits; if the preset proximity condition and the preset matching condition are met, the current block is determined to be an edge area, and the second number of bits required for encoding is allocated to the edge area; the second number of bits is greater than the number of bits allocated for the non-edge area; the current block is encoded according to the second number of bits to obtain the encoding result of the current block. Therefore, the image compression method of the present application not only considers the edge area of the object in the image, so that the image clarity can be ensured in the edge area after image compression, but also considers the key information of the flat subsequence of the previous block when identifying whether the current block is an edge area, which can not only further effectively improve the clarity of the edge area after compression, but also save the key information of the flat subsequence of the previous block, and the space occupation cost is low.
[0123] Each module in the above-mentioned image compression device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0124] In one embodiment, a computer device is provided, which may be a server, including a processor, a memory, an input / output interface (I / O for short) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store image data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, an image compression method is implemented.
[0125] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, an image compression method is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.
[0126] Those skilled in the art will understand that Figure 6The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0127] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps of the above-mentioned image compression method when executing the computer program.
[0128] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned image compression method are implemented.
[0129] In one embodiment, a computer program product is provided, comprising a computer program, which implements the steps of the above-mentioned image compression method when executed by a processor.
[0130] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0131] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0132] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0133] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. An image compression method, characterized in that: The method comprises: Detecting an area satisfying a target condition in a current image block of an image, and obtaining a flat subsequence consisting of pixel values in the area; wherein the target condition is that there is an area in the current image block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current image block is greater than the preset threshold; Allocating a first sub-bit number required for recording the existence of a sequence; allocating a second sub-bit number required for recording the starting position of the flat sub-sequence; allocating a third sub-bit number required for recording the starting pixel value of the flat sub-sequence according to the pixel value of the flat sub-sequence; summing the first sub-bit number, the second sub-bit number and the third sub-bit number to obtain a first bit number required for information recording, and recording key information of the flat sub-sequence according to the first bit number; the key information includes sequence existence, the starting position of the flat sub-sequence and the starting pixel value; determining whether a starting position of the flat subsequence and a starting position of the flat subsequence in a previous block meet a preset proximity condition, and determining whether a starting pixel value of the flat subsequence and a starting pixel value of the flat subsequence in the previous block meet a preset matching condition; the previous block is at least one previous image block that has been encoded before the current block, and the number of bits required to record key information of the previous block is the first number of bits; If the preset proximity condition and the preset matching condition are met, the current image block is determined as an edge area, and a second number of bits required for encoding is allocated to the edge area; the second number of bits is greater than the number of bits allocated to the non-edge area; The current picture block is encoded according to the second bit number to obtain an encoding result of the current picture block.
2. The method according to claim 1, characterized in that: The detecting of an area satisfying a target condition in a current block of an image and obtaining a flat subsequence consisting of pixel values in the area comprises: In the current block of the image, a sliding window is used to detect whether there is an area where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold; If there is an area whose pixel value is smaller than the preset threshold, detecting whether the difference between the maximum pixel value and the minimum pixel value of the entire current image block is greater than the preset threshold; If it is greater than the preset threshold, the region meets the target condition, and the pixel values in the region are grouped into a flat subsequence.
3. The method according to claim 1, characterized in that The determining whether the starting position of the flat subsequence and the starting position of the flat subsequence in the previous image block meet a preset proximity condition, and determining whether the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous image block meet a preset matching condition includes: Calculating the distance between the starting position of the flat subsequence and the starting position of the flat subsequence in the previous block, and determining whether the distance is less than a preset distance; a pixel difference between the starting pixel value of the flat subsequence and the starting pixel value of the flat subsequence in the previous block, and determining whether the pixel difference is less than a first preset difference; If the preset proximity condition and the preset matching condition are met, determining the current image block as an edge area includes: If the distance is less than or equal to the preset distance, and the pixel difference is less than or equal to the first preset difference, the current image block is determined as an edge area.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Determining whether a starting position of the flat subsequence in the current image block and a starting position of the flat subsequence in the previous image block are offset in the same direction; If the preset proximity condition and the preset matching condition are met, determining the current image block as an edge area includes: If the starting point positions are offset in the same direction and meet the preset proximity condition and the preset matching condition, the current image block is determined as an edge area.
5. The method according to claim 4, characterized in that The method further comprises: Calculating the length of the flat subsequence in the current image block to obtain a first length; Calculating the length of the flat subsequence in the previous block to obtain a second length; or, the key information of the previous block and the key information of the current block both include length information, determining the length of the flat subsequence in the previous block according to the recorded length information to obtain the second length; Determining that a difference between the first length and the second length is less than or equal to a second preset difference; If the starting positions are offset in the same direction and meet the preset proximity condition and the preset matching condition, determining the current image block as an edge area includes: If the difference is less than or equal to the second preset difference, the starting positions are offset in the same direction, and the preset proximity condition and the preset matching condition are satisfied, the current image block is determined as an edge area.
6. An image compression device, characterized in that: The device comprises: a detection module, configured to detect an area satisfying a target condition in a current image block of an image, and obtain a flat subsequence consisting of pixel values in the area; wherein the target condition is that there is an area in the current image block where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold, and the difference between the maximum pixel value and the minimum pixel value of the entire current image block is greater than the preset threshold; A recording module, configured to allocate a first sub-bit number required for recording the existence of a sequence; allocate a second sub-bit number required for recording the starting position of the flat sub-sequence; allocate a third sub-bit number required for recording the starting pixel value of the flat sub-sequence according to the pixel value of the flat sub-sequence; sum the first sub-bit number, the second sub-bit number and the third sub-bit number to obtain a first bit number required for information recording, and record key information of the flat sub-sequence according to the first bit number; the key information includes sequence existence, the starting position and the starting pixel value of the flat sub-sequence; a first judgment module, configured to judge whether a starting position of the flat subsequence and a starting position of the flat subsequence in a previous block meet a preset proximity condition, and judge whether a starting pixel value of the flat subsequence and a starting pixel value of the flat subsequence in the previous block meet a preset matching condition; the previous block is at least one previous image block that has been encoded before the current block, and the number of bits required to record key information of the previous block is the first number of bits; an allocation module, configured to determine the current image block as an edge area if the preset proximity condition and the preset matching condition are met, and allocate a second number of bits required for encoding to the edge area; the second number of bits is greater than the number of bits allocated to the non-edge area; The encoding module is used to encode the current picture block according to the second bit number to obtain an encoding result of the current picture block.
7. The device according to claim 6, characterized in that The detection module is further used to detect, in the current block of the image, whether there is an area where the difference between the maximum pixel value and the minimum pixel value is less than a preset threshold value by using a sliding window; if there is an area less than the preset threshold value, detect whether the difference between the maximum pixel value and the minimum pixel value of the entire current block is greater than the preset threshold value; if it is greater than the preset threshold value, the area meets the target condition, and the pixel values in the area are organized into a flat subsequence.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Image coding method and device
CN110062230A
Image correction method and device, electronic equipment, medium and program product
CN118608440A