Image compression method, device, computer equipment and readable storage medium

By segmenting the binary image after error diffusion into target areas and matching the mapping template for compression, the problem of randomness in image data after error diffusion that reduces compression efficiency is solved, and efficient image compression is achieved.

CN118509608BActive Publication Date: 2024-09-24ZHUHAI XPRINTER ELECTRONICS TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410967434.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-18
Publication Date
2024-09-24
Estimated Expiration
2044-07-18

AI Technical Summary

Technical Problem

The random diffusion of quantization errors introduced by the error diffusion algorithm in image binarization processing increases the randomness of image data and reduces the compression efficiency of traditional compression methods.

Method used

By dividing the binary image after error diffusion into multiple target areas of the same size, query the target mapping template in the mapping template set according to the number and distribution of target elements in the target area, and perform matching based on the similarity threshold. Use lossless or indexed compression algorithms to compress the target area.

Benefits of technology

It significantly improves the image compression efficiency, reduces the amount of data, adapts to the randomness of the image after error diffusion, and balances compression efficiency and image quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118509608B
    Figure CN118509608B
Patent Text Reader

Abstract

The present application relates to the field of image processing technology related to printers, and in particular to a method, device, computer equipment and readable storage medium for compressing an image. The method comprises: obtaining a binary image and dividing the binary image into a plurality of target areas of the same size; for any target area, taking the element whose element value is 1 in the target area as the target element in the target area; according to the number and distribution of the target elements in the target area, querying the target mapping template corresponding to the target area in the mapping template set; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area; and compressing the target area according to the target mapping template.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of printer-related image processing technology, and in particular to an image compression method, device, computer equipment and readable storage medium. Background Art

[0002] The error diffusion algorithm is a commonly used image binarization method that diffuses the quantization error of a pixel to adjacent pixels, thereby visually retaining more image details. This algorithm can generate visually satisfactory binary images, especially in preserving the edges and details of the image.

[0003] However, since the error diffusion algorithm introduces random diffusion of quantization errors during the processing, the binarized image data has a high degree of randomness. The randomness of the data increases the difficulty of image compression, because traditional compression methods (such as run-length coding, Huffman coding, etc.) usually rely on the repetitive pattern or predictability of the data to achieve efficient compression. In the image after error diffusion, this predictability is greatly reduced, resulting in a decrease in compression efficiency, so it is urgently needed to be improved. Summary of the invention

[0004] Based on this, it is necessary to provide a picture compression method, device, computer equipment and readable storage medium that can improve compression efficiency in response to the above technical problems.

[0005] In a first aspect, the present application provides an image compression method, comprising:

[0006] Obtain a binary image, where the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1;

[0007] Segment the binary image into multiple target regions of the same size;

[0008] For any target region, the element whose element value is 1 in the target region is taken as the target element in the target region;

[0009] According to the number and distribution of target elements in the target area, a target mapping template corresponding to the target area is queried in the mapping template set; wherein the similarity between the number and distribution of elements with element values ​​of 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area;

[0010] The target area is compressed according to the target mapping template.

[0011] In one embodiment, the method further comprises:

[0012] Using the size information of the target area as the size information of the mapping template area corresponding to the target area;

[0013] According to the size information of the target area, determine the upper limit and the lower limit of the number of target elements that can be contained in the target area;

[0014] Generate a value range based on the upper limit and lower limit of the number;

[0015] For any positive integer value in the value interval, a sample mapping template corresponding to the positive integer value is generated according to the size information of the mapping template area and the distribution of the target elements of the positive integer value in the mapping template area;

[0016] The sample mapping templates corresponding to each positive integer value are taken as a mapping template set.

[0017] In one of the embodiments, if the positive integer value is a positive integer greater than 1, a sample mapping template corresponding to the positive integer value is generated according to the distribution of the target elements of the positive integer value in the mapping template area, including:

[0018] Different distribution schemes are adopted to generate sample mapping templates with different distribution conditions corresponding to the positive integer value according to the size information of the mapping template area and the distribution conditions of the target elements with the positive integer value in the mapping template area.

[0019] In one embodiment, according to the number and distribution of target elements in the target area, searching the mapping template set for a target mapping template whose similarity with the target area reaches a similarity threshold, includes:

[0020] Searching for a pending mapping template in the mapping template set; wherein the number of target elements in the pending mapping template is the same as the number of target elements in the target region;

[0021] Determine the regional characteristic value of the target area according to the number and distribution of the target elements in the target area; the regional characteristic value includes a row characteristic value and a column characteristic value;

[0022] For any pending mapping template, determining the regional characteristic value of the pending mapping template according to the number and distribution of target elements in the pending mapping template;

[0023] From the regional feature values ​​of the pending mapping templates, a regional feature value whose similarity with the regional feature value of the target region reaches a similarity threshold is selected, and the pending mapping template corresponding to the regional feature value is used as the target mapping template.

[0024] In one embodiment, compressing the target area according to the target mapping template includes:

[0025] Get compression request;

[0026] If the compression request indicates lossless compression, and the size information of the target area is smaller than the size threshold, a lossless compression algorithm is used to compress the target area.

[0027] In one embodiment, compressing the target area according to the target mapping template includes:

[0028] If the compression request is index compression, then find the corresponding target index value of the target mapping template in the index table;

[0029] The target index value is used as the compressed target area to achieve compression processing on the target area.

[0030] In one embodiment,

[0031] In a second aspect, the present application also provides an image compression device, comprising:

[0032] An acquisition module is used to acquire a binary image, where the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1;

[0033] A segmentation module is used to segment the binary image into multiple target areas of the same size;

[0034] A valid value determination module, for any target region, takes the element whose element value in the target region is 1 as the target element in the target region;

[0035] A matching module is used to query a target mapping template corresponding to the target area in the mapping template set according to the number and distribution of target elements in the target area; wherein the similarity between the number and distribution of elements with element value 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area;

[0036] The compression module is used to compress the target area according to the target mapping template.

[0037] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:

[0038] Obtain a binary image, where the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1;

[0039] Segment the binary image into multiple target regions of the same size;

[0040] For any target region, the element whose element value is 1 in the target region is taken as the target element in the target region;

[0041] According to the number and distribution of target elements in the target area, a target mapping template corresponding to the target area is queried in the mapping template set; wherein the similarity between the number and distribution of elements with element values ​​of 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area;

[0042] The target area is compressed according to the target mapping template.

[0043] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the following steps are implemented:

[0044] Obtain a binary image, where the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1;

[0045] Segment the binary image into multiple target regions of the same size;

[0046] For any target region, the element whose element value is 1 in the target region is taken as the target element in the target region;

[0047] According to the number and distribution of target elements in the target area, a target mapping template corresponding to the target area is queried in the mapping template set; wherein the similarity between the number and distribution of elements with element values ​​of 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area;

[0048] The target area is compressed according to the target mapping template.

[0049] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:

[0050] Obtain a binary image, where the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1;

[0051] Segment the binary image into multiple target regions of the same size;

[0052] For any target region, the element whose element value is 1 in the target region is taken as the target element in the target region;

[0053] According to the number and distribution of target elements in the target area, a target mapping template corresponding to the target area is queried in the mapping template set; wherein the similarity between the number and distribution of elements with element values ​​of 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area;

[0054] The target area is compressed according to the target mapping template. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions 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 related drawings can be obtained based on these drawings without paying creative work.

[0056] Figure 1 is a schematic flow chart of an image compression method in one embodiment;

[0057] Figure 2 FIG. 4 is a structural block diagram of an image compression device in one embodiment. DETAILED DESCRIPTION

[0058] 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.

[0059] In an exemplary embodiment, Figure 1 As shown, an image compression method is provided, comprising:

[0060] S101, obtaining a binary image.

[0061] Among them, the binary image is an image processed by the error diffusion algorithm, and the element values of each element in the binary image are 0 or 1.

[0062] It can be understood that a binary image is a special type of image where the value of each pixel can only be 0 or 1. In image processing, binarization is typically used to simplify image analysis, improve processing speed, and highlight key information in the image.

[0063] The Error Diffusion Algorithm is a halftoning technique used to convert a grayscale image or a color image into a binary image while trying to preserve the visual quality of the original image as much as possible. In this process, the algorithm checks each pixel of the image one by one and decides whether the pixel should be set to 0 (black) or 1 (white) according to a certain rule (such as the Floyd-Steinberg algorithm).

[0064] After a pixel is binarized, the difference (i.e., the error) between the original pixel value and the binarized pixel value is calculated and spread to adjacent unprocessed pixels according to a certain ratio. The purpose of this is to consider this error in subsequent binarization processes to reduce the overall distortion of the image.

[0065] S102, segment the binary image into multiple target regions of the same size.

[0066] It can be understood that segmenting the image can make subsequent processing more localized and refined. By processing each small region separately, patterns can be more effectively identified, data can be compressed, or other types of analysis can be performed. Dividing the image into small regions of the same size (for example, each region is an N x N pixel block) can ensure the consistency of processing and simplify the algorithm design. This segmentation method also enables each region to be matched with a predefined N x N grid template. Each segmented target region will be compared with a set of predefined M N x N grid templates. These templates represent various possible binary patterns.

[0067] By finding the template that best matches the target region, the index of this template can be used to represent the original region, thereby achieving compression. Since each pixel in the binary image has only two states (0 or 1), theoretically, an N x N region can have 2^(N*N) different combinations (i.e., K different types). However, by mapping to a predefined set of M templates (M << K), a smaller index value can be used to replace the original pixel combination, thus greatly reducing the storage requirements. The effectiveness of this compression method depends on the selection and number of predefined templates, as well as their ability to effectively represent common patterns in the image.

[0068] S103: For any target region, an element whose element value is 1 in the target region is used as a target element in the target region.

[0069] In the previous step, the binary image has been segmented into multiple target regions of the same size. Each target region is the basic unit of image processing. In a binary image, the pixel value usually has only two possible values: 0 and 1. Among them, the pixel with a value of 1 often represents some specific parts of the image, such as foreground objects or areas of interest. In this step, all pixels with a value of 1 in the target region are defined as target elements. These target elements are the focus of subsequent processing and analysis. By identifying the target elements, key information in the image can be more accurately located and processed. For example, in image compression, these target elements may correspond to important details that need to be retained.

[0070] S104: According to the number and distribution of target elements in the target area, query the target mapping template set for a target mapping template corresponding to the target area.

[0071] The similarity between the number and distribution of elements with element values ​​of 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold. The mapping template set is determined based on the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area.

[0072] Specifically, for each target area, it is necessary to analyze the number of target elements inside it and their distribution in space. This includes the relative positions between target elements, the patterns or structures formed, etc. The mapping template set is a predefined template library that contains a variety of possible binary modes. Each template is an N x N grid with the same size as the target area, and the elements in the template are also binary (0 or 1).

[0073] These templates are designed to represent various typical patterns or structures that may appear in the image. For each target area, the algorithm searches the set of mapping templates for a template that is most similar to the number and distribution of target elements in the target area. This process usually involves calculating the similarity between the target area and each template. The similarity calculation can be designed according to the specific application requirements, and may include comparing the number, location, and pattern of target elements.

[0074] It is understandable that when selecting the grid size (N) and the number of grid templates (M), it is indeed necessary to comprehensively consider the image processing effect, compression efficiency, and computational efficiency.

[0075] Effect of grid size (N):

[0076] The smaller the N: The smaller the range involved in local changes, which means the image content within each grid is more specific and detailed. The image distortion is relatively small because each small grid can better capture the local features of the image. The computational amount is relatively small because processing a smaller area generally requires fewer computing resources.

[0077] The larger the N: The range involved in local changes becomes larger, which may lead to greater image distortion because each grid contains more image content. The computational amount will increase because a larger image area needs to be processed.

[0078] The influence of the number of grid templates (M):

[0079] When N is determined, the range of available values of M (the number of templates) is related to the size of N. Generally speaking, the larger the N, the more possible template combinations there are, so the range of available values of M will become larger. The closer M is to K (assuming K represents the number of all possible template combinations): The effect of the processed image will be closer to the original image because more templates mean higher detail retention. But the compression efficiency will be relatively poor because more template information needs to be stored to reconstruct the image. When M is much smaller than K (M << K): The effect of the processed image will have a较大 gap with the original image because fewer templates may not be able to accurately represent all the details of the original image. But it can better compress the image because only less template information needs to be stored.

[0080] When choosing N and M, it is necessary to make a trade-off according to the specific application scenario and requirements. For example, in image processing tasks that require high fidelity, smaller N and larger M may be selected; while in scenarios that require efficient compression, larger N and smaller M may be chosen. Generally speaking, there is no universal optimal solution, but it is necessary to make a choice and adjustment according to the actual situation.

[0081] Furthermore, in order to determine when a template is "similar enough" to the target area, a similarity threshold needs to be set. Only when the similarity between the target area and a certain template exceeds this threshold, will this template be selected as the target mapping template. The setting of the similarity threshold is a trade-off process. Too high a threshold may result in not finding a suitable template, while too low a threshold may lead to inaccurate matching. Once a template whose similarity to the target area exceeds the threshold is found, this template is selected as the target mapping template. In subsequent compression or processing, the target area will be represented by this template, thus achieving data simplification and compression.

[0082] S105, perform compression processing on the target area according to the target mapping template.

[0083] For each target region, a target mapping template with the highest similarity is found. This template is similar to the target region in shape and structure, so it can be used to represent and compress the original target region data. The core idea of ​​the compression process is to use less data to represent the original image information in order to reduce storage space and transmission costs. In this step, instead of directly storing each pixel value of the target region, the index or identifier of the target mapping template that best matches the region is stored. Since the target mapping templates are predefined and there are a limited number of them, only a relatively small index value needs to be stored instead of the pixel data of the entire region. For each target region, the algorithm replaces the original pixel data with the index of the corresponding target mapping template. This index value will be stored in the compressed image data so that the original image can be reconstructed when needed (although there will be a certain degree of loss). The compressed data will contain a series of template indices corresponding to each target region in the original image. Compression using this method can significantly reduce the amount of data required, but it may also result in a certain degree of image quality loss. The degree of loss depends on the fineness and number of templates and the setting of the similarity threshold.

[0084] In the above-mentioned image compression methods, traditional compression methods (such as run-length coding, Huffman coding, etc.) are more efficient when processing data with highly repetitive patterns or predictability. However, the random diffusion of quantization errors introduced by the error diffusion algorithm increases the randomness of the data and reduces the predictability of the data. S101 to 105 compress by mapping to a predefined template. This method does not rely on the repeatability of the data, but uses the local similarity of the image, so it is more suitable for processing images that have undergone error diffusion. By dividing the image into multiple target areas of the same size (S102), the method can perform more refined processing in the local area. This localized processing method helps to capture and retain important details in the image while ignoring the randomness introduced by error diffusion. S104 achieves effective abstraction and simplification of image data by finding the mapping template that is most similar to the target area. This method can represent a large number of image areas with a small number of templates, thereby significantly improving compression efficiency. By adjusting the similarity threshold (mentioned in S104), a suitable balance between compression efficiency and image quality can be found. This method allows users to adjust the compression settings as needed to meet different application scenarios. The compression method for binary images after error diffusion proposed in this application has the advantages of stronger adaptability, local processing optimization, effective use of templates, balance between compression efficiency and image quality, and simplicity and scalability of the algorithm compared to traditional technologies.

[0085] In an exemplary embodiment, the method includes:

[0086] 11) The size information of the target area is used as the size information of the mapping template area corresponding to the target area.

[0087] Specifically, the size information of the target area is used as the size information of the mapping template area. This means that the size of the mapping template will be exactly the same as the size of the target area. According to the size information of the target area, the upper and lower limits of the number of target elements (i.e., pixels with a value of 1) in the area are determined. This range is calculated based on the size of the target area. For example, an N x N area may contain a maximum of N^2 target elements and a minimum of 0. The number of templates generated by a positive integer near the middle of the value interval is greater than the number of templates generated by the values ​​at both ends of the value interval.

[0088] 12) According to the size information of the target area, determine the upper limit and lower limit of the number of target elements that can be contained in the target area.

[0089] Based on the upper and lower limits calculated in the previous step, a value range is generated. Each positive integer value in this range represents the number of possible target elements (pixels with a value of 1) in the mapping template.

[0090] 13) Generate a value range based on the upper and lower limits of the number.

[0091] 14) For any positive integer value in the value interval, a sample mapping template corresponding to the positive integer value is generated according to the size information of the mapping template area and the distribution of the target elements of the positive integer value in the mapping template area.

[0092] For each positive integer value in the value interval, a corresponding sample mapping template is generated according to the size information of the mapping template area and the distribution of the target elements of the positive integer value in the mapping template area. This step may involve distributing the target elements in different ways in the template area to create a variety of templates.

[0093] 15) The sample mapping templates corresponding to each positive integer value are taken as a mapping template set.

[0094] All sample mapping templates corresponding to positive integer values ​​are collected to form a mapping template set, which will be used for subsequent template matching and compression processing.

[0095] Exemplarily, first, choose an appropriate grid size N. The size of N will determine the size of each template grid. Create a template set: Design M different N×N template grids. The elements in each template grid can be 0 or 1. Cover the number of all 1s: Make sure that the number of grids with a value of 1 in the designed template covers from 0 to N^2. This means that you need to design a template that contains all possible combinations from 0 1s to N×N 1s.

[0096] Specifically, if the positive integer value is a positive integer greater than 1, a sample mapping template corresponding to the positive integer value is generated based on the distribution of the target elements of the positive integer value in the mapping template area, including: adopting different distribution schemes to generate sample mapping templates with different distribution situations corresponding to the positive integer value based on the size information of the mapping template area and the distribution of the target elements of the positive integer value in the mapping template area.

[0097] It can be understood that the target elements are evenly distributed in the mapping template area, ensuring that there is enough space between each element while covering the entire area as much as possible. The target elements are mainly concentrated in a specific part of the mapping template area, such as the center or the edge, to simulate local features that may appear in the image. The target elements are randomly placed in the mapping template area, and each generated sample mapping template may be different, which helps to capture the randomness and diversity in the image. The target elements are placed according to a preset pattern or structure, such as forming a specific pattern or shape to simulate an image area with a specific structure. Combining the above multiple distribution schemes, a sample mapping template with a complex distribution pattern is generated to adapt to the complex situations that may appear in the image.

[0098] Continuing with the above example, for templates with the same number of 1s, we should try to ensure that the distribution of 1s is dispersed and has different shapes. This helps capture more local features in the image.

[0099] Further, according to the number and distribution of target elements in the target area, a target mapping template whose similarity with the target area reaches a similarity threshold is searched in the mapping template set, including:

[0100] 21) Search for the pending mapping template in the mapping template collection.

[0101] The number of target elements in the pending mapping template is the same as the number of target elements in the target area.

[0102] Search the mapping template set for those mapping templates whose target element number is the same as the target element number in the target region. These templates are considered "pending mapping templates" because they are potential matching candidates. 22) According to the number and distribution of target elements in the target region, determine the regional feature value of the target region, which includes row feature value and column feature value.

[0103] According to the number and distribution of target elements in the target area, one or more values ​​that can represent the characteristics of the area, namely "regional eigenvalues", are calculated. These eigenvalues ​​may include row eigenvalues ​​and column eigenvalues, which are obtained by analyzing the distribution patterns of target elements in rows and columns.

[0104] 23) For any pending mapping template, determine the regional feature value of the pending mapping template according to the number and distribution of target elements in the pending mapping template.

[0105] For each pending mapping template found in step 21), the corresponding regional feature values ​​are calculated according to the number and distribution of the target elements inside the template. These feature values ​​are used to compare with the feature values ​​of the target region.

[0106] 24) From the regional feature values ​​of each pending mapping template, a regional feature value whose similarity with the regional feature value of the target region reaches a similarity threshold is selected, and the pending mapping template corresponding to the regional feature value is used as the target mapping template.

[0107] The regional feature value of the target region is compared with the regional feature value of each pending mapping template, and an appropriate similarity measurement method (such as Hamming distance, Euclidean distance, etc.) is used to evaluate the similarity between them.

[0108] From these comparisons, the candidate mapping templates whose similarity reaches or exceeds the preset similarity threshold are selected. These templates are considered to be highly similar to the target area.

[0109] These selected candidate mapping templates are labeled as “target mapping templates” because they have sufficient similarity with the target region and can be used for subsequent image processing or compression tasks.

[0110] Exemplarily, mapping the target area A to the most similar target mapping B includes:

[0111] ① Calculate feature distance:

[0112] For the target area A and each template B in the mapping template set, their row feature distance is first calculated. This can be done by comparing the row feature value of A with the row feature value of each template B. The row feature value is a binary sequence converted from the pixel value of each row in the image area (in this scenario, it is mainly the target element, that is, the distribution of pixels with a value of 1).

[0113] The Hamming distance is used to calculate the difference between these feature values. The Hamming distance is an indicator to measure the difference between two strings. It represents the number of different characters in the corresponding positions between two strings of equal length. Here, it can effectively reflect the similarity between the target area A and the template B in the row direction.

[0114] Similarly, the column feature distance is calculated, that is, the column feature value of A is compared with the column feature value of each template B, and the Hamming distance is used to measure the difference between them.

[0115] ② Calculate the final distance:

[0116] The calculated row feature distance and column feature distance are added together to obtain the final distance between A and each template B. This summed distance provides a comprehensive similarity measure that takes into account the characteristics of the image region in both row and column directions.

[0117] ③ Select the best matching template:

[0118] From all the calculated final distances, select the template B with the smallest distance. This template is most similar to the target area A in terms of row and column features.

[0119] Finally, the target area A is mapped to the selected most similar template B. This means that in the subsequent image processing or compression process, area A will be replaced or represented as template B, thereby achieving image simplification and compression.

[0120] In an exemplary embodiment, compressing the target area according to the target mapping template includes:

[0121] 31) Get compression request.

[0122] 32) If the compression request represents lossless compression, and the size information of the target area is smaller than the size threshold, the target area is compressed using a lossless compression algorithm.

[0123] For example, the value of N is 2, 4, 8, etc. because these values ​​can make the data of the N*N grid conveniently represented by bytes (8 bits). When N takes these values, the data of the entire grid can be compactly packed into integer multiples of bytes, which helps to simplify data processing and improve storage and transmission efficiency.

[0124] For example, if N=4, a 4x4 grid contains 16 elements. If these elements are represented only by 0 and 1 (for example, whether a pixel is selected or activated), then the state of the entire grid can be represented by 16 bits. Since 1 byte equals 8 bits, a 4x4 grid can be represented by exactly 2 bytes.

[0125] When the number M of templates B is selected to be 32, it means there are 32 different 4x4 grid templates. During image processing, when a target area matches one of the 32 templates, the area can be replaced with the corresponding template index. Since the number of templates is relatively small, the index value can be represented by a smaller number of bits (for example, 5 bits can represent 32 different templates, because 2^5 = 32).

[0126] In this way, each 4x4 region in the original image may become the same byte sequence (i.e., template index) after mapping, which results in a large number of repeated byte patterns in the compressed data. This repetitiveness makes the data very suitable for further compression using traditional compression algorithms (such as LZ77, Deflate, etc.), because these algorithms can efficiently recognize and encode repeated data patterns.

[0127] 33) If the compression request is index compression, then the corresponding target index value of the target mapping template in the index table is searched; the target index value is used as the compressed target area to implement compression processing on the target area.

[0128] For example, an index table is added to template B, and only the index value is transmitted during transmission, in the following manner:

[0129] ① For example, if N is 8, an 8*8 grid can be represented by 8 bytes, and the number M of templates B is 256.

[0130] When N=8, the 8x8 grid contains 64 cells, each of which can be 0 or 1, so the state of the entire grid theoretically requires 64 bits to represent. However, since we only care about the type of template rather than the value of each specific cell, we can use the template number (index value) to represent the entire template.

[0131] 256 different 8x8 grid templates are selected as the standard template set, so that each template can correspond to an index value from 0 to 255.

[0132] ② Assign an index value to these 256 templates B, ranging from 0 to 255. The index value can be represented and stored with one byte.

[0133] Each template is assigned a unique index value, which is represented by one byte (8 bits) and ranges from 0 to 255. In this way, an 8x8 grid template that originally required 8 bytes to represent now only requires a one-byte index value to represent it.

[0134] ③ The index value (1 byte) corresponding to the original value of B (8 bytes) is transmitted as data (the compressed data here is 1 / 8 of the original value).

[0135] When transmitting or storing data, the original value (8 bytes) of the 8x8 grid is not directly transmitted or stored, but the corresponding index value (1 byte) is transmitted or stored. In this way, the amount of data is reduced to 1 / 8 of the original, greatly improving efficiency.

[0136] ④ When in use, restore the value of template B based on the index and index table.

[0137] At the receiving end or the user end, the received index value can be restored to the original value of the corresponding 8x8 grid template by looking up the index table. This process requires the use of a pre-established index table.

[0138] It should be understood that, although the steps in the flowcharts involved in the above 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 is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may 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 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.

[0139] 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.

[0140] In an exemplary embodiment, Figure 2 As shown, an image compression device is provided, comprising:

[0141] The acquisition module 11 is used to acquire a binary image, where the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1;

[0142] A segmentation module 12 is used to segment the binary image into a plurality of target areas of the same size;

[0143] The effective value determination module 13, for any target area, takes the element whose element value in the target area is 1 as the target element in the target area;

[0144] The matching module 14 is used to query the target mapping template corresponding to the target area in the mapping template set according to the number and distribution of the target elements in the target area; wherein the similarity between the number and distribution of elements with element value 1 in the target mapping template and the number and distribution of the target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area;

[0145] The compression module 15 is used to compress the target area according to the target mapping template.

[0146] 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.

[0147] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:

[0148] Obtain a binary image, where the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1;

[0149] Segment the binary image into multiple target regions of the same size;

[0150] For any target region, the element whose element value is 1 in the target region is taken as the target element in the target region;

[0151] According to the number and distribution of target elements in the target area, a target mapping template corresponding to the target area is queried in the mapping template set; wherein the similarity between the number and distribution of elements with element values ​​of 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area;

[0152] The target area is compressed according to the target mapping template.

[0153] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0154] Obtain a binary image, where the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1;

[0155] Segment the binary image into multiple target regions of the same size;

[0156] For any target region, the element whose element value is 1 in the target region is taken as the target element in the target region;

[0157] According to the number and distribution of target elements in the target area, a target mapping template corresponding to the target area is queried in the mapping template set; wherein the similarity between the number and distribution of elements with element values ​​of 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area;

[0158] The target area is compressed according to the target mapping template.

[0159] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:

[0160] Obtain a binary image, where the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1;

[0161] Segment the binary image into multiple target regions of the same size;

[0162] For any target region, the element whose element value is 1 in the target region is taken as the target element in the target region;

[0163] According to the number and distribution of target elements in the target area, a target mapping template corresponding to the target area is queried in the mapping template set; wherein the similarity between the number and distribution of elements with element values ​​of 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area;

[0164] The target area is compressed according to the target mapping template.

[0165] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method 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 the present application can include at least one of non-volatile memory 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), magnetic 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, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0166] 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 application.

[0167] 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 construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications 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: Acquire a binary image, wherein the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1; Segmenting the binary image into a plurality of target regions of the same size; For any target region, an element whose element value is 1 in the target region is used as a target element in the target region; According to the number and distribution of target elements in the target area, query the target mapping template corresponding to the target area in the mapping template set; wherein the similarity between the number and distribution of elements with element value 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area; The target area is compressed according to the target mapping template.

2. The method according to claim 1, characterized in that The method further comprises: Using the size information of the target area as the size information of the mapping template area corresponding to the target area; Determine an upper limit and a lower limit of the number of target elements that can be included in the target area according to the size information of the target area; Generate a value interval according to the upper limit value of the number and the lower limit value of the number; For any positive integer value in the value interval, a sample mapping template corresponding to the positive integer value is generated according to the size information of the mapping template area and the distribution of the positive integer value target elements in the mapping template area; A mapping template set is generated according to the sample mapping templates corresponding to each positive integer value.

3. The method according to claim 2, characterized in that If the positive integer value is a positive integer greater than 1, the size information of the mapping template area, the distribution of the positive integer value of target elements in the mapping template area, and the generation of a sample mapping template corresponding to the positive integer value include: Different distribution schemes are adopted to generate sample mapping templates with different distribution conditions corresponding to the positive integer value according to the size information of the mapping template area and the distribution conditions of the positive integer value target elements in the mapping template area.

4. The method according to claim 1, characterized in that: The step of searching a mapping template set for a target mapping template corresponding to the target area according to the number and distribution of target elements in the target area includes: Searching for a pending mapping template in the mapping template set; wherein the number of target elements in the pending mapping template is the same as the number of target elements in the target area; Determine the regional characteristic value of the target area according to the number and distribution of the target elements in the target area; the regional characteristic value includes a row characteristic value and a column characteristic value; For any pending mapping template, determining the regional characteristic value of the pending mapping template according to the number and distribution of target elements in the pending mapping template; From the regional feature values ​​of the pending mapping templates, a regional feature value whose similarity with the regional feature value of the target area reaches the similarity threshold is selected, and the pending mapping template corresponding to the regional feature value is used as the target mapping template.

5. The method according to claim 1, characterized in that The compressing the target area according to the target mapping template includes: Get compression request; If the compression request represents lossless compression, and the size information of the target area is smaller than a size threshold, a lossless compression algorithm is used to compress the target area.

6. The method according to claim 1, characterized in that The compressing the target area according to the target mapping template includes: Get compression request; If the compression request is index compression, searching for a corresponding target index value of the target mapping template in the index table; The target index value is used as the compressed target area to achieve compression processing on the target area.

7. An image compression device, characterized in that: include: An acquisition module, used for acquiring a binary image, wherein the binary image is an image processed by an error diffusion algorithm, and the element value of each element in the binary image is 0 or 1; A segmentation module, used for segmenting the binary image into a plurality of target areas of the same size; A valid value determination module, for any target region, taking an element whose element value is 1 in the target region as a target element in the target region; A matching module, configured to query a target mapping template corresponding to the target area in a mapping template set according to the number and distribution of target elements in the target area; wherein the similarity between the number and distribution of elements with an element value of 1 in the target mapping template and the number and distribution of target elements in the target area reaches a similarity threshold; the mapping template set is determined according to the size information of the target area, the upper limit and lower limit of the number of target elements that can be contained in the target area, and the distribution of the target elements in the mapping template area corresponding to the target area; A compression module is used to compress the target area according to the target mapping template.

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 6 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 6 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 6 are implemented.