[go: up one dir, main page]

CN118509608B - Picture compression method, apparatus, computer device and readable storage medium - Google Patents

Picture compression method, apparatus, computer device and readable storage medium Download PDF

Info

Publication number
CN118509608B
CN118509608B CN202410967434.2A CN202410967434A CN118509608B CN 118509608 B CN118509608 B CN 118509608B CN 202410967434 A CN202410967434 A CN 202410967434A CN 118509608 B CN118509608 B CN 118509608B
Authority
CN
China
Prior art keywords
target
target area
mapping template
value
mapping
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202410967434.2A
Other languages
Chinese (zh)
Other versions
CN118509608A (en
Inventor
请求不公布姓名
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhuhai Hengmao Electronic Technology Co ltd
Original Assignee
Zhuhai Hengmao Electronic Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhuhai Hengmao Electronic Technology Co ltd filed Critical Zhuhai Hengmao Electronic Technology Co ltd
Priority to CN202410967434.2A priority Critical patent/CN118509608B/en
Publication of CN118509608A publication Critical patent/CN118509608A/en
Application granted granted Critical
Publication of CN118509608B publication Critical patent/CN118509608B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/85Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using pre-processing or post-processing specially adapted for video compression
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/11Region-based segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/136Segmentation; Edge detection involving thresholding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/74Image or video pattern matching; Proximity measures in feature spaces
    • G06V10/75Organisation of the matching processes, e.g. simultaneous or sequential comparisons of image or video features; Coarse-fine approaches, e.g. multi-scale approaches; using context analysis; Selection of dictionaries
    • G06V10/751Comparing pixel values or logical combinations thereof, or feature values having positional relevance, e.g. template matching
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/74Image or video pattern matching; Proximity measures in feature spaces
    • G06V10/761Proximity, similarity or dissimilarity measures
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N1/00Scanning, transmission or reproduction of documents or the like, e.g. facsimile transmission; Details thereof
    • H04N1/40Picture signal circuits
    • H04N1/405Halftoning, i.e. converting the picture signal of a continuous-tone original into a corresponding signal showing only two levels
    • H04N1/4051Halftoning, i.e. converting the picture signal of a continuous-tone original into a corresponding signal showing only two levels producing a dispersed dots halftone pattern, the dots having substantially the same size
    • H04N1/4052Halftoning, i.e. converting the picture signal of a continuous-tone original into a corresponding signal showing only two levels producing a dispersed dots halftone pattern, the dots having substantially the same size by error diffusion, i.e. transferring the binarising error to neighbouring dot decisions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/17Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object
    • H04N19/172Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object the region being a picture, frame or field
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/42Methods or arrangements for coding, decoding, compressing or decompressing digital video signals characterised by implementation details or hardware specially adapted for video compression or decompression, e.g. dedicated software implementation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Medical Informatics (AREA)
  • Software Systems (AREA)
  • General Health & Medical Sciences (AREA)
  • Evolutionary Computation (AREA)
  • Databases & Information Systems (AREA)
  • Artificial Intelligence (AREA)
  • Health & Medical Sciences (AREA)
  • Compression Of Band Width Or Redundancy In Fax (AREA)

Abstract

The present application relates to the field of image processing technologies related to printers, and in particular, to a method and apparatus for compressing a picture, a computer device, and a readable storage medium. The method comprises the following steps: acquiring a binarized image and dividing the binarized image into a plurality of target areas with the same size; for any target area, taking an element with an element value of 1 in the target area as a target element in the target area; inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of target elements in the target area; the mapping template set is determined according to the size information of the target area, the upper limit value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition 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.

Description

Picture compression method, apparatus, computer device and readable storage medium
Technical Field
The present application relates to the field of image processing technologies related to printers, and in particular, to a method and apparatus for compressing a picture, a computer device, and a readable storage medium.
Background
Error diffusion algorithms are a common method of image binarization processing that preserves more image detail visually by diffusing the quantization error of one pixel to neighboring pixels. Such an algorithm is capable of generating a binary image that is visually pleasing, and in particular is excellent in preserving the edges and details of the image.
However, since the error diffusion algorithm introduces random diffusion of quantization errors during processing, this results in a high randomness of the binarized image data. The randomness of the data increases the difficulty of image compression because conventional compression methods (e.g., run-length encoding, huffman encoding, etc.) typically rely on repeated patterns or predictability of the data to achieve efficient compression. In the error-diffused image, such predictability is greatly reduced, resulting in a reduction in compression efficiency, and thus, improvement is desired.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a picture compression method, apparatus, computer device, and readable storage medium capable of improving compression efficiency.
In a first aspect, the present application provides an image compression method, including:
Acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
dividing the binarized image into a plurality of target areas with the same size;
for any target area, taking an element with an element value of 1 in the target area as a target element in the target area;
Inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition 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.
In one embodiment, the method further comprises:
Taking the size information of the target area as the size information of the mapping template area corresponding to the target area;
According to the size information of the target area, determining the upper limit value and the lower limit value of the number of target elements which can be contained in the target area;
Generating a value interval according to the number upper limit value and the number lower limit value;
for any positive integer value in the value interval, generating a sample mapping template corresponding to the positive integer value according to the size information of the mapping template area and the distribution condition of target elements of the number of the positive integer values in the mapping template area;
And taking a sample mapping template corresponding to each positive integer value as a mapping template set.
In one embodiment, if the positive integer value is a positive integer greater than 1, generating a sample mapping template corresponding to the positive integer value according to a distribution situation of target elements of the positive integer value in a mapping template area, including:
and adopting different distribution schemes, and generating sample mapping templates of different distribution conditions corresponding to the positive integer values according to the size information of the mapping template region and the distribution conditions of the target elements of the positive integer values in the mapping template region.
In one embodiment, according to the number and distribution of target elements in the target area, querying a target mapping template in the mapping template set, where the similarity between the target mapping template and the target area reaches a similarity threshold, includes:
searching a pending mapping template in the mapping template set; the number of target elements in the undetermined mapping template is the same as the number of target elements in the target area;
determining a region characteristic value of the target region according to the number and distribution conditions of target elements in the target region; the region feature values include row feature values and column feature values;
Determining the regional characteristic value of the mapping template to be determined according to the number and distribution conditions of target elements in the mapping template to be determined aiming at any mapping template to be determined;
And selecting a region characteristic value with the similarity reaching a similarity threshold value with the region characteristic value of the target region from the region characteristic values of the to-be-determined mapping templates, and taking the to-be-determined mapping template corresponding to the region characteristic value as the target mapping template.
In one embodiment, the compressing the target area according to the target mapping template includes:
acquiring a compression request;
And if the compression request represents lossless compression and the size information of the target area is smaller than the size threshold, compressing the target area by adopting a lossless compression algorithm.
In one embodiment, the compressing the target area according to the target mapping template includes:
if the compression request is index compression, searching a corresponding target index value of the target mapping template in the index table;
And adopting the target index value as the compressed target area to realize the compression processing of the target area.
In one embodiment of the present invention, in one embodiment,
In a second aspect, the present application also provides an image compression apparatus, including:
The acquisition module is used for acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
The segmentation module is used for segmenting the binarized image into a plurality of target areas with the same size;
The effective value determining module is used for taking an element with an element value of 1 in the target area as a target element in the target area for any target area;
The matching module is used for inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of the target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition of the target elements in the mapping template area corresponding to the target area;
And the compression module is used for compressing the target area according to the target mapping template.
In a third aspect, the present application also provides a computer device comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program:
Acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
dividing the binarized image into a plurality of target areas with the same size;
for any target area, taking an element with an element value of 1 in the target area as a target element in the target area;
Inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition 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.
In a fourth aspect, the present application also provides a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of:
Acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
dividing the binarized image into a plurality of target areas with the same size;
for any target area, taking an element with an element value of 1 in the target area as a target element in the target area;
Inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition 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.
In a fifth aspect, the application also provides a computer program product comprising a computer program which, when executed by a processor, performs the steps of:
Acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
dividing the binarized image into a plurality of target areas with the same size;
for any target area, taking an element with an element value of 1 in the target area as a target element in the target area;
Inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition 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.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the related art, the drawings that are needed in the description of the embodiments of the present application or the related technologies will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and other related drawings may be obtained according to these drawings without inventive effort to those of ordinary skill in the art.
FIG. 1 is a flow chart of an image compression method in one embodiment;
Fig. 2 is a block diagram showing the structure of an image compression apparatus in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
In an exemplary embodiment, as shown in fig. 1, there is provided an image compression method, including:
S101, acquiring a binarized image.
The binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1.
It will be appreciated that a binarized image is a special image in which the value of each pixel can only be 0 or 1. In image processing, binarization is typically used to simplify image analysis, increase processing speed, and highlight critical information in images.
Error diffusion algorithm (Error Diffusion Algorithm) is a halftone technique for converting a gray-scale image or a color image into a binary image while maintaining as much as possible the visual quality of the original image. In this process, the algorithm will examine each pixel of the image one by one and decide, according to some rule (e.g., the Floyd-Steinberg algorithm), whether the pixel should be set to 0 (black) or 1 (white).
When a pixel is binarized, the difference (i.e., error) between the original pixel value and the binarized pixel value is calculated and spread to the adjacent unprocessed pixels in a certain proportion. The purpose of this is to take this error into account in the subsequent binarization process to reduce the distortion of the overall image.
S102, dividing the binarized image into a plurality of target areas with the same size.
It will be appreciated that segmenting the image may make the subsequent processing more localized and refined. By processing each small region separately, patterns, compressed data, or other types of analysis can be more efficiently identified. Dividing the image into small regions of equal size (e.g., each region is a block of N x N pixels) can ensure consistency of processing and simplify algorithm design. This segmentation also enables each region to be matched to a predefined NxN grid template. Each segmented target region will be compared to a set of predefined M N x N grid templates. These templates represent various binarization patterns that may occur.
By finding the template that best matches the target region, the original region can be represented by the index of the template, thereby achieving compression. Since there are only two states (0 or 1) per pixel in the binarized image, a region of N x N can theoretically have 2 (N x N) different combinations (i.e., K different types). But by mapping to predefined M templates (M < < K), the original pixel combination can be replaced with a smaller index value, thereby greatly reducing the storage requirements. The effectiveness of the compression method depends on the selection and number of predefined templates and whether they can effectively represent common patterns in the image.
S103, regarding any target area, taking an element with an element value of 1 in the target area as a target element in the target area.
In the previous step, the binarized image has been segmented into a plurality of target areas of the same size. Each target area is a basic unit of image processing. In a binarized image, the pixel values are usually only two possibilities, 0 and 1. Where a pixel of value 1 often represents some particular portion of the image, such as a foreground object or region of interest. In this step, all pixels with a value of 1 in the target area are defined as target elements. These target elements are the focus of subsequent processing and analysis. By identifying target elements, key information in an image may be more precisely located and processed, for example, in image compression, the target elements may correspond to important details that need to be preserved.
S104, inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution condition of target elements in the target area.
The similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition of the target elements in the mapping template area corresponding to the target area.
In particular, for each target region, it is necessary to analyze the number of target elements within it and their distribution in space. This includes that the set of mapping templates, including the relative positions between the target elements, the patterns or structures formed, etc., is a predefined template library that contains a plurality of possible binarization patterns. Each template is a grid of N x N, the same size as the target area, and the elements in the templates are also binary (0 or 1).
These templates are designed to represent various typical patterns or structures that may appear in the image. For each target region, the algorithm searches a set of mapping templates for a template that most closely resembles the number and distribution of target elements in the target region. This process typically involves calculating the similarity between the target region and each template. The calculation of the similarity may be designed according to specific application requirements, and may include comparing the number, position, formed pattern, and the like of the target elements.
It will be appreciated that in selecting the grid size (N) and the number of grid templates (M), it is indeed necessary to take into account the image processing effect, the compression efficiency and the computational efficiency in combination.
Influence of grid size (N):
The smaller N: the smaller the range to which the local variation relates, which means that the image content within each grid is more specific and detailed. The image distortion is relatively small because each small grid captures the local features of the image better. The amount of computation is relatively small because processing smaller areas generally requires less computing resources.
The greater N: the range to which the local variation relates becomes larger, possibly resulting in greater image distortion, as more image content is contained within each grid. The amount of computation increases because a larger image area needs to be processed.
Influence of the number of grid templates (M):
when N is determined, the range of values of M (the number of templates) is related to the size of N. In general, the larger N, the more template combinations are possible, and thus the larger the range of M values that can be obtained. The closer M is to K (assuming K represents all possible template combinations): the closer the image processed effect will be to the original image, because more templates mean higher detail retention. Compression efficiency may be poor because more template information needs to be stored to reconstruct the image. M is much smaller than K (M < < K): the effect of the processed image will be quite different from the original image, because fewer templates may not accurately represent all details of the original image. But the image is better compressed because less template information needs to be stored.
When selecting N and M, trade-offs need to be made according to the specific application scenario and requirements. For example, in image processing tasks requiring high fidelity, a smaller N and a larger M may be selected; in a scenario where efficient compression is required, a larger N and a smaller M may be selected. In general, there is no general optimal solution, but rather it needs to be selected and adjusted according to the actual situation.
Further, to determine when a template is "sufficiently similar" to the target area, a similarity threshold needs to be set. Only when the similarity of the target region to a certain template exceeds this threshold will the template be selected as the target mapping template. Setting a similarity threshold is a trade-off process, too high a threshold may result in a suitable template not being found, while too low a threshold may result in an inaccurate match. Once a template is found that has a similarity to the target region that exceeds the threshold, the template is selected as the target mapping template. In the subsequent compression or processing, the target area will be represented by this template, thereby enabling simplification and compression of the data.
S105, compressing the target area according to the target mapping template.
And finding out a target mapping template with highest similarity for each target area. This template is similar in shape and structure to the target area, so that the core idea of the data compression process that can be used to represent and compress the original target area is to represent the original image information with less data to reduce storage space and transmission costs. In this step, rather than storing each pixel value of the target region directly, an index or identifier of the target mapping template that best matches the region is stored. Since the target mapping templates are predefined and limited in number, only a relatively small index value need be stored instead of pixel data of the entire area. For each target region, the algorithm replaces the original pixel data with an 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 if desired (although with some loss). The compressed data will contain a series of template indexes that correspond to the respective target areas in the original image. Compression using this method can significantly reduce the amount of data required, but can also result in some degree of image quality loss. The degree of loss depends on the fineness, number of templates and the setting of the similarity threshold.
The above image compression method, conventional compression methods (such as run-length encoding, huffman encoding, etc.), are efficient in processing data with a highly repetitive pattern or predictability. However, the random diffusion of quantization errors introduced by the error diffusion algorithm increases the randomness of the data, reducing the predictability of the data. S101 to 105 are compressed by mapping to a predefined template, which does not depend on the repeatability of the data, but exploits the similarity of image parts and is therefore more adapted to process error-diffused images. By dividing the image into a plurality of target areas of the same size (S102), the method can perform finer processing in the local area. This localized approach helps to capture and preserve important details in the image while ignoring those randomness introduced by error diffusion. S104, by searching the mapping template most similar to the target area, effective abstraction and simplification of the image data are realized. This approach 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 point can be found between compression efficiency and image quality. This approach allows the user to adjust the compression settings as needed to meet different application scenarios. Compared with the traditional technology, the compression method for the binarized image after error diffusion has the advantages of stronger adaptability, local processing optimization, effective utilization of templates, balance of compression efficiency and image quality, simplicity and expandability of an algorithm and the like.
In one exemplary embodiment, the method includes:
11 The size information of the target area is used as the size information of the mapping template area corresponding to the target area.
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. And determining the upper limit value and the lower limit value of the number of target elements (namely pixels with the value of 1) in the region according to the size information of the target region. This range is calculated based on the target region size, e.g., an NxN region may contain up to N2 target elements, and a minimum of 0. The number of templates generated by a positive integer near the middle value of the value interval is larger than the number of templates generated by the values at the two ends of the value interval.
12 According to the size information of the target area, determining the upper limit value and the lower limit value of the number of the target elements which can be contained in the target area.
And generating a value interval according to the number upper limit value and the number lower limit value calculated in the previous step. Each positive integer value within this interval represents the number of possible target elements (pixels with a value of 1) in the mapping template.
13 According to the upper limit value and the lower limit value, a value interval is generated.
14 For any positive integer value in the value interval, generating a sample mapping template corresponding to the positive integer value according to the size information of the mapping template area and the distribution condition of target elements of the number of the positive integer values in the mapping template area.
And generating a corresponding sample mapping template according to the size information of the mapping template area and the distribution condition of target elements of the number of the positive integer values in the mapping template area aiming at each positive integer value in the value interval. This step may involve distributing the target elements in different ways within the template region to create a diversified template.
15 Sample mapping templates corresponding to the positive integer values are used as a mapping template set.
And collecting the sample mapping templates corresponding to all positive integer values to form a mapping template set. This set will be used for subsequent template matching and compression processing.
Illustratively, first, an appropriate grid size N is selected. The size of N will determine the size of each template grid. Creating a template set: m different N template grids were designed. The elements in each template grid may be 0 or 1. Number covering all 1: ensuring that the number of 1-valued lattices in the designed template is covered from 0 to N2. This means that a design template is required, which contains all possible combinations from 0, 1 to nxn 1.
Specifically, if the positive integer value is a positive integer greater than 1, generating a sample mapping template corresponding to the positive integer value according to the distribution condition of target elements of the positive integer value in the mapping template area, including: and adopting different distribution schemes, and generating sample mapping templates of different distribution conditions corresponding to the positive integer values according to the size information of the mapping template region and the distribution conditions of the target elements of the positive integer values in the mapping template region.
It will be appreciated that the target elements are evenly distributed within the region of the mapping template, ensuring that there is sufficient space between each element, while covering the entire region as much as possible. The target elements are focused primarily on a particular portion of the mapped template region, such as the center or edge, to simulate local features that may appear in the image. The target elements are randomly placed within the mapping template region, and each time a sample mapping template is generated, it may be different, which helps capture randomness and diversity in the image. The target elements are placed according to a predetermined pattern or structure, for example, forming a specific pattern or shape, to simulate an image area having a specific structure. In combination with the above-described multiple distribution schemes, a sample mapping template with a complex distribution pattern is generated to accommodate the complex situations that may occur in the image.
Following the above example, for templates with the same number of 1, it should be ensured as much as possible that the distribution of 1 is dispersed and morphologically varied. This helps to capture more local features in the image.
Further, according to the number and distribution of target elements in the target area, querying a target mapping template with similarity reaching a similarity threshold value between the target area in the mapping template set, including:
21 Searching a mapping template set for the undetermined mapping template.
The number of target elements in the undetermined mapping template is the same as the number of target elements in the target area.
And searching the mapping templates with the same number of target elements as the target elements in the target area in the mapping template set. These templates are considered "pending mapping templates" because they are potential match candidates. 22 According to the number and distribution of the target elements in the target area, determining the area characteristic value of the target area, wherein the area characteristic value comprises a row characteristic value and a column characteristic value.
One or more values representing the characteristics of the region, namely 'region characteristic values', are calculated according to the number and distribution of target elements in the target region. These feature values may include row feature values and column feature values, which are derived by analyzing the distribution pattern of the target elements over the rows and columns.
23 For any pending mapping template, determining the regional characteristic value of the pending mapping template according to the number and distribution condition of target elements in the pending mapping template.
For each undetermined mapping template found in step 21), the corresponding region characteristic value is calculated according to the number and distribution of the internal target elements. These feature values will be used for comparison with the feature values of the target area.
24 Selecting the regional characteristic value with the similarity reaching the similarity threshold value with the regional characteristic value of the target region from the regional characteristic values of the to-be-determined mapping templates, and taking the to-be-determined mapping template corresponding to the regional characteristic value as the target mapping template.
The region feature values of the target region are compared with the region feature values of each pending mapping template, and the similarity between them is evaluated using an appropriate similarity measure (e.g., hamming distance, euclidean distance, etc.).
And selecting undetermined mapping templates with similarity reaching or exceeding a preset similarity threshold from the comparisons. These templates are considered to be highly similar to the target area.
These selected pending mapping templates are labeled "target mapping templates" because they have sufficient similarity to the target area to be available for subsequent image processing or compression tasks.
Illustratively, mapping the target region a to the most similar target map B includes:
① Calculating the characteristic distance:
For each template B in the target region a and the set of mapping templates, their line feature distances are first calculated. This may be done by comparing the line feature value of a with the line feature value of each template B. The line feature values are binary sequences that are converted by the pixel values of each line in the image area (in this scenario, mainly the target element, i.e. the distribution of pixels with a value of 1).
The hamming distance is used to calculate the difference between these eigenvalues. The hamming distance is an indicator that measures the difference between two strings and represents the number of different characters at the corresponding positions between two strings of equal length. Here, it can effectively reflect the similarity of the target area a and the template B in the row direction.
Likewise, a column feature distance is calculated, i.e., 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.
② Calculating a final distance:
And adding the calculated row characteristic distance and the column characteristic distance to obtain the final distance between the A and each template B. This sum distance provides an overall similarity measure that considers features of the image region in both the row and column directions.
③ Selecting a best matching template:
From all the calculated final distances, the template B with the smallest distance is selected. This template is most similar to the target area a in row and column features.
Finally, the target area a is mapped onto the selected most similar template B. This means that the a region will be replaced or represented as template B during subsequent image processing or compression, thereby enabling simplification and compression of the image.
In an exemplary embodiment, compressing the target area according to the target mapping template includes:
31A compression request is obtained.
32 If the compression request represents lossless compression and the size information of the target area is smaller than the size threshold, compressing the target area by adopting a lossless compression algorithm.
Illustratively, the values of N are 2, 4, 8, etc. because these values enable the data of an N x N grid to be conveniently represented using bytes (8 bits). When N takes these values, the data of the entire trellis can be compactly packed into an integer multiple of bytes, which helps to simplify data processing and improve storage and transmission efficiency.
Taking n=4 as an example, a 4x4 grid contains 16 elements. If these elements are represented by only 0 and 1 (e.g., indicating whether a pixel is selected or activated), then the state of the entire grid may be represented by 16 bits. Since 1 byte is equal to 8 bits, a 4x4 trellis can be represented using exactly 2 bytes.
When the number M of selection templates B is 32, this means that there are 32 different 4x4 grid templates. When a target region matches one of the 32 templates during image processing, the region may be replaced with the corresponding template index. Because of the relatively small number of templates, the index value may be represented using a small number of bits (e.g., 5 bits may represent 32 different templates because 2^5 =32).
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 repeatability makes the data well suited for further compression using conventional compression algorithms (e.g., LZ77, deflate, etc.), as these algorithms can efficiently identify and encode repeated data patterns.
33 If the compression request is index compression, searching a corresponding target index value of the target mapping template in the index table; and adopting the target index value as the compressed target area to realize the compression processing of the target area.
For example, an index table is added to the template B, and only index values are transmitted during transmission, which adopts the following modes:
① For example, N is 8, a grid of 8x8 can be represented by 8 bytes, and the number M of templates B is 256.
When n=8, the 8×8 grid contains 64 lattices, each lattice may be 0 or 1, and thus the state of the entire grid theoretically requires 64 bits to represent. But since only the kind of template is concerned, not the value of each lattice in particular, the entire template can be represented by the template number (index value).
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.
② An index value ranging from 0 to 255 is assigned to the 256 templates B, and the index value may be represented and stored in one byte.
Each template is assigned a unique index value, represented in a byte (8 bits), ranging from 0 to 255. Thus, an 8x8 grid template, which would otherwise require 8 bytes to represent, now requires only one byte of index value to represent.
③ An index value (1 byte) corresponding to the original value (8 bytes) of B is transmitted as data (here, the compressed data is 1/8 of the original data).
In data transmission or storage, the original value (8 bytes) of the 8x8 grid is not directly transmitted or stored, but the corresponding index value (1 byte) thereof is transmitted or stored. Thus, the data volume is reduced to 1/8 of the original data volume, and the efficiency is greatly improved.
④ And when in use, the value of the template B is obtained by restoring according to the index and the index table.
At the receiving end or the using 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 reliance on a pre-established index table.
It should be understood that, although the steps in the flowcharts related to the above embodiments are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Based on the same inventive concept, the embodiment of the application also provides an image compression device for realizing the above related image compression method. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation in one or more embodiments of the image compression device provided below may refer to the limitation of the image compression method hereinabove, and will not be repeated herein.
In an exemplary embodiment, as shown in fig. 2, there is provided an image compression apparatus including:
the acquisition module 11 is configured to acquire a binary image, where the binary image is an image processed by an error diffusion algorithm, and an element value of each element in the binary image is 0 or 1;
A segmentation module 12 for segmenting the binarized image into a plurality of target areas of the same size;
The effective value determining module 13 takes an element with an element value of 1 in a target area as a target element in the target area for any target area;
The matching module 14 is configured 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; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition of the target elements in the mapping template area corresponding to the target area;
And the compression module 15 is used for performing compression processing on the target area according to the target mapping template.
The respective modules in the above-described image compression apparatus may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one exemplary embodiment, a computer device is provided comprising a memory and a processor, the memory having stored therein a computer program, the processor when executing the computer program performing the steps of:
Acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
dividing the binarized image into a plurality of target areas with the same size;
for any target area, taking an element with an element value of 1 in the target area as a target element in the target area;
Inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition 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.
In one embodiment, a computer readable storage medium is provided having a computer program stored thereon, which when executed by a processor, performs the steps of:
Acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
dividing the binarized image into a plurality of target areas with the same size;
for any target area, taking an element with an element value of 1 in the target area as a target element in the target area;
Inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition 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.
In one embodiment, a computer program product is provided comprising a computer program which, when executed by a processor, performs the steps of:
Acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
dividing the binarized image into a plurality of target areas with the same size;
for any target area, taking an element with an element value of 1 in the target area as a target element in the target area;
Inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition 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.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, database, or other medium used in embodiments provided herein may include at least one of non-volatile memory and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (RESISTIVE RANDOM ACCESS MEMORY, reRAM), magneto-resistive Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (PHASE CHANGE Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in various forms such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The databases referred to in the embodiments provided herein may include at least one of a relational database and a non-relational database. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processor referred to in the embodiments provided in the present application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computation, an artificial intelligence (ARTIFICIAL INTELLIGENCE, AI) processor, or the like, but is not limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the present application.
The foregoing examples illustrate only a few embodiments of the application and are described in detail herein without thereby limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of the application should be assessed as that of the appended claims.

Claims (10)

1. An image compression method, the method comprising:
Acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
Dividing the binarized image into a plurality of target areas with the same size;
for any target area, taking an element with an element value of1 in the target area as a target element in the target area;
Inquiring a target mapping template corresponding to the target area in a mapping template set according to the number and distribution conditions of target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition of the target elements in the mapping template area corresponding to the target area;
and carrying out compression processing on the target area according to the target mapping template.
2. The method according to claim 1, wherein the method further comprises:
the size information of the target area is used as the size information of a mapping template area corresponding to the target area;
determining the upper limit value and the lower limit value of the number of target elements which can be contained in the target area according to the size information of the target area;
generating a value interval according to the number upper limit value and the number lower limit value;
For any positive integer value in the value interval, generating a sample mapping template corresponding to the positive integer value according to the size information of the mapping template area and the distribution condition of target elements of the positive integer value in the mapping template area;
And generating a mapping template set according to the sample mapping templates corresponding to the positive integer values.
3. The method according to claim 2, wherein if the positive integer value is a positive integer greater than 1, generating the sample mapping template corresponding to the positive integer value by the size information of the mapping template region and the distribution of the target elements of the positive integer value in the mapping template region includes:
And adopting different distribution schemes, and generating sample mapping templates of different distribution conditions corresponding to the positive integer values according to the size information of the mapping template region and the distribution conditions of the target elements of the positive integer values in the mapping template region.
4. The method according to claim 1, wherein the querying, in the mapping template set, the target mapping template corresponding to the target area according to the number and distribution of the target elements in the target area includes:
Searching a pending mapping template in the mapping template set; the number of the target elements in the undetermined mapping template is the same as that of the target elements in the target area;
determining a region characteristic value of the target region according to the number and distribution conditions of target elements in the target region; the region characteristic value comprises a row characteristic value and a column characteristic value;
Determining the regional characteristic value of any pending mapping template according to the number and distribution condition of target elements in the pending mapping template;
And selecting a region characteristic value with the similarity reaching the similarity threshold value from the region characteristic values of the to-be-determined mapping templates, and taking the to-be-determined mapping template corresponding to the region characteristic value as a target mapping template.
5. The method of claim 1, wherein the compressing the target area according to the target mapping template comprises:
acquiring a compression request;
And if the compression request represents lossless compression and the size information of the target area is smaller than a size threshold, compressing the target area by adopting a lossless compression algorithm.
6. The method of claim 1, wherein the compressing the target area according to the target mapping template comprises:
acquiring a compression request;
If the compression request is index compression, searching a corresponding target index value of the target mapping template in an index table;
And taking the target index value as a compressed target area to realize compression processing of the target area.
7. An image compression apparatus, comprising:
The acquisition module is used for acquiring a binarized image, wherein the binarized image is an image processed by an error diffusion algorithm, and the element value of each element in the binarized image is 0 or 1;
The segmentation module is used for segmenting the binarized image into a plurality of target areas with the same size;
the effective value determining module is used for taking an element with an element value of 1 in any target area as a target element in the target area;
The matching module is used for inquiring a target mapping template corresponding to the target area in the mapping template set according to the number and distribution conditions of the target elements in the target area; the similarity between the number and distribution conditions of the elements with the element value of 1 in the target mapping template and the number and distribution conditions 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 value and the lower limit value of the number of the target elements which can be contained in the target area, and the distribution condition of the target elements in the mapping template area corresponding to the target area;
And the compression module is used for compressing the target area according to the target mapping template.
8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 6 when the computer program is executed.
9. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
10. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
CN202410967434.2A 2024-07-18 2024-07-18 Picture compression method, apparatus, computer device and readable storage medium Active CN118509608B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410967434.2A CN118509608B (en) 2024-07-18 2024-07-18 Picture compression method, apparatus, computer device and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410967434.2A CN118509608B (en) 2024-07-18 2024-07-18 Picture compression method, apparatus, computer device and readable storage medium

Publications (2)

Publication Number Publication Date
CN118509608A CN118509608A (en) 2024-08-16
CN118509608B true CN118509608B (en) 2024-09-24

Family

ID=92229242

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410967434.2A Active CN118509608B (en) 2024-07-18 2024-07-18 Picture compression method, apparatus, computer device and readable storage medium

Country Status (1)

Country Link
CN (1) CN118509608B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111507338A (en) * 2020-04-15 2020-08-07 广西科技大学 A Chinese Chess Piece Recognition Method Based on Binary Image Skeleton Similarity Calculation
CN111901497A (en) * 2019-06-28 2020-11-06 厦门汉印电子技术有限公司 Gray image processing method and device and printer

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4434868B2 (en) * 2004-07-15 2010-03-17 日立ソフトウエアエンジニアリング株式会社 Image segmentation system
CN105894441A (en) * 2015-12-29 2016-08-24 乐视云计算有限公司 Image matching method and device
CN113873244B (en) * 2020-06-30 2023-10-20 华为技术有限公司 Coefficient coding and decoding method and coefficient coding and decoding device
CN115829835A (en) * 2022-09-21 2023-03-21 北京迈格威科技有限公司 Image processing method, electronic device, storage medium, and computer program product

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111901497A (en) * 2019-06-28 2020-11-06 厦门汉印电子技术有限公司 Gray image processing method and device and printer
CN111507338A (en) * 2020-04-15 2020-08-07 广西科技大学 A Chinese Chess Piece Recognition Method Based on Binary Image Skeleton Similarity Calculation

Also Published As

Publication number Publication date
CN118509608A (en) 2024-08-16

Similar Documents

Publication Publication Date Title
CN111684802B (en) Method and apparatus for hierarchical encoding and decoding of byte streams
Jacquin Fractal image coding based on a theory of iterated contractive image transformations
KR101605173B1 (en) Method for processing an image
CN111462261B (en) Fast CU partitioning and intra-frame decision method for H.266/VVC
US6438268B1 (en) Vector quantization codebook generation method
CN104254877B (en) Method and system for image analysis
WO2013028302A1 (en) Fast matching of image features using multi-dimensional tree data structures
KR20080021592A (en) Image comparison by metric embedding
US20220343550A1 (en) Partitioning method, encoder, decoder and computer storage medium
Kumar et al. Near lossless image compression using parallel fractal texture identification
Wang et al. Raw image reconstruction with learned compact metadata
US20180184096A1 (en) Method and apparatus for encoding and decoding lists of pixels
Zhang et al. Deep network-based image coding for simultaneous compression and retrieval
Chuang et al. Adaptive grayscale image coding scheme based on dynamic multi-grouping absolute moment block truncation coding
KR20190133363A (en) Method and apparatus for verifying integrity of image based on watermark
CN118509608B (en) Picture compression method, apparatus, computer device and readable storage medium
Sun et al. A novel fractal coding method based on MJ sets
CN107682699A (en) A kind of nearly Lossless Image Compression method
mohammed Hasan et al. An adaptive fractal image compression
Admile et al. Content based image retrieval using feature extracted from dot diffusion block truncation coding
Hasnat et al. A proposed multi-image compression technique
Wang et al. Adaptively hybrid fractal image coding
Iranpour et al. Reducing the embedding impact in steganography using Hamiltonian paths and writing on wet paper
Hu et al. Grayscale image coding using optimal pixel grouping and adaptive multi-grouping division block truncation coding
RU2671304C1 (en) Method and system for constructing digital print of video content

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant