CN115802050A - Image compression and decompression method, device, equipment and computer readable storage medium - Google Patents

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

Info

Publication number
CN115802050A
CN115802050A CN202211139550.2A CN202211139550A CN115802050A CN 115802050 A CN115802050 A CN 115802050A CN 202211139550 A CN202211139550 A CN 202211139550A CN 115802050 A CN115802050 A CN 115802050A
Authority
CN
China
Prior art keywords
data
pixel data
compressed
group
ith
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.)
Pending
Application number
CN202211139550.2A
Other languages
Chinese (zh)
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.)
Zhejiang Huaray Technology Co Ltd
Original Assignee
Zhejiang Huaray 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 Zhejiang Huaray Technology Co Ltd filed Critical Zhejiang Huaray Technology Co Ltd
Priority to CN202211139550.2A priority Critical patent/CN115802050A/en
Publication of CN115802050A publication Critical patent/CN115802050A/en
Pending legal-status Critical Current

Links

Images

Abstract

The embodiment of the invention provides an image compression and decompression method, device, equipment and a computer readable storage medium, wherein the compression method comprises the following steps: dividing pixel data of an original image into a plurality of data groups; for the ith pixel data in any data group, determining the compressed prediction data of the ith pixel data (not the first k pixel data in the data group); determining the compression data of the ith pixel data in any first data group according to the compression prediction data; for the ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to the difference values of the residual data of all the pixel data except the first k pixel data in the first data group corresponding to the second data group and the residual data of the pixel data at the same position in the second data group; and coding any data group according to the compressed data of the data group to obtain an image compressed data packet.

Description

Image compression and decompression method, device, equipment and computer readable storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a computer readable storage medium for compressing and decompressing an image.
Background
With the development of industrial technology, industrial vision needs are more and more vigorous. The industrial camera based on the gigabit Ethernet has the advantages of proper price, convenient wiring, mature technology and the like, and is widely applied to industrial fields; however, as the industrial cameras are developed to have high resolution and high frame rate, the transmission bandwidth of the gigabit ethernet becomes a bottleneck. In order to be able to transmit higher data volume, industrial camera manufacturers have successively introduced industrial cameras with 2.5G, 5G, 10G bandwidth, but this also results in a corresponding increase in the hardware cost of the camera and system equipment. On the premise of not increasing hardware cost, the method aims to fully utilize the transmission bandwidth of a network, reduce redundant information of data, and realize low cost and rapid lossless compression of image data.
Disclosure of Invention
The embodiment of the invention provides an image compression and decompression method, device and equipment and a computer readable storage medium, which are used for providing an image compression scheme with high compression rate.
In a first aspect, an embodiment of the present invention provides an image compression method, including:
dividing at least part of continuous pixel data of an original image into a plurality of pixel data sets according to a rule that every xn continuous pixel data are divided into one set, and for any pixel data set, evenly distributing the pixel data to x data groups to obtain x data groups corresponding to the pixel data sets; wherein n is a positive integer greater than k, k is a positive integer, and x is a positive integer greater than 1;
for ith pixel data in any data group, determining compressed prediction data of the ith pixel data according to the ith pixel data in the data group and k consecutive pixel data before the ith pixel data in the data group; wherein i is a positive integer greater than k and less than or equal to n;
regarding the jth pixel data in any data group, taking the jth pixel data as compressed data corresponding to the jth pixel data; wherein j is a positive integer less than the minimum value of i;
for ith pixel data in any first data group, determining compressed data of the ith pixel data of the first data group according to the compressed prediction data of the ith pixel data of the first data group; wherein for any pixel data set, the first data set is one of the pixel data sets;
for ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to difference values of residual data of all pixel data except the first k pixel data in the first data group which belongs to the same set with the second data group and residual data of pixel data at the same position in the second data group; wherein the residual data of any pixel data is the difference between the pixel data and the compressed prediction data of the pixel data; for any pixel data set, the second data group is at least a portion of the data groups in the pixel data set other than the first data group;
and coding any data group according to the compressed data of the data group to obtain an image compressed data packet.
Optionally, for any pixel data set, evenly distributing the pixel data to x data groups to obtain x data groups corresponding to the pixel data set, including:
and for any pixel data set, distributing the pixel data according to a rule that every continuous x pixel data are sequentially distributed to x data groups to obtain x data groups corresponding to the pixel data set.
Optionally, for ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to respective differences between residual data of respective pixel data except for the first k pixel data in the first data group belonging to the same set as the second data group and residual data of pixel data at the same position in the second data group, including:
and for the ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to the sum of the occupied bit numbers of the difference values of the residual data of all the pixel data except the first k pixel data in the first data group which belongs to the same pixel data set with the second data group and the residual data of the pixel data at the same position in the second data group.
Optionally, for the ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to a sum of bits of differences between residual data of each pixel data except the first k pixel data in the first data group belonging to the same pixel data set as the second data group and residual data of pixel data at the same position in the second data group, including:
if the sum of the occupied bit numbers of the difference values of the residual data of all the pixel data except the first k pieces of pixel data in a first data group which belongs to the same pixel data set with the second data group and the residual data of the pixel data at the same position in the second data group is larger than the sum of the occupied bit numbers of the residual data of all the pixel data except the first k pieces of pixel data in the second data group, regarding the ith pixel data of the second data group, taking the residual data of the ith pixel data of the second data group as the compressed data of the ith pixel data of the second data group;
and if the sum of the number of occupied bits of the difference values of the residual data of all the pixel data except the first k pixel data in the first data group and the residual data of the pixel data at the same position of k in the second data group in the first data group belonging to the same pixel data set with the second data group is less than or equal to the sum of the number of occupied bits of the residual data of all the pixel data except the first k pixel data in the second data group, regarding the ith pixel data of the second data group, taking the difference value of the residual data of the ith pixel data of the second data group and the residual data of the ith pixel data of the first data group as the compression data of the ith pixel data of the second data group.
Alternatively, x =2;
dividing at least part of pixel data of an original image into a plurality of pixel data sets according to a rule that every xn continuous pixel data are divided into one set, comprising:
dividing all pixel data of an original image into a plurality of pixel data sets according to a rule that every 2n continuous pixel data are divided into one set;
for any pixel data set, the first data group is a data group formed by pixel data at odd positions in the pixel data set, and the second data group is a data group formed by pixel data at even positions in the pixel data set.
Optionally, for the ith pixel data, the compressed prediction data of the ith pixel data satisfies the following relationship:
Figure BDA0003852924020000041
where m is the number of the data set, X m (i) Is the ith pixel data, X m (i) For the compression prediction data of the ith pixel data, delta (i) is determined according to the (i-1) th pixel data, the (i-2) th pixel data and the (i-3) th pixel data in the data group, and a and b are preset values.
Optionally, Δ (i) satisfies the following relationship:
Δ(i)=||X m (i-2)-X m (i-3)|-|X m (i-1)-X m (i-2)||。
optionally, encoding according to the compressed data of the data group to obtain an image compressed data packet, including:
encoding at least part of compressed data of the data group by using an entropy encoding table to obtain first encoded data;
determining the average bit width and the offset bit width of all the first coded data, and determining a bit width residual error according to the average bit width and the offset bit width;
for any one first encoding data, determining second encoding data corresponding to the first encoding data; wherein the occupied-bit-number encoding in the second encoded data is equal to the occupied-bit-number encoding in the first encoded data minus the bit-width residual;
and putting the second coded data, the number of pixel data of the data group, the average bit width and the offset bit width and identification information for indicating a generation mode of compressed data into an image compressed data packet.
Optionally, determining the compressed data of the ith pixel data of the first data group according to the compressed predicted data of the ith pixel data of the first data group includes:
and taking residual data of the ith pixel data in the first data group as compressed data of the ith pixel data in the first data group.
In a second aspect, based on the same inventive concept, an embodiment of the present invention further provides an image decompression method, including:
acquiring at least one image compression data packet corresponding to an original image;
decompressing any image compression data packet to obtain pixel data;
generating an original image according to pixel data obtained by decompressing each image compressed data packet;
the method comprises the following steps of for any image compression data packet, decompressing to obtain pixel data:
determining each compressed data based on the image compressed data packet; wherein at least part of the compressed data is determined from the encoded data in the image compressed data packet;
for the jth compressed data, determining the jth compressed data as jth pixel data; wherein j is a positive integer less than the minimum value of i;
for the ith compressed data, determining the compression mode of the compressed data according to the identification information in the image compressed data packet, and determining the compression prediction data of the ith pixel data by using the compression mode and according to the ith compressed data and the pixel data corresponding to k continuous compressed data before the ith compressed data corresponding to the image compressed data packet; wherein i is a positive integer which is greater than k and less than or equal to n, n is the number of the coded data in the coded data packet, and k is a positive integer;
judging whether the coded data packet corresponds to a first data group or a second data group;
if the encoded data packet corresponds to a second data group, for ith compressed data in the second data group, determining pixel data corresponding to the ith compressed data in the second data group according to the compression prediction data of the ith pixel data in the second data group, the ith compressed data in the second data group and the ith compressed data corresponding to a first data group of a pixel data set which belongs to the same genus as the second data group;
and if the coded data packet corresponds to a first data group, determining pixel data corresponding to ith compressed data of the first data group according to the compressed prediction data of the ith pixel data of the first data group and the ith compressed data of the first data group for the ith compressed data in the first data group.
Optionally, determining, according to the compressed predicted data of the ith pixel data of the second data group, the ith compressed data of the second data group, and the ith compressed data in the first data group of the same pixel data set as the second data group, the pixel data corresponding to the ith compressed data of the second data group specifically includes:
when the compression mode of the compressed data is determined to be a first-class compression mode according to the identification information in the encoding data packet, determining pixel data corresponding to ith compressed data of the second data group according to compressed predicted data of ith pixel data of the second data group, ith compressed data of the second data group and ith compressed data in a first data group of a pixel data set which belongs to the same genus as the second data group;
and when the compression mode of the compressed data is determined to be a second type of compression mode according to the identification information in the encoding data packet, determining pixel data corresponding to ith compressed data of the second data group according to the compression prediction data of ith pixel data of the second data group and ith compressed data of the second data group.
Optionally, determining, according to the compressed predicted data of the ith pixel data of the second data group, the ith compressed data of the second data group, and the ith compressed data in the first data group of the same pixel data set as the second data group, the pixel data corresponding to the ith compressed data of the second data group specifically includes:
when the compression mode of the compressed data is determined to be a first-class compression mode according to the identification information in the encoding data packet, adding the compression prediction data of the ith pixel data of the second data group with the ith compressed data in the first data group of the same pixel data set belonging to the second data group, and subtracting the ith compressed data of the second data group to obtain the pixel data corresponding to the ith compressed data of the second data group;
and when the compression mode of the compressed data is determined to be a second type of compression mode according to the identification information in the encoding data packet, adding the compression prediction data of the ith pixel data of the second data group and the ith compressed data of the second data group to obtain the pixel data corresponding to the ith compressed data of the second data group.
Optionally, determining, by using the compression method and according to the ith pixel data in the first data group and k consecutive pixel data before the ith pixel data in the first data group, compressed prediction data of the ith pixel data in the first data group includes:
if the compression mode is the first compression mode, the compressed prediction data of the ith pixel data of the second data group is:
Figure BDA0003852924020000071
if the compression mode is the second compression mode, the compressed prediction data of the ith pixel data of the second data group is:
Figure BDA0003852924020000072
if the compression mode is a third compression mode, the compression prediction data of the ith pixel data of the second data group is:
X′ m (i)=2X m (i-1)-X m (i-2)
where m is the number of the data set, X m (i) Is ith pixel data, X' m (i) Compressed prediction data for the ith pixel data.
Optionally, determining each compressed data based on the image compressed data packet comprises:
acquiring the identification information, the average bit width, the offset bit width and the pixel data quantity from the image compression data packet;
according to the pixel data quantity, sequentially acquiring second coded data from the image compressed data packet;
determining a bit width residual error according to the average bit width and the offset bit width of the coded data;
for any one second coded data, determining first coded data corresponding to the second coded data according to the bit width residual error; wherein the occupied-bit-number encoding in the first encoded data is equal to the occupied-bit-number encoding in the second encoded data plus the bit-width residual;
for any one first encoding data, determining compression data corresponding to the first encoding data by using an entropy encoding table.
Optionally, determining, according to the compression prediction data of the ith pixel data of the first data group and the ith compression data of the first data group, the pixel data corresponding to the ith compression data of the first data group includes:
and adding the compression prediction data of the ith pixel data of the first data group and the ith compression data of the first data group to obtain the pixel data corresponding to the ith compression data of the first data group.
In a third aspect, based on the same inventive concept, an embodiment of the present invention further provides an image compression apparatus, including:
the grouping module is used for dividing at least part of continuous pixel data of an original image into a plurality of pixel data sets according to a rule that every xn continuous pixel data are divided into one set, and for any pixel data set, the pixel data are evenly distributed to x data groups to obtain x data groups corresponding to the pixel data sets; wherein n is a positive integer greater than k, k is a positive integer, and x is a positive integer greater than 1;
the prediction module is used for determining compressed prediction data of ith pixel data in any data group according to the ith pixel data in the data group and k continuous pixel data before the ith pixel data in the data group; wherein i is a positive integer greater than k and less than or equal to n;
the first compression module is used for taking the jth pixel data in any data group as compressed data corresponding to the jth pixel data; wherein j is a positive integer less than the minimum value of i;
the second compression module is used for determining the compression data of the ith pixel data of any first data group according to the compression prediction data of the ith pixel data of the first data group; wherein for any pixel data set, the first data group is one of the pixel data sets;
a third compression module, configured to determine, for an ith pixel data in any second data group, compressed data corresponding to the ith pixel data in the second data group according to difference values between residual data of each pixel data, except for the first k pixel data, in a first data group that belongs to the same set as the second data group, and residual data of pixel data at the same position in the second data group; wherein the residual data of any pixel data is the difference between the pixel data and the compressed prediction data of the pixel data; for any pixel data set, the second data group is at least a portion of the data groups in the pixel data set other than the first data group;
and the coding module is used for coding any data group according to the compressed data of the data group to obtain an image compressed data packet.
In a fourth aspect, based on the same inventive concept, an embodiment of the present invention further provides an image decompression apparatus, including:
the acquisition module is used for acquiring at least one image compression data packet corresponding to an original image;
the decompression module is used for decompressing any image compression data packet to obtain pixel data;
the restoration module is used for generating an original image according to pixel data obtained by decompressing each image compression data packet;
the method comprises the following steps of decompressing any image compression data packet to obtain pixel data:
determining each compressed data based on the image compressed data packet; wherein at least part of the compressed data is determined from the encoded data in the image compression data packet;
for the jth compressed data, determining the jth compressed data as jth pixel data; wherein j is a positive integer less than the minimum value of i;
for the ith compressed data, determining the compression mode of the compressed data according to the identification information in the image compressed data packet, and determining the compressed prediction data of the ith pixel data by using the compression mode and according to the ith compressed data and the pixel data corresponding to k continuous compressed data before the ith compressed data corresponding to the image compressed data packet; wherein i is a positive integer which is greater than k and less than or equal to n, n is the number of the coded data in the coded data packet, and k is a positive integer;
judging whether the coded data packet corresponds to a first data group or a second data group;
if the encoded data packet corresponds to a second data group, determining pixel data corresponding to ith compressed data of the second data group according to the compressed prediction data of the ith pixel data of the second data group, the ith compressed data of the second data group and the ith compressed data corresponding to a first data group of a pixel data set which belongs to the same category as the second data group;
and if the encoding data packet corresponds to a first data group, determining pixel data corresponding to the ith compressed data of the first data group according to the compression prediction data of the ith pixel data of the first data group and the ith compressed data of the first data group for the ith compressed data in the first data group.
In a fifth aspect, based on the same inventive concept, an embodiment of the present invention further provides an electronic device, including: a processor and a memory for storing processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the image compression method according to the first aspect or to implement the image decompression method according to the second aspect.
In a sixth aspect, based on the same inventive concept, embodiments of the present invention further provide an electronic device, including an asic, which is used to implement the image compression method according to the first aspect or the image decompression method according to the second aspect.
In a seventh aspect, based on the same inventive concept, embodiments of the present invention further provide a computer-readable storage medium, where a computer program is stored, and the computer program is used to implement the image compression method according to the first aspect, or implement the image decompression method according to the second aspect.
The invention has the following beneficial effects:
according to the image compression and decompression method, the image compression and decompression device, the image compression and decompression equipment and the computer readable storage medium, the pixel data of the original image are grouped, and the second data group determines the compressed data of the second data group according to the difference value of the residual error data of the pixel data of the second data group and the residual error data of the pixel data of the first data group, so that the pixel data of the second data group can be further compressed by referring to the color rule of the pixel data of the first data group, and the data volume can be better compressed.
Drawings
FIG. 1 is a flowchart of an image compression method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a pixel distribution of an image in Bayer format;
FIG. 3 is a second flowchart of an image compression method according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating a structure of an image compression packet according to an embodiment of the present invention;
FIG. 5 is a flowchart of an image decompression method according to an embodiment of the present invention;
FIG. 6 is a partial flowchart of an image decompression method according to an embodiment of the present invention;
FIG. 7 is a second flowchart of a portion of an image decompression method according to an embodiment of the present invention;
FIG. 8 is a schematic structural diagram of an image compression apparatus according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of an image decompression apparatus according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present invention;
fig. 11 is a second schematic structural diagram of an electronic device according to an embodiment of the invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, the present invention is further described in conjunction with the accompanying drawings and examples. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The same reference numerals in the drawings denote the same or similar structures, and thus their repetitive description will be omitted. The words expressing the position and direction described in the present invention are illustrated in the accompanying drawings, but may be changed as required and still be within the scope of the present invention. The drawings of the present invention are for illustrative purposes only and do not represent true scale.
It should be noted that in the following description, specific details are set forth in order to provide a thorough understanding of the present invention. The invention can be embodied in many different forms than those described herein and those skilled in the art will appreciate that the invention is susceptible to similar forms of embodiment without departing from the spirit and scope of the invention. Therefore, the present invention is not limited to the specific embodiments disclosed below. The description which follows is a preferred embodiment of the present application, but is made for the purpose of illustrating the general principles of the application and not for the purpose of limiting the scope of the application. The protection scope of the present application shall be subject to the definitions of the appended claims.
The following describes an image compression and decompression method, apparatus, device, and computer readable storage medium according to an embodiment of the present invention with reference to the accompanying drawings.
In a first aspect, an embodiment of the present invention provides an image compression method. As shown in fig. 1, includes:
s110, dividing at least partial continuous pixel data of the original image into a plurality of pixel data sets according to a rule that every xn continuous pixel data are divided into one set.
In a specific implementation process, the process of dividing the pixel data sets may divide the pixel data to be compressed by the image compression method provided by the embodiment of the present invention at one time to obtain all the pixel data sets; or dividing the pixel data into a pixel data set and compressing the pixel data set in subsequent steps after acquiring xn continuous pixel data, dividing the pixel data set into a pixel data set and compressing the pixel data set in subsequent steps after completing the compression process of the pixel data set, and repeating the steps until all the pixel data to be compressed by the scheme is compressed is completed, so as to complete the process, thereby realizing the dynamic process of variable division and variable compression. When compressing the original image, only part of the pixel data may be compressed by the image compression method provided by the embodiment of the present invention, or all the pixel data of the original image may be compressed by the image compression method provided by the embodiment of the present invention.
And S120, for any pixel data set, evenly distributing the pixel data to x data groups to obtain x data groups corresponding to the pixel data set.
Wherein n is a positive integer greater than k, k is a positive integer, and x is a positive integer greater than 1.
Thus, each data group will include n pixel data.
S130, for the ith pixel data in any data group, determining the compressed prediction data of the ith pixel data according to the ith pixel data in the data group and k consecutive pixel data before the ith pixel data in the data group.
Wherein i is a positive integer greater than k and less than or equal to n.
And S140, regarding the jth pixel data in any data group, taking the jth pixel data as compressed data corresponding to the jth pixel data.
Wherein j is a positive integer less than the minimum value of i.
S150, for the ith pixel data in any first data group, determining the compressed data of the ith pixel data of the first data group according to the compressed predicted data of the ith pixel data of the first data group.
Wherein, for any pixel data set, the first data group is one of the pixel data sets.
In a specific implementation process, the embodiment of the present invention does not make much limitation on which data group in the pixel data set is selected as the first data group. For example, x =2, and either one of two data groups corresponding to the pixel data set may be set as the first data group. Since it will be described later that one of the roles of the first data group is to provide a reference for the compression process of the pixel data of the second data group, in order to be able to compress all the pixel data of the original image most efficiently, it is preferable that the data group generated first in the order of distribution be the first data group. For example, when x =2, two data groups are allocated according to the rule of the position parity grouping of the pixel data, and the data group in which the pixel data at the odd-numbered position in the original image is located is set as the first data group.
And S160, for the ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to the difference values of the residual data of all the pixel data except the first k pixel data in the first data group which belongs to the same set with the second data group and the residual data of the pixel data at the same position in the second data group.
Wherein, the residual data of any pixel data is the difference between the pixel data and the compressed prediction data of the pixel data, namely:
Δ X m (i)=X m (i)-X′ m (i)
where m is the number of the data set, X m (i) Is ith pixel data, X' m (i) For the compressed prediction data of the ith pixel data, Δ X m (i) Is residual data of the ith pixel data.
For any pixel data set, the second data set is at least a portion of the data sets of the pixel data set other than the first data set. For example, by dividing the pixel data in the pixel data set into three data sets in step S120, after determining that one of the data sets is the first data set, the remaining two data sets may be set as the second data set; one of the remaining two data sets may also be set as the second data set, and the other data set is neither the first data set nor the second data set, so that the compression scheme for the data set is compressed by using other prior art, which is not a key point in the embodiment of the present invention, and thus is not described in detail.
For any pixel data X of the second data group except the first k pixel data 2 (i) In other words, the pixel data X at the same position in the first data group belonging to the same set as the second data group 1 (i) Residual data of Δ X 1 (i) And pixel data X in the second data group 2 (i) Residual data of Δ X 2 (i) Difference of (2) Δ X (i), namely:
Δ X(i)= Δ X 1 (i)- Δ X 2 (i)
by determining the difference of the residual data of the pixel data at the same position in the two data sets except the first k pixel data, respectively: ( Δ X(i min )、……、 Δ X (n)), and then determining the second data set, excluding the first k pixel data, based on the numerical condition of the differencesCompressed data of each pixel data.
S170, coding any data group according to the compressed data of the data group to obtain an image compressed data packet.
It should be noted that the sequence of the above steps is only an exemplary sequence, and there is no strict sequence restriction between some steps, as long as it is reasonable. For example, the sequence between the step S150 and the step S160 may be exchanged; for another example, the step S170 is performed after the step S150 is performed, and then the step S170 is performed after the step S160 is performed.
In this way, according to the image compression scheme provided by the embodiment of the present invention, after the pixel data of the original image is grouped, the second data group determines the compressed data of the second data group according to the difference between the residual data of the pixel data of the second data group and the residual data of the pixel data of the first data group, so that the pixel data of the second data group can be further compressed by referring to the color rule of the pixel data of the first data group, and the data amount can be compressed better.
In a specific implementation process, the implementation manner of evenly distributing xn pixel data in one pixel data set to x data groups in step S120 may be set according to actual needs. Several possible embodiments are given below for example, and of course, other allocation manners that are not illustrated are also possible, and the embodiments of the present invention are not described in detail.
That is, in step S120, for any pixel data set, pixel data is evenly distributed to x data groups, so as to obtain x data groups corresponding to the pixel data set, which specifically includes:
for any pixel data set, sequentially distributing the pixel data to the data groups according to the sequence of the data groups according to the rule that every continuous y pixel data are distributed to 1 data group, and obtaining x data groups corresponding to the pixel data set.
In the specific implementation process, the following specific cases may be specifically included according to different values of y:
(1)y=n
that is, the step S120 is specifically: and for any pixel data set, carrying out data set non-repeated distribution on the pixel data according to the rule that every continuous n pixel data are distributed to 1 data set, and obtaining x data sets corresponding to the pixel data set.
For example, y = n =8, X =3, and the pixel data of one pixel data set is a, B \8230;, and X in this order. Then, after the distribution according to the above rule, the pixel data in the three data sets are:
data set a: A. b, C, D, E, F, G, H
Data set b: I. j, K, L, M, N, O, P
Data set c: q, R, S, T, U, V, W, X
(2)1<y<n
That is, the step S120 is specifically: for any pixel data set, sequentially distributing the pixel data to the data groups according to the sequence of the data groups according to the rule that every continuous y pixel data are distributed to 1 data group, and obtaining x data groups corresponding to the pixel data set.
For example, n =8, X =3, y =2, and the pixel data of one pixel data set is a, B \8230;, and X in this order. After the distribution is performed according to the above rule, the pixel data in the three data sets are:
data set a: A. b, G, H, M, N, S, T
Data set b: C. d, I, J, O, P, U, V
Data set c: E. f, K, L, Q, R, W, X
(3)y=1
That is, the step S120 is specifically: and for any pixel data set, distributing the pixel data according to the rule that every continuous x pixel data are sequentially distributed to x data groups to obtain x data groups corresponding to the pixel data set.
For example, n =8,x =3,y =1. The pixel data of a certain pixel data set are A, B \8230 \, and X in sequence. After the distribution is performed according to the above rule, the pixel data in the three data sets are:
data set a: A. d, G, J, M, P, S, V
Data set B: B. e, H, K, N, Q, T, W
Data set c: C. f, I, L, O, R, U, X
In contrast, in the compressed prediction data according to the embodiment of the present invention, for the ith pixel data, the compressed prediction data of the ith pixel data satisfies the following relationship:
Figure BDA0003852924020000151
where m is the number of the data set, X m (i) Is ith pixel data, X' m (i) For the compression prediction data of ith pixel data, delta (i) is determined according to (i-1) th pixel data, (i-2) th pixel data and (i-3) th pixel data in the data group, and a and b are preset values.
Preferably, a =16,b =32.
Further, Δ (i) satisfies the following relationship:
Δ(i)=||X m (i-2)-X m (i-3)|-|X m (i-1)-X m (i-2)||
of course, it is also possible to determine the compressed prediction data of the pixel data by other ways according to the color rule of the original image, and the above determination scheme is only a preferred scheme provided by the embodiment of the present invention, and the embodiment of the present invention is not limited strictly.
Therefore, by the compressed prediction data calculation method, the change gradient of the pixel data can be determined by utilizing the 3 pixel data before the currently processed pixel data, so that the change trend of the currently processed pixel data compared with the previous pixel data is reflected, higher prediction accuracy can be obtained, and the compression can be conveniently carried out by utilizing the rule of the change trend in the subsequent compression process.
The compression schemes for the first data set and the second data set are described in greater detail below.
First data set
In step S150, for the ith pixel data in any first data group, the compression number of the ith pixel data in the first data group for the ith pixel data in any first data group is determined according to the compressed prediction data of the ith pixel data in the first data group, and the residual data of the ith pixel data in the first data group is used as the compressed data of the ith pixel data in the first data group.
In effect, the residual data reflects the varying strength of the varying gradient of the neighboring pixel data. For common images, residual data of each pixel data approximately accords with a normal distribution rule, and the residual data are mainly distributed in a small numerical range in a centralized manner, so that the data volume of the compressed image data packet is reduced.
(II) second data group
In step S160, for the ith pixel data in any second data group, determining the compressed data corresponding to the ith pixel data in the second data group according to the difference between the residual data of each pixel data in the first data group, except the first k pixel data, belonging to the same set as the second data group and the residual data of the pixel data at the same position in the second data group, specifically including:
and for the ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to the sum of the occupied bit numbers of the difference values of the residual data of all the pixel data except the first k pixel data in the first data group which belongs to the same pixel data set with the second data group and the residual data of the pixel data at the same position in the second data group.
Specifically, the corresponding compressed data is determined according to the number of bits of the difference, and any one of the following embodiments may be adopted, including but not limited to:
(1) And if the sum of the occupied bits of the difference values of the residual data of the pixel data except the first k pixel data in the first data group belonging to the same pixel data set with the second data group and the residual data of the pixel data at the same position in the second data group is less than or equal to a preset threshold, regarding the ith pixel data of the second data group, taking the residual data of the ith pixel data of the second data group as the compressed data of the ith pixel data of the second data group.
And if the sum of the occupied bit numbers of the difference values of the residual data of all the pixel data except the first k pixel data in a first data group which belongs to the same pixel data set with the second data group and the residual data of the pixel data at the same position in the second data group is larger than the preset threshold, regarding the ith pixel data of the second data group, taking the difference value of the residual data of the ith pixel data of the second data group and the residual data of the ith pixel data of the first data group as the compression data of the ith pixel data of the second data group.
(2) And if the sum of the occupied bit numbers of the difference values of the residual data of all the pixel data except the first k pieces of pixel data in the first data group and the residual data of the pixel data at the same position in the second data group, which belong to the same pixel data set with the second data group, is greater than the sum of the occupied bit numbers of the residual data of all the pixel data except the first k pieces of pixel data in the second data group, regarding the ith pixel data of the second data group, taking the residual data of the ith pixel data of the second data group as the compressed data of the ith pixel data of the second data group.
And if the sum of the number of occupied bits of the difference values of the residual data of each pixel data except the first k pixel data in the first data group and the residual data of the pixel data at the same position in the second data group, which belong to the same pixel data set as the second data group, is less than or equal to the sum of the number of occupied bits of the residual data of each pixel data except the first k pixel data in the second data group, regarding the ith pixel data of the second data group, taking the difference value of the residual data of the ith pixel data of the second data group and the residual data of the ith pixel data of the first data group as the compression data of the ith pixel data of the second data group.
For example, there is a set of pixel data, comprising a first data set and a second data set, k =4,n =8. The residual data of the pixel data except the first 4 pixel data in the first data set are respectively 4, 5, 6 and 7, and the residual data of the pixel data except the first 4 pixel data in the second data set are respectively 3,4, 5 and 6. The difference values of the residual data of the pixel data at the corresponding positions of the two data sets are 1, 1 and 1. Since the sum of the occupied bit numbers of the differences 4 (the occupied bit number of the difference 1 is 1, the sum of the occupied bit numbers of the differences is 1+1= 4), is smaller than the sum of the occupied bit numbers of the residual data of the pixel data at the same position in the second data group 11 (the occupied bit number of the residual data 3 is 2, the number of occupied bits of the residual data 4, 5, 6 is 3, and then the sum of the number of occupied bits of each residual data is 2+ 3= 11), then each of the differences 1, 1 is determined as the compressed data of the fifth pixel, the sixth pixel, the seventh pixel, and the eighth pixel in the second data group, respectively.
In this way, the pixel data is compressed by selecting the mode of smaller total occupied bit number sum by considering the size relationship between the total occupied bit number of the residual data and the total occupied bit number of the difference value obtained by subtracting the residual data again for the second data group, so that the data volume of the second data group can be further reduced on the basis of the compression scheme of the first data group.
For a Bayer (Bayer) format raw image, pixels of two colors are arranged alternately in an odd-even position order for pixels located in the same row (for example, in the case illustrated in fig. 2, in the first row of pixels, pixels at odd-numbered positions are green (G), and pixels at even-numbered positions are red (R), and in the second row of pixels, pixels at odd-numbered positions are blue (B), and pixels at even-numbered positions are green (G)). Then, with respect to this characteristic of the Bayer pattern image, the image compression scheme may be further designed to perform group compression on the pixel data according to odd-even positions, so as to divide the pixel data of the same color into the same data group, thereby constructing an effect that the pixel data has a certain color correlation relationship in the data group and between the pixel data and the pixel data at the same position in different data groups, so as to perform compression.
Then, in particular, let x =2 in the above step.
Correspondingly, the step S110 of dividing at least part of the pixel data of the original image into a plurality of pixel data sets according to a rule that every xn consecutive pixel data are divided into one set specifically includes:
all pixel data of an original image is divided into a plurality of pixel data sets according to a rule that every 2n consecutive pixel data are divided into one set.
Accordingly, for any pixel data set, the first data group is a data group formed by pixel data at odd-numbered positions in the pixel data set, and the second data group is a data group formed by pixel data at even-numbered positions in the pixel data set.
A specific implementation example is given here for a raw image in Bayer format.
As shown in fig. 3, the compression method for an original image of the Bayer format includes:
s200, judging whether all pixel data of the original image are compressed or not.
If the result of the step S200 is no, execute step S210; if the result of the step S200 is yes, the compression process is ended.
S210, 2n consecutive pixel data are obtained from the pixel data of the original image without repetition as one pixel data set.
Wherein n can be set to be an integer of more than or equal to 8 and less than or equal to 128 according to actual needs.
S220, evenly distributing the pixel data to two data groups according to the odd-even positions of the pixel data set to obtain a first data group where the pixel data at the odd positions corresponding to the pixel data set are located and a second data group where the pixel data at the even positions are located.
And S221, selecting data groups from the pixel data set according to the sequence of selecting the first data group and then selecting the second data group.
For the selected first data group, performing step S250 after performing step S240; for the selected second data group, step S261 is performed after step S240 is performed.
And S230, regarding the jth pixel data in the current data group, and taking the jth pixel data as compressed data corresponding to the jth pixel data.
Wherein j ∈ {1,2,3,4}.
S240, for the ith pixel data in the current data set, determining the compression prediction data of the ith pixel data according to the ith pixel data in the data set and continuous 3 pixel data before the ith pixel data in the data set.
Wherein i is a positive integer greater than 4 and less than or equal to n.
For the ith pixel data, the compressed prediction data of the ith pixel data satisfies the following relation:
Figure BDA0003852924020000201
Δ(i)=||X m (i-2)-X m (i-3)|-|X m (i-1)-X m (i-2)||
where m is the number of the data set and m is the {1,2}, X m (i) Is ith pixel data, X' m (i) Compressed prediction data for the ith pixel data.
And S250, regarding the ith pixel data in the first data group, using the compressed prediction data of the ith pixel data in the first data group as the compressed data of the ith pixel data in the first data group. Step S270 is performed.
And S261, calculating difference values of residual data of all pixel data except the first 4 pixel data in the first data group and residual data of pixel data at the same position in the second data group, wherein the first data group and the second data group belong to the same set, and judging the size relation between the sum of occupied bits of the difference values and the sum of occupied bits of the residual data of all pixel data except the first 4 pixel data in the second data group.
If the sum of the occupied bit numbers of the difference values is greater than the sum of the occupied bit numbers of the residual data of the pixel data except the first 4 pixel data in the second data group, executing step S262; if the sum of the occupied bit numbers of the difference values is less than or equal to the sum of the occupied bit numbers of the residual data of the pixel data in the second data group except the first 4 pixel data, step S263 is performed.
And S262, regarding the ith pixel data in the second data group, taking residual error data of the ith pixel data in the second data group as compressed data of the ith pixel data in the second data group. Step S270 is performed.
And S263, regarding the ith pixel data of the second data group, taking the difference value of the residual error data of the ith pixel data of the second data group and the residual error data of the ith pixel data of the first data group as the compression data of the ith pixel data of the second data group. Step S270 is performed.
S270, coding the current data group according to the compressed data of the data group to obtain an image compressed data packet. Returning to the step S200.
After the process of compressing pixel data into compressed data is completed, the compressed data needs to be assembled into a compressed file for saving or transmission.
Further, as an optional implementation manner, in the step S170, encoding any data group according to the compressed data of the data group to obtain an image compressed data packet, includes:
for any data group, encoding at least part of compressed data of the data group by using an entropy encoding table to obtain first encoded data;
and putting the first encoding data, the pixel data quantity of the data group and identification information for indicating a generation mode of compressed data into an image compressed data packet.
In a specific implementation process, the first encoded data may be obtained by encoding the rest of the compressed data except the first k compressed data in the data group, and the first k compressed data may be directly placed in the corresponding position in the image compressed data packet. For example, entropy coding using Joint Photographic Experts Group (JPEG) as shown in Table 1 belowThe table encodes the remaining compressed data of the data group shown in table 2 below, except the first 4 compressed data, to obtain the first encoded data shown in table 2 below. (e.g., pixel data X m (9) The compressed data of (1) is 4, and the 5 th coded value with the coding bit width of 3 corresponds to the compressed data 4 shown in table 1, that is, the binary coding of the compressed data is 100. The rest of the pixel data are similar, and therefore, the description is omitted. )
TABLE 1 Baseline entropy coding Table of symbol-2 Structure
Figure BDA0003852924020000211
Figure BDA0003852924020000221
Table 2 correspondence table between partial compressed data and first encoded data of certain data group
Figure BDA0003852924020000222
Further, as another optional implementation manner, the step S170 of encoding any data group according to the compressed data of the data group to obtain an image compressed data packet includes:
for any data group, at least part of compressed data of the data group is encoded by using an entropy encoding table to obtain first encoded data;
determining the average bit width and the offset bit width of all the first coded data, and determining a bit width residual error according to the average bit width and the offset bit width;
for any one first encoding data, determining second encoding data corresponding to the first encoding data; wherein the occupied-bit-number encoding in the second encoded data is equal to the occupied-bit-number encoding in the first encoded data minus the bit-width residual;
and putting the second encoding data, the number of pixel data of the data group, the average bit width and the offset bit width and identification information for indicating a generation mode of compressed data into an image compressed data packet.
In a specific implementation, the average bit width
Figure BDA0003852924020000223
The following method is adopted for determination:
Figure BDA0003852924020000231
alternatively, the first and second electrodes may be,
Figure BDA0003852924020000232
wherein, w t For the bit width value of the first coded data in the image compression data packet, t is the serial number of the bit width value, n t Bit width value w for first coded data in image compressed data packet t Number of (2), n 0 Number of pixels, p, encoded in image compression packets t Is a bit width value w t Number of pixels n encoded in the image compression packet 0 The ratio of (a) to (b).
For example, when the data group shown in table 2 is finally compressed into an image compression data packet, the bit width value 1 is 1, the bit width value 2 is 4, and the bit width value 3 is 3. Then the average bit width is rounded down:
Figure BDA0003852924020000233
the offset bit width w' is determined as follows:
Figure BDA0003852924020000234
alternatively, the first and second electrodes may be,
Figure BDA0003852924020000235
wherein w min For the minimum bit width value, w, of the first coded data in an image compression packet max And compressing the maximum bit width value of the first encoding data in the data packet for the image.
For example, when the image compression packet is finally generated from the data group shown in table 2, the minimum bit width value is 1, and the maximum bit width value is 3. Then if both the average bit width and the offset bit width are rounded down, then the bit width is offset:
Figure BDA0003852924020000236
the bit width residual may be determined as follows:
Figure BDA0003852924020000241
then, the second encoded data corresponding to the data set shown in table 2 will be as shown in table 3 below. The second encoded data is then placed in the corresponding location in the image compression packet.
Table 3 correspondence table between partial compressed data and encoded data of certain data group
Figure BDA0003852924020000242
In this way, by further simplifying the occupied bit number codes in the coded data, the numerical values of the occupied bit number codes can be distributed as close to 0 as possible, so that the occupied bit number of the codes is further reduced when the codes are converted into binary.
Further, with respect to the parity packet compression scheme described above, the image compression packet described above may be structured as shown in fig. 4. The image compression data packet sequentially comprises the identification information occupying 4 bytes, the average bit width occupying 4 bytes, the pixel data quantity occupying 6 bytes, the offset bit width occupying 2 bytes and image data (for the condition that all compression data in a data group are encoded, the image data is encoding data; for the condition that the compression data of k pixels except the first pixel in the data group are encoded, the image data is the compression data of the k pixels and the encoding data of the other pixels). The identification information occupying 4 bytes can indicate whether a data group corresponding to the generated image compression data packet is a first data group formed by odd-numbered position pixels or a second data group formed by even-numbered position pixels, and indicate which of three calculation methods is adopted for calculating when pixel data in the data group relates to calculating compression prediction data in the compression process.
If the technical solution provided by the embodiment of the present invention is applied to devices such as an industrial camera, in a communication process between the industrial camera and a connected control device, the transmission of the image may be performed by compressing an original image by using the image compression method, and then sequentially transmitting and transmitting the obtained plurality of image compression data packets.
Then, after the step S170, the method further comprises (not shown in the figure):
and for any image compression data packet, sending the image compression data packet to a receiving device.
In a specific implementation process, a gigabit network Streaming Protocol (GVSP) may be used to send the image compression data packet to the receiving device, and then the image compression data packet may be configured as a structure defined by GVSP.
In a second aspect, based on the same inventive concept, an embodiment of the present invention further provides an image decompression method, configured to decompress an image compressed by using the image compression method of the first aspect into an original image. As shown in fig. 5, includes:
s310, at least one image compression data packet corresponding to the original image is obtained.
And S320, decompressing any image compression data packet to obtain pixel data.
And S330, generating an original image according to the pixel data obtained by decompressing each image compressed data packet.
As shown in fig. 6, for any image compressed data packet, the pixel data is obtained by decompressing the following steps:
s321, determining each compressed data based on the image compressed data packet. Wherein at least part of the compressed data is determined from the encoded data in the image compressed data packet.
In a specific implementation process, if only a part of compressed data in an image compressed data packet is encoded when the image compressed data packet is generated, the part of compressed data can be restored according to encoded data in the compressed data packet. And the rest of the non-encoded compressed data can be directly obtained from the corresponding position in the image compressed data packet if no other processing is performed after the compression (for example, in an embodiment described in the first aspect, only the compressed data of the rest of the pixels except the first k pixels are encoded during the encoding, the compressed data of the first k pixels are directly put into the image compressed data packet, and the compressed data of the first k pixels can be directly obtained during the decompression).
S322, for the jth compressed data, determining the jth compressed data as the jth pixel data.
Where j is a positive integer less than the minimum value of i.
S323, for the ith compressed data, determining the compression mode of the compressed data according to the identification information in the image compressed data packet, and determining the compressed prediction data of the ith pixel data by using the compression mode and according to the ith compressed data and the pixel data corresponding to the k consecutive compressed data before the ith compressed data corresponding to the image compressed data packet.
Wherein i is a positive integer greater than k and less than or equal to n, n is the number of encoded data in the encoded data packet, and k is a positive integer.
S324, judging whether the coding data packet corresponds to the first data group or the second data group.
If the encoded data packet corresponds to the first data group, go to step S325; if the encoded data packet corresponds to the second data group, step S326 is executed.
S325, for the ith compressed data in the first data group, determining the pixel data corresponding to the ith compressed data in the first data group according to the compressed predicted data of the ith pixel data in the first data group and the ith compressed data in the first data group.
S326, for the ith compressed data in the second data group, determining the pixel data corresponding to the ith compressed data in the second data group according to the compressed predicted data of the ith pixel data in the second data group, the ith compressed data in the second data group, and the ith compressed data corresponding to the first data group of the same pixel data set as the second data group.
Further, if the first encoded data of the first aspect is put into the image compressed data packet in the compression process, step S321 determines each compressed data based on the image compressed data packet, which specifically includes:
and acquiring the identification information and the pixel data quantity from the image compressed data packet.
Sequentially acquiring first coded data from the image compressed data packet according to the pixel data quantity;
for any one first encoding data, determining compression data corresponding to the first encoding data by using an entropy encoding table.
Further, if the second encoded data described in the first aspect is put into the image compressed data packet in the compression process, the step S321 of determining each compressed data based on the image compressed data packet specifically includes:
and acquiring the identification information, the average bit width, the offset bit width and the pixel data number from the image compression data packet.
According to the pixel data quantity, sequentially acquiring second coded data from the image compressed data packet;
and determining a bit width residual error according to the average bit width and the offset bit width of the coded data.
For any one second coded data, determining first coded data corresponding to the second coded data according to the bit width residual error; wherein the occupied-bit-number encoding in the first encoded data is equal to the occupied-bit-number encoding in the second encoded data plus the bit-width residual;
and for any one first encoding data, determining the compression data corresponding to the first encoding data by using an entropy encoding table.
In the specific implementation process, the process of restoring the compressed data according to the encoded data is opposite to the process of encoding the compressed data in the compression process described in the first aspect, so that the corresponding content in the first aspect may be referred to for reverse implementation, and details are not described herein.
In a specific implementation process, if the technical solution provided in the embodiments of the present invention is applied to an industrial camera and other devices, in a communication process between the industrial camera and a connected control device, the industrial camera may compress acquired original images by using the image compression method according to the first aspect to obtain image compression data packets, and then sequentially send the image compression data packets to the control device.
Then, if the device performing the image decompression process is the control device, before the step S310, the method further includes (not shown in the figure):
and receiving the image compression data packets in sequence.
In a specific implementation process, the GVSP protocol may be used to send the image compression data packet to the receiving device, and then the encoded data is extracted according to the structure defined by the GVSP when step S321 is executed.
The following is a description of the decompression process of the first data group and the second data group, respectively.
First data set
Further, for the ith compressed data in the first data group in the step S325, determining the pixel data corresponding to the ith compressed data in the first data group according to the compressed predicted data of the ith pixel data in the first data group and the ith compressed data in the first data group, specifically including:
and adding the compression prediction data of the ith pixel data of the first data group and the ith compression data of the first data group to obtain the pixel data corresponding to the ith compression data of the first data group.
(II) second data group
Further, as shown in fig. 7, the step S326, determining, according to the compressed predicted data of the ith pixel data of the second data group, the ith compressed data of the second data group, and the ith compressed data of the first data group of the same pixel data set as the second data group, the pixel data corresponding to the ith compressed data of the second data group, specifically includes:
s3261, determining the compression mode of the compressed data to be a first type compression mode or a second type compression mode according to the identification information in the coded data packet.
If the compression mode is the first type, executing step S3262; if the compression method is the second type of compression method, step S3263 is performed.
S3262, determining pixel data corresponding to the ith pixel data of the second data group according to the compression prediction data of the ith pixel data of the second data group, the ith compression data of the second data group and the ith compression data of the first data group of the same pixel data set as the second data group.
S3263, according to the compression prediction data of the ith pixel data of the second data group and the ith compression data of the second data group, determining the pixel data corresponding to the ith compression data of the second data group, and determining the pixel data corresponding to the ith compression data of the second data group.
Further, the step S3262 specifically includes:
adding the compression prediction data of the ith pixel data of the second data group with the ith compression data in the first data group of the same pixel data set belonging to the second data group, and then subtracting the ith compression data of the second data group to obtain the pixel data corresponding to the ith compression data of the second data group.
Step S3263 specifically includes:
and adding the compression prediction data of the ith pixel data of the second data group and the ith compression data of the second data group to obtain the pixel data corresponding to the ith compression data of the second data group.
Further, in step S323, determining compressed predicted data of the ith pixel data of the first data group according to the ith pixel data of the first data group and k consecutive pixel data before the ith pixel data of the first data group by using the compression method, includes:
if the compression mode is the first compression mode, the compression prediction data of the ith pixel data of the second data group is:
Figure BDA0003852924020000291
if the compression mode is the second compression mode, the compressed prediction data of the ith pixel data of the second data group is:
Figure BDA0003852924020000292
if the compression mode is a third compression mode, the compression prediction data of the ith pixel data of the second data group is:
X′ m (i)=2X m (i-1)-X m (i-2)
where m is the number of the data set, X m (i) Is ith pixel data, X' m (i) Compressed prediction data for the ith pixel data.
In a third aspect, based on the same inventive concept, an embodiment of the present invention further provides an image compression apparatus, as shown in fig. 8, including:
the grouping module M11 is configured to divide at least part of continuous pixel data of an original image into a plurality of pixel data sets according to a rule that every xn pieces of continuous pixel data are divided into one set, and for any pixel data set, evenly distribute the pixel data to x data groups to obtain x data groups corresponding to the pixel data set; wherein n is a positive integer greater than k, k is a positive integer, and x is a positive integer greater than 1;
a prediction module M12, configured to determine, for an ith pixel data in any data group, compressed prediction data of the ith pixel data according to the ith pixel data in the data group and k consecutive pixel data before the ith pixel data in the data group; wherein i is a positive integer greater than k and less than or equal to n;
a first compression module M13, configured to use, for a jth pixel data in any data group, the jth pixel data as compression data corresponding to the jth pixel data; wherein j is a positive integer less than the minimum value of i;
a second compression module M14, configured to determine, for an ith pixel data in any first data group, compressed data of the ith pixel data in the first data group according to compressed prediction data of the ith pixel data in the first data group; wherein for any pixel data set, the first data group is one of the pixel data sets;
a third compression module M15, configured to determine, for an ith pixel data in any second data group, compressed data corresponding to the ith pixel data in the second data group according to difference values between residual data of each pixel data except for the first k pixel data in a first data group belonging to the same set as the second data group and residual data of pixel data at the same position in the second data group; wherein the residual data of any pixel data is the difference between the pixel data and the compressed prediction data of the pixel data; for any pixel data set, the second data set is at least a portion of the data sets of the pixel data set other than the first data set;
and the coding module M16 is used for coding any data group according to the compressed data of the data group to obtain an image compressed data packet.
Optionally, for any pixel data set, evenly distributing the pixel data to x data groups to obtain x data groups corresponding to the pixel data set, including:
and for any pixel data set, distributing the pixel data according to the rule that every continuous x pixel data are sequentially distributed to x data groups to obtain x data groups corresponding to the pixel data set.
Optionally, the third compression module M15 is specifically configured to:
and for the ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to the sum of the occupied bit numbers of the difference values of the residual data of all the pixel data except the first k pixel data in the first data group which belongs to the same pixel data set with the second data group and the residual data of the pixel data at the same position in the second data group.
Optionally, the third compression module M15 is specifically configured to:
if the sum of the occupied bit numbers of the difference values of the residual data of all the pixel data except the first k pieces of pixel data in a first data group which belongs to the same pixel data set with the second data group and the residual data of the pixel data at the same position in the second data group is larger than the sum of the occupied bit numbers of the residual data of all the pixel data except the first k pieces of pixel data in the second data group, regarding the ith pixel data of the second data group, taking the residual data of the ith pixel data of the second data group as the compressed data of the ith pixel data of the second data group;
and if the sum of the occupied bit numbers of the difference values of the residual data of all the pixel data except the first k pixel data in the first data group and the residual data of the pixel data at the same position of k in the second data group in the first data group belonging to the same pixel data set with the second data group is less than or equal to the sum of the occupied bit numbers of the residual data of all the pixel data except the first k pixel data in the second data group, regarding the ith pixel data of the second data group, taking the difference value of the residual data of the ith pixel data of the second data group and the residual data of the ith pixel data of the first data group as the compression data of the ith pixel data of the second data group.
Alternatively, x =2;
dividing at least part of pixel data of an original image into a plurality of pixel data sets according to a rule that every xn continuous pixel data are divided into one set, and the method comprises the following steps:
dividing all pixel data of an original image into a plurality of pixel data sets according to a rule that every 2n continuous pixel data are divided into one set;
for any pixel data set, the first data group is a data group composed of pixel data at odd positions in the pixel data set, and the second data group is a data group composed of pixel data at even positions in the pixel data set.
Optionally, for the ith pixel data, the compressed prediction data of the ith pixel data satisfies the following relation:
Figure BDA0003852924020000311
where m is the number of the data set, X m (i) Is ith pixel data, X' m (i) For the compression prediction data of ith pixel data, delta (i) is determined according to (i-1) th pixel data, (i-2) th pixel data and (i-3) th pixel data in the data group, and a and b are preset values.
Alternatively, Δ (i) satisfies the following relationship:
Δ(i)=||X m (i-2)-X m (i-3)|-|X m (i-1)-X m (i-2)||。
optionally, encoding the compressed data of the data group to obtain an image compressed data packet, including:
encoding at least part of compressed data of the data group by using an entropy encoding table to obtain first encoded data;
determining the average bit width and the offset bit width of all the first coded data, and determining a bit width residual error according to the average bit width and the offset bit width;
for any one first coded data, determining second coded data corresponding to the first coded data; wherein the occupied-bit-number encoding in the second encoded data is equal to the occupied-bit-number encoding in the first encoded data minus the bit-width residual;
and putting the second encoding data, the number of pixel data of the data group, the average bit width and the offset bit width and identification information for indicating a generation mode of compressed data into an image compressed data packet.
Optionally, the second compression module M14 is specifically configured to:
and taking residual error data of the ith pixel data in the first data group as compressed data of the ith pixel data in the first data group.
In a fourth aspect, based on the same inventive concept, an embodiment of the present invention further provides an image decompression apparatus, as shown in fig. 9, including:
an obtaining module M21, configured to obtain at least one image compression data packet corresponding to an original image;
the decompression module M22 is used for decompressing any image compression data packet to obtain pixel data;
the restoring module M23 is used for generating an original image according to pixel data obtained by decompressing each image compression data packet;
the method comprises the following steps of for any image compression data packet, decompressing to obtain pixel data:
determining compressed data based on the image compressed data packet; wherein at least part of the compressed data is determined from the encoded data in the image compressed data packet;
for the jth compressed data, determining the jth compressed data as jth pixel data; wherein j is a positive integer less than the minimum value of i;
for the ith compressed data, determining the compression mode of the compressed data according to the identification information in the image compressed data packet, and determining the compression prediction data of the ith pixel data by using the compression mode and according to the ith compressed data and the pixel data corresponding to k continuous compressed data before the ith compressed data corresponding to the image compressed data packet; wherein i is a positive integer which is greater than k and less than or equal to n, n is the number of the coded data in the coded data packet, and k is a positive integer;
judging whether the coded data packet corresponds to a first data group or a second data group;
if the encoded data packet corresponds to a second data group, determining pixel data corresponding to ith compressed data of the second data group according to the compressed prediction data of the ith pixel data of the second data group, the ith compressed data of the second data group and the ith compressed data corresponding to a first data group of a pixel data set which belongs to the same category as the second data group;
and if the coded data packet corresponds to a first data group, determining pixel data corresponding to ith compressed data of the first data group according to the compressed prediction data of the ith pixel data of the first data group and the ith compressed data of the first data group for the ith compressed data in the first data group.
Optionally, determining, according to the compressed predicted data of the ith pixel data of the second data group, the ith compressed data of the second data group, and the ith compressed data in the first data group of the same pixel data set as the second data group, the pixel data corresponding to the ith compressed data of the second data group specifically includes:
when the compression mode of the compressed data is determined to be a first-class compression mode according to the identification information in the encoding data packet, determining pixel data corresponding to ith compressed data of the second data group according to compressed predicted data of ith pixel data of the second data group, ith compressed data of the second data group and ith compressed data in a first data group of a pixel data set which belongs to the same genus as the second data group;
and when the compression mode of the compressed data is determined to be a second type of compression mode according to the identification information in the encoding data packet, determining pixel data corresponding to ith compressed data of the second data group according to the compression prediction data of ith pixel data of the second data group and ith compressed data of the second data group.
Optionally, determining, according to the compressed predicted data of the ith pixel data of the second data group, the ith compressed data of the second data group, and the ith compressed data in the first data group of the same pixel data set as the second data group, the pixel data corresponding to the ith compressed data of the second data group specifically includes:
when the compression mode of the compressed data is determined to be a first-class compression mode according to the identification information in the encoding data packet, adding the compression prediction data of the ith pixel data of the second data group with the ith compressed data in the first data group of the same pixel data set belonging to the second data group, and subtracting the ith compressed data of the second data group to obtain the pixel data corresponding to the ith compressed data of the second data group;
and when the compression mode of the compressed data is determined to be a second type of compression mode according to the identification information in the encoding data packet, adding the compression prediction data of the ith pixel data of the second data group and the ith compressed data of the second data group to obtain the pixel data corresponding to the ith compressed data of the second data group.
Optionally, determining compressed predicted data of the ith pixel data of the first data group according to the ith pixel data of the first data group and k consecutive pixel data before the ith pixel data of the first data group by using the compression method includes:
if the compression mode is the first compression mode, the compression prediction data of the ith pixel data of the second data group is:
Figure BDA0003852924020000341
if the compression mode is the second compression mode, the compression prediction data of the ith pixel data of the second data group is:
Figure BDA0003852924020000342
if the compression mode is a third compression mode, the compressed prediction data of the ith pixel data of the second data group is:
X′ m (i)=2X m (i-1)-X m (i-2)
where m is the number of the data set, X m (i) Is the ith pixel data, X m (i) Compressed prediction data for the ith pixel data.
Optionally, determining each compressed data based on the image compressed data packet comprises:
acquiring the identification information, the average bit width, the offset bit width and the pixel data quantity from the image compression data packet;
according to the pixel data quantity, sequentially acquiring second coded data from the image compressed data packet;
determining a bit width residual error according to the average bit width and the offset bit width of the coded data;
for any second coded data, determining first coded data corresponding to the second coded data according to the bit width residual error; wherein the occupied-bit-number encoding in the first encoded data is equal to the occupied-bit-number encoding in the second encoded data plus the bit-width residual;
for any one first encoding data, determining compression data corresponding to the first encoding data by using an entropy encoding table.
Optionally, determining, according to the compressed predicted data of the ith pixel data of the first data group and the ith compressed data of the first data group, pixel data corresponding to the ith compressed data of the first data group includes:
and adding the compression prediction data of the ith pixel data of the first data group and the ith compression data of the first data group to obtain the pixel data corresponding to the ith compression data of the first data group.
In the several embodiments provided in the present application, it should be understood that the above-described apparatus embodiments are merely illustrative, for example, the division of the modules is only one logical function division, and there may be other division ways in actual implementation, for example, a plurality of modules or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or modules, and may be in an electrical, mechanical or other form.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical modules, may be located in one position, or may be distributed on a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present application may be integrated into one processing module, or each of the modules may exist alone physically, or two or more modules are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may be stored in a computer readable storage medium.
Since the specific manner in which each module of the image compression apparatus according to the third aspect/the image decompression apparatus according to the fourth aspect performs an operation has been described in detail in the embodiment of the image compression method according to the first aspect/the image decompression method according to the second aspect, it is not described herein again.
In a fifth aspect, based on the same inventive concept, an embodiment of the present invention further provides an electronic device, as shown in fig. 10, including: a processor 110 and a memory 120 for storing instructions executable by the processor 110;
wherein the processor 110 is configured to execute the instructions to implement the image compression method according to the first aspect or to implement the image decompression method according to the second aspect.
In particular implementations, the devices may vary widely due to configuration or performance differences and may include one or more processors 110, memory 120, computer-readable storage medium 130, with one or more applications 131 or data 132 included in the memory 120 and/or computer-readable storage medium 130. The memory 120 and/or computer-readable storage medium 130 may also include one or more operating systems 133 therein, such as Windows, mac OS, linux, IOS, android, unix, freeBSD, and the like. Memory 120 and computer-readable storage medium 130 may be, among other things, transient storage or persistent storage. The application 131 may include one or more of the modules (not shown in fig. 10), each of which may include a series of instruction operations. Still further, the processor 110 may be configured to communicate with the computer-readable storage medium 130, on which a series of instruction operations in the computer-readable storage medium 130 are executed. The apparatus may also include one or more power supplies (not shown in FIG. 10); one or more network interfaces 140, the network interfaces 140 comprising a wired network interface 141 and/or a wireless network interface 142; one or more input/output/interfaces 143.
In a sixth aspect, an embodiment of the present invention further provides an electronic device, which includes an Application Specific Integrated Circuit (ASIC), and the ASIC is used to implement the image compression method according to the first aspect or the image decompression method according to the second aspect.
In a specific implementation process, the ASIC may be designed based on a Complex Programmable Logic Device (CPLD) or a Field Programmable Gate Array (FPGA) Device according to actual needs. ASIC code for performing the image compression/decompression methods provided by embodiments of the present invention, such as Verilog HDL, VHDL, system Verilog, and the like, may be written in any combination of one or more hardware description languages.
For example, the electronic device for implementing the image compression method according to the first aspect may be an industrial camera, and the industrial camera collects compressed images and transmits the compressed images to the control device at the other end of the connection. The circuit based on the FPGA design included in the industrial camera can be as shown in fig. 11, and includes the following circuit functional modules:
a packet Data request module M31, configured to extract image Data with a complete packet length from a Double Data Rate (DDR) memory according to the negotiated GVSP packet length;
and a data prediction module M32 for calculating compressed prediction data and a residual of the pixel data.
And the data encoding module M33 is used for calculating compressed data of the pixel data, calculating a required encoding data bit width and encoding the compressed data.
And the data counting module M34 is responsible for counting the effective data length of a GVSP original data after encoding, and is used as the effective data length of a GVSP data packet.
And the GVSP group packet module M35 is responsible for forming an image compression data packet from GVSP header information, encoded data, effective data length, and other information according to the GVSP packet format.
And a sending module M36, configured to send the image compression data packet to a receiving device.
Because the currently mainly popular lossless compression algorithms such as JPEG-LS, LZ77, RLE and the like need to carry out probability type statistics on data and repeatedly scan the data, the compression process of the data can cause the delay from the triggering of a camera to the image acquisition of the image data to be longer, and the low-delay requirement in the field of industrial detection cannot be met. The data transmission of the Ethernet industrial camera is based on an IPV4/UDP Ethernet transmission protocol, and the image data is a data packet encapsulated according to the GVSSP protocol standard. Compressed data may also be transmitted via the GVSP. The existing lossless compression algorithm is mostly based on multi-line pixels to carry out pixel prediction and whole image residual coding. In the prediction algorithm of the pixel point, prediction is mostly performed based on correlation, and a previous line or surrounding pixels need to be referred to, for example, JPEG-LS, caic algorithm, and the like. When a receiving side decodes a compressed image, the compressed image can be normally decoded only by receiving complete data; considering that the problems of packet error, retransmission, packet loss and the like occur in the transmission process of the network, the waiting time delay of the receiving side is relatively large, and the performance of the system is seriously influenced. Thus, the image compression and decompression method provided by the embodiment of the invention is realized by an ASIC, the image compression process is performed in a pipelining mode through the ASIC, and the time sequence delay of hardware is basically negligible. Correspondingly, for the control device at the receiving end, when the control device adopts the circuit which is designed based on the ASIC and is used for implementing the image decompression method according to the second aspect to decompress the image, only one complete message needs to be cached, and the decoding is completed, that is, the transmission and receiving processes of the data are completed. Thus, only one delay for decoding the data message is added in the whole data transmission process. The scheme provided by the embodiment of the invention can reduce the length of the data message, thereby further reducing the time delay of data transmission time.
Embodiments of the present invention further provide a computer-readable storage medium, where the computer-readable storage medium stores a computer program, where the computer program is used to implement the image compression method according to the first aspect, or implement the image decompression method according to the second aspect.
According to the image compression and decompression method, the image compression and decompression device, the image compression and decompression equipment and the computer readable storage medium, after the pixel data of the original image are grouped, the second data group determines the compressed data of the second data group according to the difference value of the residual error data of the pixel data of the second data group and the residual error data of the pixel data of the first data group, so that the pixel data of the second data group can be further compressed by referring to the color rule of the pixel data of the first data group, and the data volume can be better compressed.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (20)

1. An image compression method, comprising:
dividing at least partial continuous pixel data of an original image into a plurality of pixel data sets according to a rule that every xn continuous pixel data are divided into one set, and for any pixel data set, averagely distributing the pixel data to x data groups to obtain x data groups corresponding to the pixel data sets; wherein n is a positive integer greater than k, k is a positive integer, and x is a positive integer greater than 1;
for ith pixel data in any data group, determining compressed prediction data of the ith pixel data according to the ith pixel data in the data group and k consecutive pixel data before the ith pixel data in the data group; wherein i is a positive integer greater than k and less than or equal to n;
regarding the jth pixel data in any data group, taking the jth pixel data as compressed data corresponding to the jth pixel data; wherein j is a positive integer less than the minimum value of i;
for ith pixel data in any first data group, determining compressed data of the ith pixel data of the first data group according to the compressed prediction data of the ith pixel data of the first data group; wherein for any pixel data set, the first data group is one of the pixel data sets;
for ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to the difference values of residual data of all pixel data except the first k pixel data in the first data group which belongs to the same set with the second data group and residual data of pixel data at the same position in the second data group; wherein the residual data of any pixel data is the difference between the pixel data and the compressed prediction data of the pixel data; for any pixel data set, the second data set is at least a portion of the data sets of the pixel data set other than the first data set;
and coding any data group according to the compressed data of the data group to obtain an image compressed data packet.
2. The method of claim 1, wherein, for any pixel data set, evenly distributing pixel data to x data groups to obtain x data groups corresponding to the pixel data set, comprises:
and for any pixel data set, distributing the pixel data according to a rule that every continuous x pixel data are sequentially distributed to x data groups to obtain x data groups corresponding to the pixel data set.
3. The method of claim 1, wherein determining, for the ith pixel data in any of the second data groups, compressed data corresponding to the ith pixel data in the second data group based on respective differences between residual data of respective pixel data in the first data group except for the first k pixel data in the same set as the second data group and residual data of pixel data at the same position in the second data group comprises:
and for the ith pixel data in any second data group, determining compressed data corresponding to the ith pixel data in the second data group according to the sum of the occupied bit numbers of the difference values of the residual data of all the pixel data except the first k pixel data in the first data group which belongs to the same pixel data set with the second data group and the residual data of the pixel data at the same position in the second data group.
4. The method of claim 3, wherein for the ith pixel data in any second data group, determining the compressed data corresponding to the ith pixel data in the second data group according to the sum of the bit numbers of the differences between the residual data of the pixel data except the first k pixel data in the first data group belonging to the same pixel data set as the second data group and the residual data of the pixel data at the same position in the second data group comprises:
if the sum of the number of occupied bits of the difference values of the residual data of each pixel data except the first k pixel data in a first data group belonging to the same pixel data set as the second data group and the residual data of the pixel data at the same position in the second data group is greater than the sum of the number of occupied bits of the residual data of each pixel data except the first k pixel data in the second data group, regarding the ith pixel data of the second data group, taking the residual data of the ith pixel data of the second data group as the compressed data of the ith pixel data of the second data group;
and if the sum of the number of occupied bits of the difference values of the residual data of all the pixel data except the first k pixel data in the first data group and the residual data of the pixel data at the same position of k in the second data group in the first data group belonging to the same pixel data set with the second data group is less than or equal to the sum of the number of occupied bits of the residual data of all the pixel data except the first k pixel data in the second data group, regarding the ith pixel data of the second data group, taking the difference value of the residual data of the ith pixel data of the second data group and the residual data of the ith pixel data of the first data group as the compression data of the ith pixel data of the second data group.
5. The method of claim 2, wherein x =2;
dividing at least part of pixel data of an original image into a plurality of pixel data sets according to a rule that every xn continuous pixel data are divided into one set, comprising:
dividing all pixel data of an original image into a plurality of pixel data sets according to a rule that every 2n continuous pixel data are divided into one set;
for any pixel data set, the first data group is a data group composed of pixel data at odd positions in the pixel data set, and the second data group is a data group composed of pixel data at even positions in the pixel data set.
6. The method of claim 1, wherein for an ith pixel data, the compressed prediction data for the ith pixel data satisfies the following relationship:
Figure FDA0003852924010000031
where m is the number of the data set, X m (i) Is ith pixel data, X' m (i) And (i) determining the compression prediction data of the ith pixel data according to the (i-1) th pixel data, the (i-2) th pixel data and the (i-3) th pixel data in the data group, wherein a and b are preset values.
7. The method of claim 6, wherein Δ (i) satisfies the relationship:
△(i)=||X m (i-2)-X m (i-3)|-|X m (i-1)-X m (i-2)||。
8. the method of claim 1, wherein encoding the compressed data of the data group to obtain an image compressed data packet comprises:
encoding at least part of compressed data of the data group by using an entropy encoding table to obtain first encoded data;
determining the average bit width and the offset bit width of all the first coded data, and determining a bit width residual error according to the average bit width and the offset bit width;
for any one first coded data, determining second coded data corresponding to the first coded data; wherein the occupied-bit-number encoding in the second encoded data is equal to the occupied-bit-number encoding in the first encoded data minus the bit-width residual;
and putting the second encoding data, the number of pixel data of the data group, the average bit width and the offset bit width and identification information for indicating a generation mode of compressed data into an image compressed data packet.
9. The method of claim 1, wherein determining compressed data for an ith pixel data of the first data set from compressed predicted data for an ith pixel data of the first data set comprises:
and taking residual data of the ith pixel data in the first data group as compressed data of the ith pixel data in the first data group.
10. An image decompression method, comprising:
acquiring at least one image compression data packet corresponding to an original image;
decompressing any image compression data packet to obtain pixel data;
generating an original image according to pixel data obtained by decompressing each image compressed data packet;
the method comprises the following steps of for any image compression data packet, decompressing to obtain pixel data:
determining each compressed data based on the image compressed data packet; wherein at least part of the compressed data is determined from the encoded data in the image compressed data packet;
for the jth compressed data, determining the jth compressed data as jth pixel data; wherein j is a positive integer less than the minimum value of i;
for the ith compressed data, determining the compression mode of the compressed data according to the identification information in the image compressed data packet, and determining the compression prediction data of the ith pixel data by using the compression mode and according to the ith compressed data and the pixel data corresponding to k continuous compressed data before the ith compressed data corresponding to the image compressed data packet; wherein i is a positive integer greater than k and less than or equal to n, n is the number of encoded data in the encoded data packet, and k is a positive integer;
judging whether the coded data packet corresponds to a first data group or a second data group;
if the encoded data packet corresponds to a second data group, for ith compressed data in the second data group, determining pixel data corresponding to the ith compressed data in the second data group according to the compression prediction data of the ith pixel data in the second data group, the ith compressed data in the second data group and the ith compressed data corresponding to a first data group of a pixel data set which belongs to the same genus as the second data group;
and if the coded data packet corresponds to a first data group, determining pixel data corresponding to ith compressed data of the first data group according to the compressed prediction data of the ith pixel data of the first data group and the ith compressed data of the first data group for the ith compressed data in the first data group.
11. The method of claim 10, wherein determining the pixel data corresponding to the ith compressed data of the second data group based on the compressed predicted data of the ith pixel data of the second data group, the ith compressed data of the second data group, and the ith compressed data of the first data group belonging to the same set of pixel data as the second data group specifically comprises:
when the compression mode of the compressed data is determined to be a first-class compression mode according to the identification information in the encoding data packet, determining pixel data corresponding to ith compressed data of the second data group according to compressed predicted data of ith pixel data of the second data group, ith compressed data of the second data group and ith compressed data in a first data group of a pixel data set which belongs to the same genus as the second data group;
and when the compression mode of the compressed data is determined to be a second type of compression mode according to the identification information in the encoding data packet, determining pixel data corresponding to the ith compressed data of the second data group according to the compression prediction data of the ith pixel data of the second data group and the ith compressed data of the second data group.
12. The method of claim 11, wherein determining the pixel data corresponding to the ith compressed data of the second data group according to the compressed predicted data of the ith pixel data of the second data group, the ith compressed data of the second data group, and the ith compressed data of the first data group belonging to the same pixel data set as the second data group comprises:
when the compression mode of the compressed data is determined to be a first-class compression mode according to the identification information in the encoding data packet, adding the compression prediction data of the ith pixel data of the second data group with the ith compressed data in the first data group of the same pixel data set belonging to the second data group, and then subtracting the ith compressed data of the second data group to obtain the pixel data corresponding to the ith compressed data of the second data group;
and when the compression mode of the compressed data is determined to be a second type of compression mode according to the identification information in the encoding data packet, adding the compression prediction data of the ith pixel data of the second data group and the ith compressed data of the second data group to obtain the pixel data corresponding to the ith compressed data of the second data group.
13. The method of claim 10, wherein determining compressed predicted data for an ith pixel data of the first data set using the compression scheme and based on the ith pixel data of the first data set and k consecutive pixel data preceding the ith pixel data of the first data set comprises:
if the compression mode is the first compression mode, the compressed prediction data of the ith pixel data of the second data group is:
Figure FDA0003852924010000061
if the compression mode is the second compression mode, the compressed prediction data of the ith pixel data of the second data group is:
Figure FDA0003852924010000062
if the compression mode is a third compression mode, the compression prediction data of the ith pixel data of the second data group is:
X′ m (i)=2X m (i-1)-X m (i-2)
where m is the number of the data set, X m (i) Is ith pixel data, X' m (i) Compressed prediction data for the ith pixel data.
14. The method of claim 10, wherein determining each compressed data based on the image compressed data packet comprises:
acquiring the identification information, the average bit width, the offset bit width and the pixel data number from the image compression data packet;
according to the pixel data quantity, sequentially acquiring second coded data from the image compressed data packet;
determining a bit width residual error according to the average bit width and the offset bit width of the coded data;
for any second coded data, determining first coded data corresponding to the second coded data according to the bit width residual error; wherein the occupied-bit-number encoding in the first encoded data is equal to the occupied-bit-number encoding in the second encoded data plus the bit-width residual;
and for any one first encoding data, determining the compression data corresponding to the first encoding data by using an entropy encoding table.
15. The method of claim 10, wherein determining pixel data corresponding to an ith pixel data of the first data group from the compressed predicted data of the ith pixel data of the first data group and the ith compressed data of the first data group comprises:
and adding the compression prediction data of the ith pixel data of the first data group and the ith compression data of the first data group to obtain the pixel data corresponding to the ith compression data of the first data group.
16. An image compression apparatus, comprising:
the grouping module is used for dividing at least part of continuous pixel data of an original image into a plurality of pixel data sets according to a rule that every xn continuous pixel data are divided into one set, and for any pixel data set, averagely distributing the pixel data to x data groups to obtain x data groups corresponding to the pixel data sets; wherein n is a positive integer greater than k, k is a positive integer, and x is a positive integer greater than 1;
the prediction module is used for determining compressed prediction data of ith pixel data in any data group according to the ith pixel data in the data group and k continuous pixel data before the ith pixel data in the data group; wherein i is a positive integer greater than k and less than or equal to n;
the first compression module is used for taking the jth pixel data in any data group as compressed data corresponding to the jth pixel data; wherein j is a positive integer less than the minimum value of i;
the second compression module is used for determining the compression data of the ith pixel data of any first data group according to the compression prediction data of the ith pixel data of the first data group; wherein for any pixel data set, the first data set is one of the pixel data sets;
a third compression module, configured to determine, for an ith pixel data in any second data group, compressed data corresponding to the ith pixel data in the second data group according to difference values between residual data of each pixel data, except for the first k pixel data, in a first data group that belongs to the same set as the second data group, and residual data of pixel data at the same position in the second data group; wherein the residual data of any pixel data is the difference between the pixel data and the compressed prediction data of the pixel data; for any pixel data set, the second data group is at least a portion of the data groups in the pixel data set other than the first data group;
and the coding module is used for coding any data group according to the compressed data of the data group to obtain an image compressed data packet.
17. An image decompression apparatus, characterized by comprising:
the acquisition module is used for acquiring at least one image compression data packet corresponding to an original image;
the decompression module is used for decompressing any image compression data packet to obtain pixel data;
the restoration module is used for generating an original image according to pixel data obtained by decompressing each image compression data packet;
the method comprises the following steps of decompressing any image compression data packet to obtain pixel data:
determining compressed data based on the image compressed data packet; wherein at least part of the compressed data is determined from the encoded data in the image compression data packet;
for the jth compressed data, determining the jth compressed data as jth pixel data; wherein j is a positive integer less than the minimum value of i;
for the ith compressed data, determining the compression mode of the compressed data according to the identification information in the image compressed data packet, and determining the compressed prediction data of the ith pixel data by using the compression mode and according to the ith compressed data and the pixel data corresponding to k continuous compressed data before the ith compressed data corresponding to the image compressed data packet; wherein i is a positive integer which is greater than k and less than or equal to n, n is the number of the coded data in the coded data packet, and k is a positive integer;
judging whether the coded data packet corresponds to a first data group or a second data group;
if the encoded data packet corresponds to a second data group, for ith compressed data in the second data group, determining pixel data corresponding to the ith compressed data in the second data group according to the compression prediction data of the ith pixel data in the second data group, the ith compressed data in the second data group and the ith compressed data corresponding to a first data group of a pixel data set which belongs to the same genus as the second data group;
and if the coded data packet corresponds to a first data group, determining pixel data corresponding to ith compressed data of the first data group according to the compressed prediction data of the ith pixel data of the first data group and the ith compressed data of the first data group for the ith compressed data in the first data group.
18. An electronic device, comprising: a processor and a memory for storing processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the image compression method of any one of claims 1-9 or to implement the image decompression method of any one of claims 10-15.
19. An electronic device, characterized in that it comprises an application specific integrated circuit, which is used to implement the image compression method according to any one of claims 1 to 9, or to implement the image decompression method according to any one of claims 10 to 15.
20. A computer-readable storage medium, characterized in that it stores a computer program for implementing the image compression method according to any one of claims 1-9, or implementing the image decompression method according to any one of claims 10-15.
CN202211139550.2A 2022-09-19 2022-09-19 Image compression and decompression method, device, equipment and computer readable storage medium Pending CN115802050A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211139550.2A CN115802050A (en) 2022-09-19 2022-09-19 Image compression and decompression method, device, equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211139550.2A CN115802050A (en) 2022-09-19 2022-09-19 Image compression and decompression method, device, equipment and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN115802050A true CN115802050A (en) 2023-03-14

Family

ID=85432028

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211139550.2A Pending CN115802050A (en) 2022-09-19 2022-09-19 Image compression and decompression method, device, equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN115802050A (en)

Similar Documents

Publication Publication Date Title
CN102369522B (en) The parallel pipeline formula integrated circuit of computing engines realizes
JP2672382B2 (en) Synchronous method for the transmission of a sequence of images encoded by a variable length code on an asynchronous channel, and an apparatus for the implementation of this method
CN101039374B (en) Image lossless compression method
CN116723337B (en) HDMI high definition data optimized transmission method and system
WO2018103452A1 (en) Method and device for encoding and decoding information bitmap, and storage medium
CN107105208A (en) A kind of lossless coding and coding/decoding method of Bayer images
WO2021031877A1 (en) Methods and apparatus for image coding and decoding, and chip
CN106656195A (en) Data compression decompression method and data compression decompression system
CN107018419A (en) A kind of image compression encoding method based on AMBTC
CN111131828A (en) Image compression method and device
CN103124350A (en) Image compression method and device based on run-length encoding (RLE)
CN100586182C (en) Apparatus and method for image processing, compression, decompression, transfer, transmission and reception, and display device
US20140015698A1 (en) System and method for fixed rate entropy coded scalar quantization
CN115802050A (en) Image compression and decompression method, device, equipment and computer readable storage medium
CN105163122A (en) Image compression and decompression method based on similarity of image blocks
US8175403B1 (en) Iterative backward reference selection with reduced entropy for image compression
US5699122A (en) Method and apparatus for encoding a video signal by using a modified block truncation coding method
CN116170596A (en) Encoding and decoding method and electronic equipment
CN110855990B (en) Image encoding method, image decoding method, computer device, and image processing system
CN112055223A (en) Image coding and decoding method and coder-decoder
CN106131575A (en) The method for compressing image combined with Chinese remainder theorem based on wavelet transformation
WO2023169190A1 (en) Encoding and decoding method, and electronic device
KR20210091657A (en) Method of encoding and decoding image contents and system of transferring image contents
KR102523959B1 (en) Image processing device and method for operating image processing device
JPH08265370A (en) Error detection device of packet exchanger

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