CN117061759B - Image compression method, device, computer equipment and storage medium - Google Patents

Image compression method, device, computer equipment and storage medium Download PDF

Info

Publication number
CN117061759B
CN117061759B CN202311310568.9A CN202311310568A CN117061759B CN 117061759 B CN117061759 B CN 117061759B CN 202311310568 A CN202311310568 A CN 202311310568A CN 117061759 B CN117061759 B CN 117061759B
Authority
CN
China
Prior art keywords
image
matrix
compressed
filtering
image block
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
CN202311310568.9A
Other languages
Chinese (zh)
Other versions
CN117061759A (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.)
Suzhou Metabrain Intelligent Technology Co Ltd
Original Assignee
Suzhou Metabrain Intelligent 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 Suzhou Metabrain Intelligent Technology Co Ltd filed Critical Suzhou Metabrain Intelligent Technology Co Ltd
Priority to CN202311310568.9A priority Critical patent/CN117061759B/en
Publication of CN117061759A publication Critical patent/CN117061759A/en
Application granted granted Critical
Publication of CN117061759B publication Critical patent/CN117061759B/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/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/176Methods 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 block, e.g. a macroblock
    • 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/102Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
    • H04N19/117Filters, e.g. for pre-processing or post-processing
    • 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/102Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
    • H04N19/124Quantisation
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/80Details of filtering operations specially adapted for video compression, e.g. for pixel interpolation

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)
  • Compression Of Band Width Or Redundancy In Fax (AREA)

Abstract

The invention relates to the technical field of computers, and discloses an image compression method, an image compression device, computer equipment and a storage medium, wherein the method comprises the following steps: acquiring an image compression instruction and at least one image to be compressed; creating a main process based on the image compression instruction; determining the target block number of the first image to be compressed by using a main process; creating a first group of sub-processes and a second group of sub-processes with the number corresponding to the number of the target blocks by using the main process; extracting an image block from the first image to be compressed by using each subprocess in the first group of subprocesses respectively, and obtaining the combination sequence of each image block in the first image to be compressed respectively; respectively carrying out image compression processing on an image block by utilizing each subprocess in the second group of subprocesses to obtain compressed image blocks respectively corresponding to each image block; and combining all the compressed image blocks according to the combination sequence of each image block in the first image to be compressed by using the main process to generate a compressed image of the first image to be compressed.

Description

Image compression method, device, computer equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to an image compression method, an image compression device, a computer device, and a storage medium.
Background
Image compression is an important trend in the development of information technology nowadays, and image and video compression technologies related to the image compression are widely applied to consumer electronic products. Because the image data has more redundant information, the image is generally required to be compressed, so that the image occupies less storage space while retaining as much important information as possible, but the image compression technology is relatively complex, the operation is more, the real-time performance is difficult to ensure when the compression of massive images is carried out, and the efficiency is lower.
Disclosure of Invention
In view of the above, the present invention provides an image compression method, apparatus, computer device and storage medium, so as to solve the problem of low image compression efficiency.
In a first aspect, the present invention provides an image compression method, including:
acquiring an image compression instruction and at least one image to be compressed;
creating a main process based on the image compression instruction;
determining the target block number of a first image to be compressed by using a main process, wherein the first image to be compressed is any image to be compressed;
Creating a first group of sub-processes and a second group of sub-processes with the number corresponding to the number of the target blocks by using the main process;
extracting an image block from the first image to be compressed by using each subprocess in the first group of subprocesses respectively, and obtaining the combination sequence of each image block in the first image to be compressed respectively;
respectively carrying out image compression processing on an image block by utilizing each subprocess in the second group of subprocesses to obtain compressed image blocks respectively corresponding to each image block;
and combining all the compressed image blocks by using a main process according to the combination sequence of each image block in the first image to be compressed respectively to generate a compressed image corresponding to the first image to be compressed.
By the method, an image compression instruction and at least one image to be compressed are acquired; creating a main process based on the image compression instruction; determining the target block number of a first image to be compressed by using a main process, wherein the first image to be compressed is any image to be compressed; creating a first group of sub-processes and a second group of sub-processes with the number corresponding to the number of the target blocks by using the main process; extracting an image block from the first image to be compressed by using each subprocess in the first group of subprocesses respectively, and obtaining the combination sequence of each image block in the first image to be compressed respectively; respectively carrying out image compression processing on an image block by utilizing each subprocess in the second group of subprocesses to obtain compressed image blocks respectively corresponding to each image block; and combining all the compressed image blocks by using a main process according to the combination sequence of each image block in the first image to be compressed respectively to generate a compressed image corresponding to the first image to be compressed. In the method, when the images are compressed, a main process is created to carry out the operation of the block number on each image, a sub-process with the same block number is created by using the main process, and the sub-processes for processing the corresponding tasks are created according to different compression tasks in the compression process, when the compression tasks of different image blocks of the same image are processed, the image compression operation of each sub-process can be synchronously carried out, the efficiency of the whole image compression is greatly improved, the later image classification and identification, the image transmission and the like are also facilitated, the method is particularly suitable for compression requirement scenes of massive images, and the compression efficiency can be greatly improved, so the value of the method in the compression aspect is self-evident.
In an alternative embodiment, extracting a block of image blocks from the first image to be compressed by using each sub-process in the first group of sub-processes, and obtaining a combination sequence of each image block in the first image to be compressed, respectively, includes:
utilizing a main process to allocate a starting extraction position of each image block to each sub-process in the first group of sub-processes, wherein the starting extraction position of each image block is determined according to a preset block size and a target block number;
traversing pixels of a first image to be compressed according to a preset block size from a starting extraction position corresponding to a first subprocess by utilizing the first subprocess to obtain a first image block and an extraction sequence of the first image block, wherein the first subprocess is any subprocess in a first group of subprocesses, and the first image block is the image block extracted by the first subprocess;
the extraction order of the first image blocks is taken as the corresponding combination order of the first image blocks in the first image to be compressed.
By the method, the initial extraction position of the image block is allocated to each sub-process in the first group of sub-processes by the main process, then the first sub-process is utilized to block according to the preset block size from the initial extraction position corresponding to the first sub-process, the first group of sub-processes can simultaneously extract the image block from the respective initial extraction positions, the image can be quickly blocked, and the efficiency of the image block operation is improved.
In an alternative embodiment, the first sub-process is configured to perform a row traversing operation and a column traversing operation, and utilize the first sub-process to traverse pixels of a first image to be compressed according to a preset block size from a start extraction position corresponding to the first sub-process to obtain a first image block and an extraction sequence of the first image block, where the method includes:
starting from a first initial extraction position, performing row traversing operation and column traversing operation on pixels of a first image to be compressed respectively by taking a preset block size as a reference, and obtaining a first image block, wherein the first initial extraction position is an initial extraction position corresponding to a first subprocess;
the order in which the first image blocks are extracted is taken as the extraction order of the first image blocks.
In an alternative embodiment, the method further includes, after traversing pixels of the first image to be compressed according to a preset block size from a start extraction position corresponding to the first sub-process by using the first sub-process to obtain the first image block and an extraction sequence of the first image block:
storing the image blocks in a preset shared data structure according to a combination sequence;
after confirming that all the image blocks are stored in the preset shared data structure, generating identification information corresponding to each image block according to the combination sequence.
By the method, the identification information corresponding to each image block is generated, and then the splicing operation of the whole image can be conveniently finished through the identification information of the image block.
In an alternative embodiment, after storing the image blocks in the preset shared data structure in the combined order, the method further includes:
and sending a storage completion signal to the main process by using the first sub-process, wherein the storage completion signal is used for indicating that the first sub-process is an idle process.
By the method, the first subprocess can timely inform the main process after storing the corresponding image blocks, and the main process can timely allocate other tasks for the first subprocess, so that the resource utilization rate is improved.
In an optional implementation manner, the image compression processing is performed on the first image block by using a second sub-process in the second group of sub-processes to obtain a compressed image block corresponding to the first image block, where the second sub-process is any one sub-process in the second group of sub-processes, and the image compression processing is performed on the first image block to obtain a compressed image block corresponding to the first image block, and specifically includes:
performing coding operation on the first image block to obtain a frequency domain information matrix corresponding to the first image block;
Carrying out quantization operation on the frequency domain information matrix to obtain an initial quantization matrix corresponding to the first image block;
performing filtering operation on the initial quantization matrix to obtain a target quantization matrix corresponding to the first image block;
and performing inverse quantization operation on the target quantization matrix to obtain a first compressed image block corresponding to the first image block.
By the method, the second subprocess in the second group of subprocesses can be utilized to carry out quantization, filtering and inverse quantization operations on the first image block, and the compression process of each image block can be synchronously completed.
In an alternative embodiment, filtering the initial quantization matrix to obtain a target quantization matrix corresponding to the first image block includes:
and filtering the data which are larger than the preset frequency threshold value in the quantization matrix by utilizing a plurality of filter matrixes with different sizes, and obtaining a target quantization matrix corresponding to the first image block.
By the mode, high-frequency noise in the image can be filtered, and compression quality is better ensured.
In an optional implementation manner, filtering data greater than a preset frequency threshold in the quantization matrix by using a plurality of filter matrices with different sizes to obtain a target quantization matrix corresponding to the first image block, including:
Sequencing a plurality of filter matrixes according to the size of each filter matrix, and determining the filtering sequence of each filter matrix;
carrying out weight normalization operation on each filter matrix to obtain normalized filter weight matrixes corresponding to each filter matrix respectively;
and performing progressive filtering operation on the initial quantization matrix, and performing progressive filtering operation on the initial quantization matrix by utilizing each normalized filtering weight matrix according to a filtering sequence and a preset frequency threshold value to obtain a target quantization matrix.
Through the mode, progressive filtering operation can be carried out on the quantization matrix by using a plurality of filters, noise information in an image can be better filtered, and the filtering matrix is subjected to weight normalization processing, so that the gradient amplification problem of the filter is reduced.
In an optional implementation manner, the weight normalization operation is performed on each filter matrix, so as to obtain normalized filter weight matrixes corresponding to each filter matrix, and the method further includes:
acquiring Gaussian distribution standard deviations corresponding to each filtering matrix respectively;
determining a first weight matrix corresponding to a first filter matrix according to index data of a central point of the first filter matrix, index data of each matrix element in an initial quantization matrix and Gaussian distribution standard deviation, wherein the first filter matrix is any one of a plurality of filter matrices with different sizes;
And carrying out normalization processing on the weight matrix to obtain a first normalized filtering weight matrix corresponding to the first filtering matrix.
In an optional implementation manner, according to index data of a center point of the first filtering matrix, index data of each matrix element in the initial quantization matrix, and gaussian distribution standard deviation, a first weight matrix corresponding to the first filtering matrix is determined, which is specifically implemented in the following manner:
wherein,index data for each matrix element corresponding to the initial quantization matrix, respectively +.>For the first weight matrix,/a>Index data of the center points of the first filter matrix, respectively,>and the standard deviation of the Gaussian distribution corresponding to the first filtering matrix.
In an optional implementation manner, normalization processing is performed on the weight matrix to obtain a first normalized filtering weight matrix corresponding to the first filtering matrix, which is specifically implemented in the following manner:
wherein,for the first weight matrix,/a>For the first normalized filter weight matrix, +.>Is the sum of all elements in the first weight matrix.
In an alternative embodiment, performing progressive filtering operation on the initial quantization matrix according to the filtering sequence by using each normalized filtering weight matrix according to the filtering sequence, to obtain a target quantization matrix, including:
Determining a current normalized filtering weight matrix according to the filtering sequence, and filtering a current quantization matrix by using the current normalized filtering weight matrix to obtain a first filtering quantization matrix, wherein the current quantization matrix is a quantization matrix corresponding to the current normalized filtering weight matrix;
determining a next normalized filtering weight matrix according to the filtering sequence, and filtering the first filtering quantization matrix by using the next normalized filtering weight matrix to obtain a second filtering quantization matrix;
and obtaining a target quantization matrix after determining that all the normalized filtering weight matrixes finish filtering operation.
Through the mode, the filtering sequence of the normalized filtering weight matrix can be set, the normalized filtering weight matrix is used for filtering the quantization matrix for the first time in sequence, the filtering result is obtained, the filtering result obtained last time is filtered by using the next filtering matrix, high-frequency filtering can be carried out in a multi-level mode, and the filtering effect is better than that of filtering by using a single filter, wherein the filtering effect is equivalent to that of carrying out layer-by-layer 'sieving' on the quantization matrix.
In an alternative embodiment, determining a current normalized filtering weight matrix according to a filtering sequence, and filtering the current quantization matrix by using the current normalized filtering weight matrix to obtain a first filtered quantization matrix, including:
Aligning the center point of the current normalized filtering weight matrix with a first element in the current quantization matrix, wherein the first element is any element in the quantization matrix;
determining a target element value of the first element according to the element value of each element in the current quantization matrix and the element value of the element at the corresponding position of the current normalized filtering weight matrix;
and constructing a first filtering quantization matrix by using target element values of all elements.
In an alternative embodiment, a current normalized filtering weight matrix is determined according to a filtering sequence, and the current quantization matrix is filtered by using the current normalized filtering weight matrix, so as to obtain a first filtering quantization matrix, which is specifically implemented by the following formula:
wherein,representing the position coordinates of the elements in the quantization matrix, +.>Representing the position coordinates of the first element,a target element value representing the first element, +.>Representing the weights of the current normalized filter weight matrix,representing the position coordinates as +.>M is the number of rows of the quantization matrix, N is the number of columns of the quantization matrix,/>Representing a convolution operation.
In an alternative embodiment, the filter matrix is at least two of the following:
A 3 by 3 dimensional matrix, a 4 by 4 dimensional matrix, a 5 by 5 dimensional matrix, and a 7 by 7 dimensional matrix.
Through the mode, the filter matrixes are different in size and smaller in size difference, not only can have different filter effects, but also can keep certain filter density, and the filter effect is better.
In an alternative embodiment, determining, with the main process, the target number of tiles of the first image to be compressed includes:
acquiring the height and width of a first image to be compressed and a preset block size by using a main process;
and determining the number of the target blocks according to the height, the width and the preset block size.
In an alternative embodiment, the preset block size includes a row width and a column height of the blocks, and determining the target number of blocks according to the height, the width, and the preset number of blocks includes:
determining the column number of the blocks according to the height and the column height;
determining the number of rows of the blocks according to the width and the line width;
and determining the number of the target blocks according to the number of columns and the number of rows.
In a second aspect, the present invention provides an image compression apparatus comprising:
the acquisition module is used for acquiring an image compression instruction and at least one image to be compressed;
the first creation module is used for creating a main process based on the image compression instruction;
The determining module is used for determining the target block number of the first image to be compressed by utilizing the main process, wherein the first image to be compressed is any image to be compressed;
the second creation module is used for creating a first group of sub-processes and a second group of sub-processes with the number corresponding to the number of the target blocks by using the main process;
the extraction module is used for respectively extracting an image block from the first image to be compressed by utilizing each subprocess in the first group of subprocesses and acquiring the combination sequence of each image block in the first image to be compressed;
the image compression module is used for respectively carrying out image compression processing on one image block by utilizing each subprocess in the second group of subprocesses to obtain compressed image blocks respectively corresponding to each image block;
and the generation module is used for combining all the compressed image blocks according to the combination sequence of each image block in the first image to be compressed by using the main process to generate a compressed image corresponding to the first image to be compressed.
In a third aspect, the present invention provides a computer device comprising: the image compression device comprises a memory and a processor, wherein the memory and the processor are in communication connection, the memory stores computer instructions, and the processor executes the computer instructions, so that the image compression method of the first aspect or any implementation mode corresponding to the first aspect is executed.
In a fourth aspect, the present invention provides a computer-readable storage medium having stored thereon computer instructions for causing a computer to perform the image compression method of the first aspect or any of its corresponding embodiments.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are needed in the description of the embodiments or the prior art will be briefly described, and it is obvious that the drawings in the description below are some embodiments of the present invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flow chart of an image compression method according to an embodiment of the present invention;
FIG. 2 is a flow chart of a method of determining compression order of image blocks according to an embodiment of the present invention;
FIG. 3 is a flow chart of a method for obtaining a first compressed image block corresponding to a first image block according to an embodiment of the present invention;
FIG. 4 is a flow chart of another image compression method according to an embodiment of the present invention;
fig. 5 is a flow diagram of a parallel image compression method according to an embodiment of the present invention;
Fig. 6 is a block diagram of a structure of an image compression apparatus according to an embodiment of the present invention;
fig. 7 is a schematic diagram of a hardware structure of a computer device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Image compression is an important trend in the development of information technology nowadays, and image and video compression technologies related to the image compression are widely applied to consumer electronic products. With the rapid development of information processing and the increasing storage and transmission capabilities of data, it is becoming increasingly important to develop high resolution, high definition image compression algorithms.
Because of factors such as larger image size or higher resolution, the image may face some challenges in the process of transmission, storage and processing, such as difficulty in meeting the requirements of real-time performance or storage space, the image data is usually required to be compressed first, and the data volume of the image attribute values can be effectively reduced through image compression, so that the time and space complexity of image processing and digital analysis is reduced. Among the conventional image compression methods, JPEG is the most effective image compression method, which can compress images very little, is the most widely used image format at present, and the internal high-efficiency discrete cosine transform (Discrete Cosine Transform, abbreviated as DCT) algorithm is the key for realizing large-scale distribution of digital images and digital photos. However, the existing JPEG encoding method cannot meet the compression requirement of a large-scale test image, in the compression process, the image is divided into 8×8 small blocks, DCT conversion is performed on each small block, quantization and encoding are performed, and finally all encoded data are spliced together to form a JPEG file. For massive experimental graphs, the operation amount is large, and the real-time performance is difficult to ensure, so that a new method capable of rapidly compressing images is necessary to be researched so as to improve the calculation efficiency.
Based on this, according to an embodiment of the present invention, there is provided an image compression method embodiment, it being noted that the steps shown in the flowcharts of the drawings may be performed in a computer system such as a set of computer executable instructions, and that although a logical order is shown in the flowcharts, in some cases the steps shown or described may be performed in an order different from that herein.
In this embodiment, an image compression method is provided, which may be used in the above-mentioned computer device, such as a mobile phone, a computer, etc., fig. 1 is a flowchart of an image compression method according to an embodiment of the present invention, and as shown in fig. 1, the flowchart includes the following steps:
step S101, an image compression instruction and at least one image to be compressed are acquired.
Specifically, the image compression instruction may be in the form of a request or in the form of a command line, and may be specific to the actual situation.
Step S102, creating a main process based on the image compression instruction.
Specifically, for example, the main process may be initialized based on the image compression instruction, and when the main process is initialized, all image files that need to be compressed are loaded and added to the task queue.
Step S103, determining the target block number of the first image to be compressed by using the main process.
Specifically, the first image to be compressed is any one of the images to be compressed. And acquiring the size of the image to be compressed by using the main process, and determining the target block number of the image to be compressed according to the size of the image to be compressed and the preset block size.
In an alternative example, the image to be compressed is for example of sizePixels, preset block size isThe number of target tiles is 16 tiles.
In another alternative example, the image to be compressed is of a size of, for examplePixels, preset block size +.>The number of target blocks is 20 blocks, wherein 4 image blocks are less than +.>The pixels may be directly processed for the image block, or some filling modes may be selected to fill the image block with pixel data of insufficient size, for example, average mode or filling 0, etcThe specific filling manner may be determined according to practical situations, and is not limited herein.
Step S104, a first group of sub-processes and a second group of sub-processes with the number corresponding to the target block number are created by the main process.
Specifically, a first group of sub-processes and a second group of sub-processes, the number of which corresponds to the number of target blocks, are created by using the main process, and multiple groups of sub-processes corresponding to the respective processing processes can be created according to the respective processing processes in the image compression operation, for example, the first group of sub-processes can be used for blocking an image to be compressed, and the second group of sub-processes can be used for performing image compression on each image block, and the like.
In step S105, each sub-process in the first set of sub-processes is used to extract a block of image blocks from the first image to be compressed, so as to obtain a combination sequence of each image block in the first image to be compressed.
Specifically, a main process may be used to allocate a block of image blocks to each sub-process, and then each sub-process in the first set of sub-processes may be used to extract the block of image from the first image to be compressed.
In an alternative example, the extraction order of the image blocks may be regarded as the combination order of the image blocks in the first image to be compressed.
In another alternative example, the order of combination of each image block may be set in the image to be compressed, and each sub-process in the first set of sub-processes acquires the order of combination of the image blocks when the image blocks are extracted.
And S106, respectively carrying out image compression processing on one image block by utilizing each subprocess in the second group of subprocesses to obtain compressed image blocks respectively corresponding to each image block.
Specifically, a main process can be utilized to allocate an image block for each sub-process in the second group of sub-processes, then each sub-process in the second group of sub-processes is utilized to perform image compression processing on the allocated image blocks respectively, and compressed image blocks corresponding to each image block are obtained.
In step S107, all the compressed image blocks are combined by the main process according to the combination sequence of each image block in the first image to be compressed, so as to generate a compressed image corresponding to the first image to be compressed.
Specifically, a main process is utilized to acquire a combination sequence of each compressed image block, and each image block of the image to be compressed is spliced according to the combination sequence to generate a compressed image corresponding to the first image to be compressed.
In an alternative example, if some image blocks are subjected to data filling processing, filling data needs to be deleted during stitching, so that the reduction degree of the compressed image can be better ensured.
According to the image compression method provided by the embodiment, an image compression instruction and at least one image to be compressed are acquired; creating a main process based on the image compression instruction; determining the target block number of a first image to be compressed by using a main process, wherein the first image to be compressed is any image to be compressed; creating a first group of sub-processes and a second group of sub-processes with the number corresponding to the number of the target blocks by using the main process; extracting an image block from the first image to be compressed by using each subprocess in the first group of subprocesses respectively, and obtaining the combination sequence of each image block in the first image to be compressed respectively; respectively carrying out image compression processing on an image block by utilizing each subprocess in the second group of subprocesses to obtain compressed image blocks respectively corresponding to each image block; and combining all the compressed image blocks by using a main process according to the combination sequence of each image block in the first image to be compressed respectively to generate a compressed image corresponding to the first image to be compressed. In the method, when the images are compressed, a main process is created to carry out the operation of the block number on each image, a sub-process with the same block number is created by using the main process, and the sub-processes for processing the corresponding tasks are created according to different compression tasks in the compression process, when the compression tasks of different image blocks of the same image are processed, the image compression operation of each sub-process can be synchronously carried out, the efficiency of the whole image compression is greatly improved, the later image classification and identification, the image transmission and the like are also facilitated, the method is particularly suitable for compression requirement scenes of massive images, and the compression efficiency can be greatly improved, so the value of the method in the compression aspect is self-evident.
In an alternative embodiment, step S105 includes the method steps shown in fig. 2:
in step S201, a starting extraction position of an image block is allocated to each sub-process in the first set of sub-processes by using the main process.
Specifically, the initial extraction position of each image block is determined according to the preset block size and the target block number.
In an alternative example, for example, the predetermined size isIf the pixels are segmented from left to right and from top to bottom, the initial extraction position of the first image block is the first pixel at the upper left corner, the initial of the second image block is the 9 th pixel of the first row, when the first row is divided, the 1 st pixel of the 9 th row is used as the initial extraction position of the next image block, and the like, the initial extraction position of each image block is determined, and the initial extraction position of each image block is the initial extraction position of the corresponding sub-process.
Step S202, using the first sub-process to traverse pixels of the first image to be compressed according to a preset block size from a start extraction position corresponding to the first sub-process, and obtaining a first image block and an extraction sequence of the first image block.
Specifically, the first sub-process is any one of the first group of sub-processes, and the first image block is an image block extracted by the first sub-process. Traversing pixels in the image to be compressed according to a preset direction from a starting extraction position corresponding to the first subprocess by utilizing the first subprocess, extracting pixels with preset block sizes to form a first image block, and extracting the first image block in sequence.
In an alternative example, the first sub-process may send an extraction completion signal to the main process after the extraction of the image block is completed, and the main process may determine the extraction completion order of each sub-process according to the order in which the extraction completion signals are received, that is, determine the extraction order of the image block corresponding to each sub-process.
In an alternative embodiment, the first sub-process is configured to perform a row traversing operation and a column traversing operation, where step S202 includes:
and a step a1, starting from a first initial extraction position, and respectively performing row traversing operation and column traversing operation on pixels of a first image to be compressed by taking a preset block size as a reference to acquire a first image block.
Specifically, the first initial extraction position is an initial extraction position corresponding to the first sub-process. Two traversal programs, namely row traversal and column traversal, can be created by using the main process, the sub-process executes row traversal operation and column traversal operation, and when a first image block is acquired, the row traversal operation and the column traversal operation are respectively performed on pixels of a first image to be compressed by taking a preset block size as a reference from a first initial extraction position.
In an alternative example, for example, the block size is preset to be Each sub-process starts from a corresponding initial extraction position, traverses pixels of an image to be compressed according to rows, and iterates with 8 row step sizes; and simultaneously, traversing pixels of the image to be compressed according to columns from the corresponding initial extraction positions, and iterating with 8 columns as step sizes to obtain image blocks corresponding to each subprocess respectively.
And a step a2, taking the sequence of extracting the first image blocks as the extraction sequence of the first image blocks.
Step S203 takes the extraction order of the first image block as the corresponding combination order of the first image block in the first image to be compressed.
Specifically, the extraction sequence of the first image block is used as the corresponding combination sequence of the first image block in the first image to be compressed, so that after all image blocks of the first image to be compressed are respectively compressed, splicing is performed according to the combination sequence to generate a compressed image of the first image to be compressed.
In an alternative embodiment, after step S202, the method further includes:
and b1, storing the image blocks in a preset shared data structure according to the combination sequence.
In particular, the preset shared data structure may be a list created by the host process for storing image blocks.
And b2, after confirming that all the image blocks are stored in the preset shared data structure, generating identification information corresponding to each image block according to the combination sequence.
Specifically, after confirming that all the image blocks are stored in the preset shared data structure, corresponding identification information, for example, identifiers 1 to n, is generated for each image block according to the combination sequence of the image blocks.
In an alternative embodiment, after step b1, the method further includes:
a storage complete signal is sent to the main process using the first sub-process.
Specifically, the storage completion signal is used to indicate that the first sub-process is an idle process. After the first subprocess stores the image block into a preset shared data structure, a storage completion signal can be sent to the main process, the main process can list the subprocess into an idle process queue after receiving the storage completion signal, and when a new task exists, the idle subprocess can be immediately called for processing.
After the image to be compressed is segmented, in order to ensure the compression rate, the compression process may be performed for each image block in synchronization.
In an alternative embodiment, step S106 includes:
And performing image compression processing on the first image block by using a second subprocess in the second group of subprocesses to obtain a compressed image block corresponding to the first image block.
Specifically, the second sub-process is any one of the second group of sub-processes, and the main process may allocate an image block to each of the second group of sub-processes, and the sub-processes synchronously perform image compression processing after obtaining the image block. The image compression processing is performed on the first image block, so as to obtain a compressed image block corresponding to the first image block, which specifically includes the method steps shown in fig. 3:
step S301, performing encoding operation on the first image block to obtain a frequency domain information matrix corresponding to the first image block.
Specifically, the first image block is subjected to coding operation, such as DCT transformation, so as to obtain a frequency domain information matrix corresponding to the first image block.
Step S302, carrying out quantization operation on the frequency domain information matrix to obtain an initial quantization matrix corresponding to the first image block.
Specifically, the quantization operation is performed on the frequency domain information matrix obtained in step S302, that is, the coefficient matrix obtained by performing DCT transformation on the first image block.
In an alternative example, a default quantization matrix in the JPEG standard may be used to quantize the frequency domain information matrix, where the default quantization matrix ensures compression quality while ensuring compression ratio.
Step S303, filtering operation is carried out on the initial quantization matrix, and a target quantization matrix corresponding to the first image block is obtained.
Specifically, if the image to be compressed is an original image acquired by a camera or the like, there may be more high-frequency noise, so that a filtering operation needs to be performed on the quantization matrix, for example, a gaussian low-pass filter may be used to perform a filtering operation on the quantization matrix, and the high-frequency component is filtered out, so as to obtain the target quantization matrix.
In an alternative embodiment, filtering the initial quantization matrix to obtain a target quantization matrix corresponding to the first image block includes:
and filtering the data which are larger than the preset frequency threshold value in the quantization matrix by utilizing a plurality of filter matrixes with different sizes, and obtaining a target quantization matrix corresponding to the first image block.
Specifically, a preset frequency threshold may be set, and data in the quantization matrix greater than the preset frequency threshold is filtered to obtain a target quantization matrix corresponding to the first image block.
Step S304, performing inverse quantization operation on the target quantization matrix to obtain a first compressed image block corresponding to the first image block.
Specifically, since the compressed image blocks need to be sequentially restored to complete final stitching, so as to obtain a compressed image, but the target quantization matrix is not pixel data, and cannot be restored, the target quantization matrix needs to be subjected to inverse quantization operation, and if the first image block is subjected to DCT transformation in the previous step, the inverse discrete cosine transform (inverse Discrete Cosine Transformation, abbreviated as IDCT) operation is also required to be performed on the inversely quantized coefficients, so as to obtain the compressed image block.
In an optional implementation manner, filtering data greater than a preset frequency threshold in the quantization matrix by using a plurality of filter matrices with different sizes to obtain a target quantization matrix corresponding to the first image block, including:
and c1, sequencing a plurality of filter matrixes according to the size of each filter matrix, and determining the filtering sequence of each filter matrix.
Specifically, for example, the filtering sequence of each filtering matrix may be determined according to the order of the sizes of the filtering matrices from small to large.
And c2, carrying out weight normalization operation on each filter matrix to obtain normalized filter weight matrixes corresponding to each filter matrix respectively.
Specifically, weight normalization operation is performed on each filter matrix, and a normalized filter weight matrix corresponding to each filter matrix is obtained.
In an optional implementation manner, performing a weight normalization operation on each filter matrix to obtain a normalized filter weight matrix corresponding to each filter matrix, where the normalized filter weight matrix includes:
and c11, acquiring Gaussian distribution standard deviations corresponding to each filtering matrix respectively.
Specifically, in an alternative example, four gaussian low pass filters of different sizes (the filters are embodied in a matrix) may be utilized, one each 、/>、/>And->A standard deviation of the gaussian distribution, i.e. the standard deviation of the gaussian function, can be set for each filter, e.g.)>Is a Gaussian distribution standard deviation;/>Is of standard deviation of Gaussian distribution +.>Is of standard deviation of Gaussian distribution +.>Is of standard deviation of Gaussian distribution +.>
Step c12, determining a first weight matrix corresponding to the first filter matrix according to the index data of the center point of the first filter matrix, the index data of each matrix element in the initial quantization matrix and the Gaussian distribution standard deviation.
Specifically, the first filter matrix is any one of a plurality of filter matrices with different sizes.
In an optional implementation manner, according to index data of a center point of the first filtering matrix, index data of each matrix element in the initial quantization matrix, and gaussian distribution standard deviation, a first weight matrix corresponding to the first filtering matrix is determined, which is specifically implemented in the following manner:
/>
wherein,index data for each matrix element corresponding to the initial quantization matrix, respectively +.>For the first weight matrix,/a>Index data of the center points of the first filter matrix, respectively,>and the standard deviation of the Gaussian distribution corresponding to the first filtering matrix.
And step c13, carrying out normalization processing on the weight matrix, wherein the first normalized filter weight matrix corresponds to the first filter matrix.
Specifically, the weights of the first filter matrix are normalized, for example, batch normalization or gradient normalization may be adopted, and normalization is performed on the weights of the first filter matrix to obtain normalized weights.
In an optional implementation manner, the normalization processing is performed on the weight matrix, and the first normalization filtering weight matrix corresponding to the first filtering matrix is specifically implemented by the following manner:
wherein,for the first weight matrix,/a>For the first normalized filter weight matrix, +.>Is the sum of all elements in the first weight matrix.
And c3, performing progressive filtering operation on the initial quantization matrix by using each normalized filtering weight matrix according to the filtering sequence and a preset frequency threshold value, and obtaining a target quantization matrix.
Specifically, the filter matrixes are subjected to progressive filtering operation according to a filtering sequence and a preset filtering threshold, namely, after the last filter matrix is filtered, the next filter matrix filters the filtered result of the last filter matrix until all the filter matrixes are filtered to obtain a target quantization matrix.
In an alternative embodiment, the step c3 specifically includes:
and c31, determining a current normalized filtering weight matrix according to the filtering sequence, and filtering the current quantization matrix by using the current normalized filtering weight matrix to obtain a first filtering quantization matrix, wherein the current quantization matrix is a quantization matrix corresponding to the current normalized filtering weight matrix.
Specifically, when the current normalized filtering weight matrix is the first normalized filtering weight matrix, the current quantization matrix is a quantization matrix obtained through quantization operation, and when the current normalized filtering weight matrix is not the first normalized filtering weight matrix, the current quantization matrix is a filtering result of the last filtering matrix, the current normalized filtering weight matrix is determined according to the filtering sequence, and the current quantization matrix is filtered by the current normalized filtering weight matrix to obtain the first filtering quantization matrix.
In an alternative embodiment, step c31 specifically includes:
step c311, aligning the center point of the current normalized filtering weight matrix with the first element in the current quantization matrix.
Step c312, determining the target element value of the first element according to the element value of each element in the current quantization matrix and the element value of the element at the corresponding position of the current normalized filtering weight matrix.
Specifically, the first element is any element in the quantization matrix.
In an alternative example, the center point of the current normalized filter weight matrix may be aligned with each element in the current quantization matrix, and a weighted average of each element in the filter matrix and the first element of the current quantization matrix may be calculated as the target element value of the first element.
Step c313, constructing a first filtering quantization matrix by using the target element values of all the elements.
Specifically, each element in the current quantization matrix is traversed by using the current normalized filtering weight matrix, the target element value corresponding to each element is calculated respectively, and the first filtering quantization matrix is constructed by using the target element values of all the elements.
And c32, determining a next normalized filtering weight matrix according to the filtering sequence, and filtering the first filtering quantization matrix by using the next normalized filtering weight matrix to obtain a second filtering quantization matrix.
And c33, obtaining a target quantization matrix after determining that all the normalized filter weight matrices finish the filtering operation.
Specifically, after the current normalized filtering weight matrix filters the current quantization matrix, determining a next normalized filtering weight matrix according to a filtering sequence, and filtering a filtered result of the current normalized filtering weight matrix again until all normalized filtering weight matrices complete filtering operation, thereby obtaining a target quantization matrix.
In an alternative example, there are fourA filter matrix of the size of、/>、/>And->Ordering from small to large according to the size, firstly using weight normalized +.>Filtering the initial quantization matrix to obtain output result, and re-using +.>Is->Filtering the filtered result of the filtering matrix, and the like until the filtering matrix after the four weight normalization is filtered, so as to obtain the target quantization matrix.
In an alternative example, the initial quantization matrices obtained in step S302 may be filtered by using 4 filter matrices, to obtain filtered matrices output by the 4 filter matrices, respectively, and the target element value of each corresponding position in the 4 matrices is calculated according to the element of the position, and the target quantization matrix is constructed according to all the element values, for example, the target element value of each position is determined by using a mean value or a variance.
In an alternative embodiment, a current normalized filtering weight matrix is determined according to a filtering sequence, and the current quantization matrix is filtered by using the current normalized filtering weight matrix, so as to obtain a first filtering quantization matrix, which is specifically implemented by the following formula:
Wherein,representing the position coordinates of the elements in the quantization matrix, +.>Representing the position coordinates of the first element,a target element value representing the first element, +.>Representing the weights of the current normalized filter weight matrix,representing the position coordinates as +.>M is the number of rows of the quantization matrix, N is the number of columns of the quantization matrix,/>Representing a convolution operation.
In an alternative embodiment, determining, with the main process, the target number of tiles of the first image to be compressed includes:
and d1, acquiring the height and width of the first image to be compressed and the preset block size by using a main process.
And d2, determining the number of target blocks according to the height, the width and the preset block size.
Specifically, the main process is utilized to obtain the height and width of the first image to be compressed, for example, the width is W, the height is H, and the preset block size isAnd determining the target block number according to the height, the width and the preset block size.
In an alternative embodiment, the preset block size includes a row width and a column height of the block, and the step d2 includes:
and d21, determining the column number of the blocks according to the height and the column height.
Step d22, determining the number of rows of the blocks according to the width and the row width.
Step d23, determining the number of target blocks according to the number of columns and the number of rows.
Specifically, for example, the preset block size isThe line width is 8, the column height is 8, and the line numbers of the first image to be compressed can be obtained by taking pixels as units according to the following formula:
where R is the number of lines of the first image to be compressed, H is the column height in the preset block size, ceil () is the rounding up function.
The number of columns of the image to be compressed can be obtained by the following formula:
wherein, C is the number of columns of the first image to be compressed, W is the line width in the preset block size, ceil () is the upward rounding function.
According to the number of columns and the number of rows, the number of target blocks is determined, and the method is realized in the following manner:
wherein num is the target block number of the first image to be compressed, R is the column number of the first image to be compressed, and C is the line number of the first image to be compressed.
As a specific application embodiment of the present invention, for example, in a specific parallel fast image compression processing method, as shown in FIG. 4, the original is calculatedThe number of blocks of the image, and creating a block sub-process and an image block compression sub-process that are greater than or equal to the number of blocks, using each block sub-process to The original image is divided into blocks in parallel by the size of the (d) and the image process is coded in parallel (DCT) by utilizing the image compression subprocess to obtain +.>The frequency domain information matrix of the dimension is quantized in parallel (divided by a preset quantization factor) to obtain the corresponding +/of each image block>The dimension quantization matrix is subjected to multi-level filtering operation through a plurality of Gaussian low-pass filters with different sizes, so that a target quantization matrix of each image block is obtained, and the size of each target quantization matrix is +.>And performing IDCT transformation on the target quantization matrix to obtain compressed image blocks of each image block, and then splicing the compressed image blocks according to the combination sequence when the images are segmented to obtain a complete compressed image.
Parallel processing as shown in fig. 5, when an image compression instruction is acquired, the main process creates a process pool including a plurality of sub-processes, and specifies the number of processes to be used: sub-process 1, sub-process 2, sub-process 3 … sub-process n, each process compresses the respective image block according to the designated function (including image processing logic), for example, sub-process 1 processes the image block with identifier 1, sub-process 2 processes the image block with identifier 2, so as to push, sub-process n processes the image block with identifier n to obtain the processing result of each image block, result 1, result 2, result 3 to result n respectively, and store the processing result into the result list, and the main process splices the image blocks in the list into a complete image.
In order to verify the effectiveness of the method, we have performed compression comparison experiments of the invention with the conventional two image compression methods PNG and JPEG on the same computer. The test images used the standard test image disclosed (image size 768×512) and the sliding iron prospecting database Waterloo Exploration Database (image size 572×351), and compared to two commonly used image compression methods, PNG and JPEG. The specific comparison results are shown in Table 1. In this experiment, PNG compression algorithm has the characteristics of higher image quality and lossless compression, but compression takes the longest time, and the compressed image size is larger than the original image, which is unfavorable for storage. In contrast, the algorithm of the invention is slightly inferior to JPEG in terms of compression Ratio, but is still acceptable, and meanwhile, the compression time is shorter, and Peak Signal-to-Noise Ratio (PSNR) and structural similarity (Structural Similarity, SSIM) indexes have certain advantages relative to JPEG. It can be seen that the algorithm provided by the invention can greatly save time when compressing massive experimental images.
TABLE 1
The present embodiment also provides an image compression device, which is used to implement the foregoing embodiments and preferred embodiments, and is not described in detail. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. While the means described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and contemplated.
The present embodiment provides an image compression apparatus, as shown in fig. 6, including:
an acquiring module 601, configured to acquire an image compression instruction and at least one image to be compressed;
a first creation module 602, configured to create a main process based on the image compression instruction;
a determining module 603, configured to determine, by using a main process, a target block number of a first image to be compressed, where the first image to be compressed is any one image to be compressed;
a second creating module 604, configured to create, with the main process, a first set of sub-processes and a second set of sub-processes having numbers corresponding to the number of target blocks;
an extracting module 605, configured to extract an image block from the first image to be compressed by using each sub-process in the first set of sub-processes, and obtain a combination sequence of each image block in the first image to be compressed;
the image compression module 606 is configured to perform image compression processing on an image block by using each sub-process in the second set of sub-processes, so as to obtain compressed image blocks corresponding to each image block respectively;
the first generation module 607 is configured to combine all the compressed image blocks according to the combination sequence of each image block in the first image to be compressed by using the main process, so as to generate a compressed image corresponding to the first image to be compressed.
In an alternative embodiment, the extraction module 605 includes:
the distribution unit is used for distributing the initial extraction position of the image block to each sub-process in the first group of sub-processes by utilizing the main process, wherein the initial extraction position of each image block is determined according to the preset block size and the target block number;
the traversal unit is used for traversing pixels of the first image to be compressed according to a preset block size from a starting extraction position corresponding to the first subprocess by using the first subprocess to obtain a first image block and an extraction sequence of the first image block, wherein the first subprocess is any subprocess in the first group of subprocesses, and the first image block is an image block extracted by the first subprocess; the extraction order of the first image blocks is taken as the corresponding combination order of the first image blocks in the first image to be compressed.
In an alternative embodiment, the first sub-process is configured to perform a row traversing operation and a column traversing operation, and the traversing unit is specifically configured to:
starting from a first initial extraction position, performing row traversing operation and column traversing operation on pixels of a first image to be compressed respectively by taking a preset block size as a reference, and obtaining a first image block, wherein the first initial extraction position is an initial extraction position corresponding to a first subprocess;
The order in which the first image blocks are extracted is taken as the extraction order of the first image blocks.
In an alternative embodiment, the apparatus further comprises:
a storage module 608, configured to store the image blocks in a preset shared data structure according to a combination sequence;
the second generating module 609 is configured to generate, according to the combination sequence, identification information corresponding to each image block after confirming that all the image blocks are stored in the preset shared data structure.
In an alternative embodiment, the apparatus further comprises:
and a sending module 610, configured to send a storage completion signal to the main process by using the first sub-process, where the storage completion signal is used to indicate that the first sub-process is an idle process.
In an alternative embodiment, image compression module 606 includes:
the image compression unit is configured to perform image compression processing on the first image block by using a second sub-process in the second group of sub-processes to obtain a compressed image block corresponding to the first image block, where the second sub-process is any one of the second group of sub-processes, perform image compression processing on the first image block, and obtain a compressed image block corresponding to the first image block, and specifically includes:
The coding unit is used for carrying out coding operation on the first image block and obtaining a frequency domain information matrix corresponding to the first image block;
the quantization unit is used for carrying out quantization operation on the frequency domain information matrix to obtain an initial quantization matrix corresponding to the first image block;
the filtering unit is used for performing filtering operation on the initial quantization matrix to obtain a target quantization matrix corresponding to the first image block;
and the inverse quantization unit is used for performing inverse quantization operation on the target quantization matrix to obtain a first compressed image block corresponding to the first image block.
In an alternative embodiment, the filtering unit comprises:
the first filtering subunit is configured to filter data greater than a preset frequency threshold in the initial quantization matrix by using a plurality of filtering matrices with different sizes, so as to obtain a target quantization matrix corresponding to the first image block.
In an alternative embodiment, the filtering subunit comprises:
the sorting subunit is used for sorting the plurality of filter matrixes according to the size of each filter matrix and determining the filtering sequence of each filter matrix;
the weight normalization subunit is used for carrying out weight normalization operation on each filter matrix to obtain normalized filter weight matrixes corresponding to each filter matrix respectively;
And the progressive filtering subunit is used for performing progressive filtering operation on the initial quantization matrix by utilizing each normalized filtering weight matrix according to the filtering sequence and a preset frequency threshold value to obtain a target quantization matrix.
In an alternative embodiment, the weight normalization subunit is specifically configured to:
the acquisition subunit is used for acquiring the Gaussian distribution standard deviation corresponding to each filtering matrix respectively;
the first determination subunit is configured to determine a first weight matrix corresponding to the first filtering matrix according to index data of a center point of the first filtering matrix, index data of each matrix element in the initial quantization matrix, and a gaussian distribution standard deviation, where the first filtering matrix is any one of a plurality of filtering matrices with different sizes;
and the normalization subunit is used for carrying out normalization processing on the weight matrix to obtain a first normalized filtering weight matrix corresponding to the first filtering matrix.
In an alternative embodiment, the determination of the subunit is achieved in particular by:
/>
wherein,index data for each matrix element corresponding to the initial quantization matrix, respectively +.>For the first weight matrix,/a >Index data of the center points of the first filter matrix, respectively,>and the standard deviation of the Gaussian distribution corresponding to the first filtering matrix.
In an alternative embodiment, the normalization subunit is implemented in particular by:
wherein,for the first weight matrix,/a>For the first normalized filter weight matrix, +.>Is the sum of all elements in the first weight matrix.
In an alternative embodiment, the progressive filtering subunit comprises:
the second filtering subunit is used for determining a current normalized filtering weight matrix according to the filtering sequence, and filtering the current quantization matrix by using the current normalized filtering weight matrix to obtain a first filtering quantization matrix, wherein the current quantization matrix is a quantization matrix corresponding to the current normalized filtering weight matrix;
the third filtering subunit determines a next normalized filtering weight matrix according to the filtering sequence, and filters the first filtering quantization matrix by using the next normalized filtering weight matrix to obtain a second filtering quantization matrix;
and the second determination subunit is used for obtaining the target quantization matrix after determining that all the normalized filter weight matrices finish the filtering operation.
In an alternative embodiment, the second filtering subunit comprises:
an alignment subunit, configured to align a center point of a current normalized filtering weight matrix with a first element in a current quantization matrix, where the first element is any element in the quantization matrix;
a third determining subunit, configured to determine a target element value of the first element according to an element value of each element in the current quantization matrix and an element value of an element at a position corresponding to the current normalized filtering weight matrix;
a construction subunit for constructing a first filtered quantization matrix using the target element values of all elements.
In an alternative embodiment, the second filtering subunit is implemented in particular by:
wherein,representing the position coordinates of the elements in the quantization matrix, +.>Representing the position coordinates of the first element,a target element value representing the first element, +.>Representing the weights of the current normalized filter weight matrix,representing the position coordinates as +.>M is the number of rows of the quantization matrix, N is the number of columns of the quantization matrix,/>Representing a convolution operation.
In an alternative embodiment, the filter matrix in the first filter subunit is at least two of the following:
A 3 by 3 dimensional matrix, a 4 by 4 dimensional matrix, a 5 by 5 dimensional matrix, and a 7 by 7 dimensional matrix.
In an alternative embodiment, the determining module 603 includes:
the second acquisition subunit is used for acquiring the height and the width of the first image to be compressed and the preset block size by utilizing the main process;
and the determining unit is used for determining the target block number according to the height, the width and the preset block size.
In an alternative embodiment, the fourth determining unit is specifically configured to: determining the column number of the blocks according to the height and the column height; determining the number of rows of the blocks according to the width and the line width; and determining the number of the target blocks according to the number of columns and the number of rows.
Further functional descriptions of the above respective modules and units are the same as those of the above corresponding embodiments, and are not repeated here.
The image compression apparatus in this embodiment is presented in the form of functional units, where the units refer to ASIC (Application Specific Integrated Circuit ) circuits, processors and memories executing one or more software or fixed programs, and/or other devices that can provide the above described functions.
The embodiment of the invention also provides computer equipment, which is provided with the image compression device shown in the figure 6.
Referring to fig. 7, fig. 7 is a schematic structural diagram of a computer device according to an alternative embodiment of the present invention, as shown in fig. 7, the computer device includes: one or more processors 10, memory 20, and interfaces for connecting the various components, including high-speed interfaces and low-speed interfaces. The various components are communicatively coupled to each other using different buses and may be mounted on a common motherboard or in other manners as desired. The processor may process instructions executing within the computer device, including instructions stored in or on memory to display graphical information of the GUI on an external input/output device, such as a display device coupled to the interface. In some alternative embodiments, multiple processors and/or multiple buses may be used, if desired, along with multiple memories and multiple memories. Also, multiple computer devices may be connected, each providing a portion of the necessary operations (e.g., as a server array, a set of blade servers, or a multiprocessor system). One processor 10 is illustrated in fig. 7.
The processor 10 may be a central processor, a network processor, or a combination thereof. The processor 10 may further include a hardware chip, among others. The hardware chip may be an application specific integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general-purpose array logic, or any combination thereof.
Wherein the memory 20 stores instructions executable by the at least one processor 10 to cause the at least one processor 10 to perform a method for implementing the embodiments described above.
The memory 20 may include a storage program area that may store an operating system, at least one application program required for functions, and a storage data area; the storage data area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, memory 20 may optionally include memory located remotely from processor 10, which may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
Memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk, or solid state disk; the memory 20 may also comprise a combination of the above types of memories.
The computer device further comprises input means 30 and output means 40. The processor 10, memory 20, input device 30, and output device 20 may be connected by a bus or other means, for example in fig. 7.
The input device 30 may receive input numeric or character information and generate key signal inputs related to user settings and function control of the computer apparatus, such as a touch screen, a keypad, a mouse, a trackpad, a touchpad, a pointer stick, one or more mouse buttons, a trackball, a joystick, and the like. The output means 40 may include a display device, auxiliary lighting means (e.g., LEDs), tactile feedback means (e.g., vibration motors), and the like. Such display devices include, but are not limited to, liquid crystal displays, light emitting diodes, displays and plasma displays. In some alternative implementations, the display device may be a touch screen.
The embodiments of the present invention also provide a computer readable storage medium, and the method according to the embodiments of the present invention described above may be implemented in hardware, firmware, or as a computer code which may be recorded on a storage medium, or as original stored in a remote storage medium or a non-transitory machine readable storage medium downloaded through a network and to be stored in a local storage medium, so that the method described herein may be stored on such software process on a storage medium using a general purpose computer, a special purpose processor, or programmable or special purpose hardware. The storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk, a solid state disk or the like; further, the storage medium may also comprise a combination of memories of the kind described above. It will be appreciated that a computer, processor, microprocessor controller or programmable hardware includes a storage element that can store or receive software or computer code that, when accessed and executed by the computer, processor or hardware, implements the methods illustrated by the above embodiments.
Although embodiments of the present invention have been described in connection with the accompanying drawings, various modifications and variations may be made by those skilled in the art without departing from the spirit and scope of the invention, and such modifications and variations fall within the scope of the invention as defined by the appended claims.

Claims (19)

1. An image compression method, the method comprising:
acquiring an image compression instruction and at least one image to be compressed;
creating a main process based on the image compression instruction;
determining the target block number of a first image to be compressed by using the main process, wherein the first image to be compressed is any image to be compressed;
creating a first set of sub-processes and a second set of sub-processes in a number corresponding to the number of target partitions with the master process;
extracting an image block from the first image to be compressed by using each subprocess in the first group of subprocesses, and obtaining the combination sequence of each image block in the first image to be compressed;
respectively carrying out image compression processing on an image block by utilizing each subprocess in the second group of subprocesses to obtain compressed image blocks respectively corresponding to each image block;
Combining all the compressed image blocks by the main process according to the combination sequence of each image block in the first image to be compressed respectively to generate a compressed image corresponding to the first image to be compressed,
extracting an image block from the first image to be compressed by using each sub-process in the first group of sub-processes, and obtaining a combination sequence of each image block in the first image to be compressed, wherein the combination sequence comprises the following steps:
utilizing the main process to allocate a starting extraction position of an image block for each sub-process in the first group of sub-processes, wherein the starting extraction position of each image block is determined according to a preset block size and the target block number;
traversing pixels of the first image to be compressed according to a preset block size from a starting extraction position corresponding to a first subprocess by using the first subprocess to obtain a first image block and an extraction sequence of the first image block, wherein the first subprocess is any subprocess in the first group of subprocesses, and the first image block is the image block extracted by the first subprocess;
And taking the extraction sequence of the first image block as the corresponding combination sequence of the first image block in the first image to be compressed.
2. The method according to claim 1, wherein the first sub-process is configured to perform a row traversing operation and a column traversing operation, and the traversing pixels of the first image to be compressed according to a preset block size by using the first sub-process from a start extraction position corresponding to the first sub-process, to obtain a first image block and an extraction sequence of the first image block, includes:
starting from a first initial extraction position, performing row traversing operation and column traversing operation on pixels of the first image to be compressed respectively by taking the preset block size as a reference, and obtaining the first image block, wherein the first initial extraction position is an initial extraction position corresponding to the first subprocess;
and taking the sequence of extracting the first image block as the extraction sequence of the first image block.
3. The method according to claim 2, wherein the traversing the pixels of the first image to be compressed according to a preset block size from a start extraction position corresponding to the first sub-process by using the first sub-process, and after obtaining a first image block and an extraction sequence of the first image block, the method further comprises:
Storing the image blocks in a preset shared data structure according to the combination sequence;
after confirming that all the image blocks are stored in the preset shared data structure, generating identification information corresponding to each image block according to the combination sequence.
4. A method according to claim 3, wherein after storing the image blocks in the combined order in a preset shared data structure, the method further comprises:
and sending a storage completion signal to the main process by using the first sub-process, wherein the storage completion signal is used for indicating that the first sub-process is an idle process.
5. The method according to claim 1, 2 or 4, wherein said performing image compression processing on an image block by using each sub-process in the second set of sub-processes to obtain compressed image blocks corresponding to each image block respectively, includes:
performing image compression processing on a first image block by using a second subprocess in the second group of subprocesses to obtain a compressed image block corresponding to the first image block, wherein the second subprocess is any subprocess in the second group of subprocesses, performing image compression processing on the first image block to obtain the compressed image block corresponding to the first image block, and specifically comprises the following steps:
Performing coding operation on the first image block to obtain a frequency domain information matrix corresponding to the first image block;
performing quantization operation on the frequency domain information matrix to obtain an initial quantization matrix corresponding to the first image block;
performing filtering operation on the initial quantization matrix to obtain a target quantization matrix corresponding to the first image block;
and performing inverse quantization operation on the target quantization matrix to obtain a first compressed image block corresponding to the first image block.
6. The method of claim 5, wherein the filtering the initial quantization matrix to obtain the target quantization matrix corresponding to the first image block comprises:
and filtering the data which are larger than a preset frequency threshold value in the initial quantization matrix by utilizing a plurality of filter matrixes with different sizes, and obtaining a target quantization matrix corresponding to the first image block.
7. The method of claim 6, wherein filtering the data greater than the preset frequency threshold in the initial quantization matrix by using a plurality of filter matrices with different sizes to obtain the target quantization matrix corresponding to the first image block, comprises:
Sequencing a plurality of filter matrixes according to the size of each filter matrix, and determining the filtering sequence of each filter matrix;
carrying out weight normalization operation on each filter matrix to obtain normalized filter weight matrixes corresponding to each filter matrix respectively;
and performing progressive filtering operation on the initial quantization matrix by using each normalized filtering weight matrix according to the filtering sequence and the preset frequency threshold value, and obtaining the target quantization matrix.
8. The method of claim 7, wherein the performing a weight normalization operation on each of the filter matrices to obtain a normalized filter weight matrix corresponding to each filter matrix, respectively, includes:
acquiring Gaussian distribution standard deviations corresponding to the filter matrixes respectively;
determining a first weight matrix corresponding to a first filter matrix according to index data of a central point of the first filter matrix, index data of each matrix element in the initial quantization matrix and the Gaussian distribution standard deviation, wherein the first filter matrix is any filter matrix in a plurality of filter matrices with different sizes;
And carrying out normalization processing on the weight matrix to obtain a first normalized filtering weight matrix corresponding to the first filtering matrix.
9. The method according to claim 8, wherein the determining the first weight matrix corresponding to the first filter matrix according to the index data of the center point of the first filter matrix, the index data of each matrix element in the initial quantization matrix, and the gaussian distribution standard deviation is implemented specifically by:
wherein,index data for each matrix element corresponding to said initial quantization matrix, respectively +.>For the first weight matrix, +.>Index data of the center point of the first filter matrix, respectively, < >>And the Gaussian distribution standard deviation corresponding to the first filtering matrix is obtained.
10. The method of claim 8, wherein the normalizing the weight matrix to obtain a first normalized filtering weight matrix corresponding to the first filtering matrix is implemented by:
wherein,for the first weight matrix, +.>For said first normalized filter weight matrix, < >>Is the sum of all elements in the first weight matrix.
11. The method according to claim 7 or 8, wherein performing a progressive filtering operation on the initial quantization matrix using each of the normalized filter weight matrices performs a progressive filtering operation on the initial quantization matrix in the filtering order, and obtaining the target quantization matrix, comprising:
determining a current normalized filtering weight matrix according to the filtering sequence, and filtering a current quantization matrix by using the current normalized filtering weight matrix to obtain a first filtering quantization matrix, wherein the current quantization matrix is a quantization matrix corresponding to the current normalized filtering weight matrix;
determining a next normalized filtering weight matrix according to the filtering sequence, and filtering the first filtering quantization matrix by using the next normalized filtering weight matrix to obtain a second filtering quantization matrix;
and obtaining the target quantization matrix after determining that all the normalized filtering weight matrixes complete filtering operation.
12. The method of claim 11, wherein determining a current normalized filter weight matrix according to the filtering order and filtering a current quantization matrix using the current normalized filter weight matrix to obtain a first filtered quantization matrix comprises:
Aligning a center point of the current normalized filtering weight matrix with a first element in the current quantization matrix, wherein the first element is any element in the quantization matrix;
determining a target element value of the first element according to the element value of each element in the current quantization matrix and the element value of the element at the corresponding position of the current normalized filtering weight matrix;
the first filtered quantization matrix is constructed using target element values for all elements.
13. The method according to claim 11, wherein determining a current normalized filtering weight matrix according to the filtering order, and filtering a current quantization matrix using the current normalized filtering weight matrix, to obtain a first filtered quantization matrix, is specifically implemented by the following formula:
wherein,representing the position coordinates of the elements in the quantization matrix, and (2)>Representing the position coordinates of the first element,a target element value representing the first element, +.>Representing the weights of the current normalized filter weight matrix,representing the position coordinates as +.>M is the number of rows of the quantization matrix, N is the number of columns of the quantization matrix,/>Representing a convolution operation.
14. The method according to claim 12 or 13, wherein the filter matrix is at least two of:
a 3 by 3 dimensional matrix, a 4 by 4 dimensional matrix, a 5 by 5 dimensional matrix, and a 7 by 7 dimensional matrix.
15. The method according to any one of claims 1 to 2 or 6 to 10, wherein determining a target number of tiles of a first image to be compressed using the main process comprises:
acquiring the height and width of the first image to be compressed and a preset block size by using the main process;
and determining the target block number according to the height, the width and the preset block size.
16. The method of claim 15, wherein the predetermined tile size comprises a row width and a column height of tiles, and wherein determining the target number of tiles based on the height, the width, and the predetermined number of tiles comprises:
determining the column number of the blocks according to the height and the column height;
determining the number of rows of the blocks according to the width and the row width;
and determining the number of the target blocks according to the number of columns and the number of rows.
17. An image compression apparatus, the apparatus comprising:
The acquisition module is used for acquiring an image compression instruction and at least one image to be compressed;
the first creation module is used for creating a main process based on the image compression instruction;
the determining module is used for determining the target block number of a first image to be compressed by utilizing the main process, wherein the first image to be compressed is any image to be compressed;
a second creation module, configured to create, with the main process, a first set of sub-processes and a second set of sub-processes having numbers corresponding to the target block number;
the extraction module is used for respectively extracting an image block from the first image to be compressed by utilizing each subprocess in the first group of subprocesses, and acquiring the combination sequence of each image block in the first image to be compressed;
the image compression module is used for respectively carrying out image compression processing on an image block by utilizing each subprocess in the second group of subprocesses to obtain compressed image blocks respectively corresponding to each image block;
a generation module, configured to combine all the compressed image blocks according to a combination sequence of each image block in the first image to be compressed by using the main process, to generate a compressed image corresponding to the first image to be compressed,
The extraction module is specifically configured to:
utilizing the main process to allocate a starting extraction position of an image block for each sub-process in the first group of sub-processes, wherein the starting extraction position of each image block is determined according to a preset block size and the target block number;
traversing pixels of the first image to be compressed according to a preset block size from a starting extraction position corresponding to a first subprocess by using the first subprocess to obtain a first image block and an extraction sequence of the first image block, wherein the first subprocess is any subprocess in the first group of subprocesses, and the first image block is the image block extracted by the first subprocess;
and taking the extraction sequence of the first image block as the corresponding combination sequence of the first image block in the first image to be compressed.
18. A computer device, comprising:
a memory and a processor in communication with each other, the memory having stored therein computer instructions, the processor executing the computer instructions to perform the image compression method of any one of claims 1 to 16.
19. A computer-readable storage medium having stored thereon computer instructions for causing a computer to perform the image compression method of any one of claims 1 to 16.
CN202311310568.9A 2023-10-11 2023-10-11 Image compression method, device, computer equipment and storage medium Active CN117061759B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311310568.9A CN117061759B (en) 2023-10-11 2023-10-11 Image compression method, device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311310568.9A CN117061759B (en) 2023-10-11 2023-10-11 Image compression method, device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN117061759A CN117061759A (en) 2023-11-14
CN117061759B true CN117061759B (en) 2024-02-06

Family

ID=88655719

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311310568.9A Active CN117061759B (en) 2023-10-11 2023-10-11 Image compression method, device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117061759B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103631568A (en) * 2013-12-20 2014-03-12 厦门大学 Medical-image-oriented multi-thread parallel computing method
CN107451955A (en) * 2017-06-20 2017-12-08 昆明理工大学 A kind of K T algorithms rebuild the parallelization implementation method of spot figure in astronomic graph picture
WO2018223786A1 (en) * 2017-06-05 2018-12-13 中兴通讯股份有限公司 Cloud desktop system, and image sequence compression and encoding method, and medium therefor
CN112422985A (en) * 2020-10-26 2021-02-26 眸芯科技(上海)有限公司 Multi-core parallel hardware coding method and device suitable for JPEG
CN114245173A (en) * 2021-12-17 2022-03-25 中国平安财产保险股份有限公司 Image compression method, device, terminal equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103631568A (en) * 2013-12-20 2014-03-12 厦门大学 Medical-image-oriented multi-thread parallel computing method
WO2018223786A1 (en) * 2017-06-05 2018-12-13 中兴通讯股份有限公司 Cloud desktop system, and image sequence compression and encoding method, and medium therefor
CN107451955A (en) * 2017-06-20 2017-12-08 昆明理工大学 A kind of K T algorithms rebuild the parallelization implementation method of spot figure in astronomic graph picture
CN112422985A (en) * 2020-10-26 2021-02-26 眸芯科技(上海)有限公司 Multi-core parallel hardware coding method and device suitable for JPEG
CN114245173A (en) * 2021-12-17 2022-03-25 中国平安财产保险股份有限公司 Image compression method, device, terminal equipment and storage medium

Also Published As

Publication number Publication date
CN117061759A (en) 2023-11-14

Similar Documents

Publication Publication Date Title
CN108028941B (en) Method and apparatus for encoding and decoding digital images by superpixel
US8265402B2 (en) 2 dimensional signal encoding/decoding method and device
JP3378257B2 (en) System and method for nested split coding of sparse datasets
CN106937111B (en) Method and system for optimizing image compression quality
CN113096198B (en) Bidirectional point cloud attribute prediction compression method, device, equipment and medium
US20170353720A1 (en) Prediction mode selection method, apparatus and device
CN101779461B (en) Image compression and decompression using the pixon method
EP3343446A1 (en) Method and apparatus for encoding and decoding lists of pixels
Hu et al. An adaptive two-layer light field compression scheme using GNN-based reconstruction
WO2023082834A1 (en) Video compression method and apparatus, and computer device and storage medium
US20220377339A1 (en) Video signal processor for block-based picture processing
CN117061759B (en) Image compression method, device, computer equipment and storage medium
CN105163124A (en) Image coding method, image decoding method, image coding device and image decoding device
US10291911B2 (en) Classes of tables for use in image compression
US20220094951A1 (en) Palette mode video encoding utilizing hierarchical palette table generation
US9049432B1 (en) Motion differential set partition coding for color image sequence compression
US10687062B1 (en) Compression across multiple images
CN115086658A (en) Point cloud data processing method and device, storage medium and encoding and decoding equipment
CN107172425B (en) Thumbnail generation method and device and terminal equipment
WO2023023914A1 (en) Intra-frame prediction method and apparatus, encoding method and apparatus, decoding method and apparatus, and encoder, decoder, device and medium
RU2782583C1 (en) Block-based image merging for context segmentation and processing
US11218698B2 (en) Fractional/arbitrary tile grouping
WO2022257143A1 (en) Intra-frame prediction method and apparatus, encoding method and apparatus, decoding method and apparatus, codec, device and medium
JPH02104180A (en) Compression processing method for image data compressor
CN115714859A (en) Point cloud attribute coding method, point cloud attribute decoding method and terminal

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