Disclosure of Invention
The invention aims to provide a method for compressing and storing two-dimensional stream data in any shape, thereby solving the problems in the prior art.
In order to achieve the purpose, the technical scheme adopted by the invention is as follows:
a two-dimensional stream data compression storage method of arbitrary shape comprises the following steps,
s1, setting a parameter T, extracting a segment with a length T from the current two-dimensional stream data, where the segment is denoted as Seq ═ Amxn (T ═ 1), Amxn (T ═ 2), Amxn (T ═ 3), …, Amxn (T ═ T) >, randomly extracting K times { r1, r2, …, rk } from times {1,2,3, …, T } included in the two-dimensional stream data Seq, and extracting two-dimensional data frames corresponding to these times from the two-dimensional stream data Seq according to the K times to form a two-dimensional data frame set Seqk ═ Amxn (T ═ r1), Amxn (T ═ r2), Amxn (T ═ r3), …, Amxn (T ═ rk) >;
where mxn is the size of the two-dimensional data frame; a is a frame of two-dimensional data;
s2, performing pairwise difference between any two adjacent two-dimensional data frames in the two-dimensional data frame set Seqk, and obtaining a difference matrix set Sub (Sub2, Sub3, …, Sub) including K-1 difference matrices;
Subi=|Amxn(t=ri-1)-Amxn(t=ri)|
Subi(a,b)=|Amxn(t=ri-1)(a,b)-Amxn(t=ri)(a,b)|
wherein Subi (a, b) is the row a and column b elements of the difference matrix Subi; amxn (t-ri-1) (a, b) is the row a, column b element of the two-dimensional data frame Amxn (t-ri-1); amxn (t ═ ri) (a, b) is the row a, column b element of the two-dimensional data frame Amxn (t ═ ri);
s3, summing the difference matrix set Sub to obtain a Sum matrix Sum;
Sum=Sub2+Sub3+…+Subk
Sum(a,b)=Sub2(a,b)+Sub3(a,b)+…+Subk(a,b)
wherein Subi (a, b) is the row a and column b elements of the difference matrix Subi; sum (a, b) is the row a, column b element of the Sum matrix;
s4, acquiring a steady-state area with any shape in the two-dimensional stream data Seq by using the element with the value of 0 in the Sum matrix Sum; acquiring a rheological area with any shape in the two-dimensional stream data Seq by using elements with the numerical value of the Sum matrix Sum being not 0;
and S5, realizing the partition compression of the two-dimensional stream data Seq by utilizing the steady-state area and the rheological area in the identified two-dimensional stream data Seq.
Preferably, step S5 includes the following,
s51, constructing a compression mother matrix ZIP by using the Sum matrix Sum;
setting the Count to be 0, and performing two-dimensional scanning on a Sum matrix Sum according to a from 1 to m and b from 1 to n; if the row a and column b elements of the Sum matrix Sum are not equal to 0, Count is equal to Count +1, and the row a and column b elements of the compression mother matrix ZIP are equal to Count; if the row a and column b elements of the Sum matrix Sum are equal to 0, the row a and column b elements of the compression mother matrix ZIP are equal to 0;
and the number of the elements of which the median value is greater than 0 in the compressed mother matrix ZIP is equal to the number of the elements of which the median value is greater than 0 after the compressed mother matrix ZIP is constructed, and the number is marked as Q.
S52, compressing the two-dimensional stream data Seq using the compression mother matrix ZIP to obtain compressed two-dimensional stream data YSeq, YSeq ═ YA (T ═ 1), YA (T ═ 2), YA (T ═ 3), …, YA (T ═ T) >;
where YA (t ═ 1) ═ Amxn (t ═ 1) is a two-dimensional array of size equal to mxn;
YA (t ═ 2) is a one-dimensional array of length Q; the method for setting each element value in YA (t ═ 2) is as follows:
performing two-dimensional scanning on the compressed mother matrixes ZIP and Amxn (t is 2) simultaneously according to the sequence of a from 1 to m and b from 1 to n;
if the element of the current position (a, b) of the compressed parent matrix ZIP is Count (Count is greater than 0), assigning the element value of the same position (a, b) in Amxn (t ═ 2) to the Count-th element in YA (t ═ 2);
analogizing YA (T ═ 2), obtaining YA (T ═ 3), …, YA (T ═ T) from compression mother matrices ZIP and Amxn (T ═ 3), …, Amxn (T ═ T);
s53, deleting the two-dimensional stream data Seq, and storing a compressed mother matrix ZIP and the compressed two-dimensional stream data YSeq;
s54, when the two-dimensional stream data Seq is needed, the stored compressed mother matrix ZIP and the compressed two-dimensional stream data YSeq are read to restore the data.
Preferably, the specific process of restoring the original two-dimensional stream data Seq using the stored compressed mother matrix ZIP and the compressed two-dimensional stream data YSeq is,
let Amxn (T ═ 1), Amxn (T ═ 2), Amxn (T ═ 3), …, Amxn (T ═ T) be a two-dimensional array of size mxn in the original two-dimensional stream data Seq;
the first two-dimensional data Amxn (t ═ 1) is equal to YA (t ═ 1), that is, Amxn (t ═ 1) ═ YA (t ═ 1);
the element value of the second two-dimensional data Amxn (t ═ 2) is set by:
two-dimensional scanning is carried out on the compressed mother matrix ZIP according to the sequence that a is from 1 to m and b is from 1 to n;
if the element value of the current position (a, b) of the compression parent matrix ZIP is 0, assigning the element value of the same position (a, b) in Amxn (t ═ 1) to the element in the same position (a, b) in Amxn (t ═ 2);
if the element value of the current position (a, b) of the compressed mother matrix ZIP is Count (Count is greater than 0), assigning the element value of the Count in YA (t ═ 2) to the element in the same position (a, b) in Amxn (t ═ 2);
analogizing Amxn (T ═ 2), Amxn (T ═ 3), …, Amxn (T ═ T) are obtained from Amxn (T ═ 1), compression mother matrices ZIP and YA (T ═ 3), …, YA (T ═ T).
Preferably, the value of K is
If K is equal to T, the compression is lossless compression; if K is less than T, it indicates that the compression is lossy compression.
Preferably, the value T in step S1 can be dynamically adjusted according to the minimum compression ratio ZR required by the user, and the adjusting process is,
any given initial value of T;
calculating a compression rate ZRC under the current T value, if the ZRC is lower than ZR, reducing the T value by 10%, namely T is Tx0.9, and performing data compression of the next round; if ZR is higher than ZR, the value of T is increased by 10%, i.e., T is tx1.1, and the next round of data compression is performed.
Preferably, the compression ratio ZRC at the current value of T is calculated by,
for original two-dimensional stream data Seq, Txmxn data points exist when not compressed;
the compressed mother matrix ZIP has mxn data points; YA (t ═ 1) has mxn data points; YA (T ═ 2), YA (T ═ 3), …, YA (T ═ T) share Qx (T-1) data points; the compressed two-dimensional stream data Seq has 2xmxn + Qx (T-1) data points;
the compression ratio is zr ═ 2xmxn + Qx (T-1) ]/(Txmxn).
The invention has the beneficial effects that: 1. by processing the two-dimensional stream data, a steady-state area and a rheological area in the two-dimensional data are identified, the partition compression of the two-dimensional data stream is realized, and the compression rate is improved. 2. By adjusting the time parameter, lossless compression and lossy compression can be simultaneously realized, and the method can adapt to various different compression scenes.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating the invention, are intended for purposes of illustration only and are not intended to limit the scope of the invention.
As shown in fig. 1, in the present embodiment, there is provided a two-dimensional stream data compression storage method in an arbitrary shape, including the following steps,
s1, setting a parameter T, extracting a segment with a length T from the current two-dimensional stream data, where the segment is denoted as Seq ═ Amxn (T ═ 1), Amxn (T ═ 2), Amxn (T ═ 3), …, Amxn (T ═ T) >, randomly extracting K times { r1, r2, …, rk } from times {1,2,3, …, T } included in the two-dimensional stream data Seq, and extracting two-dimensional data frames corresponding to these times from the two-dimensional stream data Seq according to the K times to form a two-dimensional data frame set Seqk ═ Amxn (T ═ r1), Amxn (T ═ r2), Amxn (T ═ r3), …, Amxn (T ═ rk) >;
where mxn is the size of the two-dimensional data frame; a is a frame of two-dimensional data;
s2, performing pairwise difference between any two adjacent two-dimensional data frames in the two-dimensional data frame set Seqk, and obtaining a difference matrix set Sub (Sub2, Sub3, …, Sub) including K-1 difference matrices;
Subi=|Amxn(t=ri-1)-Amxn(t=ri)|
Subi(a,b)=|Amxn(t=ri-1)(a,b)-Amxn(t=ri)(a,b)|
wherein Subi (a, b) is the row a and column b elements of the difference matrix Subi; amxn (t-ri-1) (a, b) is the row a, column b element of the two-dimensional data frame Amxn (t-ri-1); amxn (t ═ ri) (a, b) is the row a, column b element of the two-dimensional data frame Amxn (t ═ ri);
s3, summing the difference matrix set Sub to obtain a Sum matrix Sum;
Sum=Sub2+Sub3+…+Subk
Sum(a,b)=Sub2(a,b)+Sub3(a,b)+…+Subk(a,b)
wherein Subi (a, b) is the row a and column b elements of the difference matrix Subi; sum (a, b) is the row a, column b element of the Sum matrix;
s4, acquiring a steady-state area with any shape in the two-dimensional stream data Seq by using the element with the value of 0 in the Sum matrix Sum; acquiring a rheological area with any shape in the two-dimensional stream data Seq by using elements with the numerical value of the Sum matrix Sum being not 0;
and S5, realizing the partition compression of the two-dimensional stream data Seq by utilizing the steady-state area and the rheological area in the identified two-dimensional stream data Seq.
In this embodiment, step S5 includes the following steps,
s51, constructing a compression mother matrix ZIP by using the Sum matrix Sum;
setting the Count to be 0, and performing two-dimensional scanning on a Sum matrix Sum according to a from 1 to m and b from 1 to n; if the row a and column b elements of the Sum matrix Sum are not equal to 0, Count is equal to Count +1, and the row a and column b elements of the compression mother matrix ZIP are equal to Count; if the row a and column b elements of the Sum matrix Sum are equal to 0, the row a and column b elements of the compression mother matrix ZIP are equal to 0;
and the number of the elements of which the median value is greater than 0 in the compressed mother matrix ZIP is equal to the number of the elements of which the median value is greater than 0 after the compressed mother matrix ZIP is constructed, and the number is marked as Q.
S52, compressing the two-dimensional stream data Seq using the compression mother matrix ZIP to obtain compressed two-dimensional stream data YSeq, YSeq ═ YA (T ═ 1), YA (T ═ 2), YA (T ═ 3), …, YA (T ═ T) >;
where YA (t ═ 1) ═ Amxn (t ═ 1) is a two-dimensional array of size equal to mxn;
YA (t ═ 2) is a one-dimensional array of length Q; the method for setting each element value in YA (t ═ 2) is as follows:
performing two-dimensional scanning on the compressed mother matrixes ZIP and Amxn (t is 2) simultaneously according to the sequence of a from 1 to m and b from 1 to n;
if the element of the current position (a, b) of the compressed parent matrix ZIP is Count (Count is greater than 0), assigning the element value of the same position (a, b) in Amxn (t ═ 2) to the Count-th element in YA (t ═ 2);
analogizing YA (T ═ 2), obtaining YA (T ═ 3), …, YA (T ═ T) from compression mother matrices ZIP and Amxn (T ═ 3), …, Amxn (T ═ T);
s53, deleting the two-dimensional stream data Seq, and storing a compressed mother matrix ZIP and the compressed two-dimensional stream data YSeq;
s54, when the two-dimensional stream data Seq is needed, the stored compressed mother matrix ZIP and the compressed two-dimensional stream data YSeq are read to restore the data.
The specific process of recovering the original two-dimensional stream data Seq by using the stored compressed mother matrix ZIP and the compressed two-dimensional stream data YSeq is,
let Amxn (T ═ 1), Amxn (T ═ 2), Amxn (T ═ 3), …, Amxn (T ═ T) be a two-dimensional array of size mxn in the original two-dimensional stream data Seq;
the first two-dimensional data Amxn (t ═ 1) is equal to YA (t ═ 1), that is, Amxn (t ═ 1) ═ YA (t ═ 1);
the element value of the second two-dimensional data Amxn (t ═ 2) is set by:
two-dimensional scanning is carried out on the compressed mother matrix ZIP according to the sequence that a is from 1 to m and b is from 1 to n;
if the element value of the current position (a, b) of the compression parent matrix ZIP is 0, assigning the element value of the same position (a, b) in Amxn (t ═ 1) to the element in the same position (a, b) in Amxn (t ═ 2);
if the element value of the current position (a, b) of the compressed mother matrix ZIP is Count (Count is greater than 0), assigning the element value of the Count in YA (t ═ 2) to the element in the same position (a, b) in Amxn (t ═ 2);
analogizing Amxn (T ═ 2), Amxn (T ═ 3), …, Amxn (T ═ T) are obtained from Amxn (T ═ 1), compression mother matrices ZIP and YA (T ═ 3), …, YA (T ═ T).
In this embodiment, if K is equal to T, the compression of the present invention is lossless compression; if K is smaller than T, the compression of the patent is lossy compression; the smaller K, the greater the data distortion and the higher the compression ratio. To balance data distortion and compression ratio, it is proposed that K be set to the root T; namely, it is
Since the stream data can be assumed to be endless, T can be made very large. The larger T, the smaller the stability zone is clearly identified and the larger the rheological zone, so it is recommended that T need not be too large, for example 1000. By setting smaller T, the streaming data can be compressed in segments, and the compression rate is improved.
The value of T can be dynamically adjusted according to the lowest compression ratio ZR required by a user, the adjusting process is,
any given initial value of T; such as 100;
calculating a compression rate ZRC under the current T value, if the ZRC is lower than ZR, reducing the T value by 10%, namely T is Tx0.9, and performing data compression of the next round; the purpose of this step is: by reducing the length of the two-dimensional flow data fragment, the local data repetition probability is improved, and the data compression rate can be increased;
if ZRC is higher than ZR, increasing the value of T by 10%, namely T is Tx1.1, and performing the next round of data compression; the purpose of this step is: by increasing the length of the two-dimensional stream data fragment, the number of compressed parent matrixes ZIP is reduced, and the storage space is saved.
In this embodiment, if the two-dimensional stream data Seq is not compressed, < Amxn (T ═ 1), Amxn (T ═ 2), Amxn (T ═ 3), …, Amxn (T ═ T) >, Seq has Txmxn data points; according to the compression method of the present invention, it is only necessary to store the compressed mother matrix ZIP and the compressed two-dimensional stream data YSeq ═ YA (T ═ 1), YA (T ═ 2), YA (T ═ 3), …, YA (T ═ T) >.
Specifically, with the compression method of the present invention, the compression ratio ZRC under the current T value is calculated by,
for original two-dimensional stream data Seq, Txmxn data points exist when not compressed;
the compressed mother matrix ZIP has mxn data points; YA (t ═ 1) has mxn data points; YA (T ═ 2), YA (T ═ 3), …, YA (T ═ T) share Qx (T-1) data points; the compressed two-dimensional stream data Seq has 2xmxn + Qx (T-1) data points;
the compression ratio is zr ═ 2xmxn + Qx (T-1) ]/(Txmxn).
When the method of the invention is applied to realize compression storage of remote sensing image data, if the amount of sensor univariate flow data is 10000 data points for example, a 100x100 two-dimensional frame can be constructed by the method of the invention and then compressed for storage.
By adopting the technical scheme disclosed by the invention, the following beneficial effects are obtained:
the invention provides a two-dimensional stream data compression and storage method in any shape, which is characterized in that a stable area and a rheological area in two-dimensional data are identified by processing the two-dimensional stream data, so that the partition compression of the two-dimensional data stream is realized, and the compression rate is improved. By adjusting the time parameter, lossless compression and lossy compression can be simultaneously realized, and the method can adapt to various different compression scenes.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements should also be considered within the scope of the present invention.