Summary of the invention
The technical problem that (one) will solve
The object of the present invention is to provide a kind of compression method and device of Bayer format-pattern, utilize the characteristics of Bayer format-pattern at color space, under the prerequisite of low algorithm complex and high reduction picture quality, can provide higher image compression rate.
(2) technical scheme
The invention provides a kind of compression method of Bayer format-pattern, comprising: S1. classifies and is rearranged into three-dimensional matrice according to the R-G1-G2-B space the described Bayer format-pattern pixel collected; S2. the described three-dimensional matrice rearranged is carried out to the three-dimensional orthogonal conversion and obtain matrix of frequency coefficients; S3. described matrix of frequency coefficients is carried out to quantification treatment, then the matrix of frequency coefficients after layout quantification treatment again it is carried out to the entropy coding, the component frame data.
Preferably, described step S1 comprises: S101. classifies to the described Bayer format-pattern pixel collected according to color space, is divided into R, G1, G2, tetra-parts of B; S102. the pixel of each part of take is a figure layer, folded at the enterprising windrow of direction perpendicular to the figure layer, forms three-dimensional matrice.
Preferably, described step S2 comprises: S201. is to rearranging the described three-dimensional matrice piecemeal obtained, the square of L * L * H of take carries out the three-dimensional orthogonal conversion and obtains described matrix of frequency coefficients as unit, wherein L is figure layer plane number of lines of pixels or columns, and H is the number of pixels of vertical view layer plane.
Preferably, L=H=4, or L=8, H=4, described orthogonal transform is one or more in discrete cosine transform and integer transform.
Preferably, for, the expression formula of the described three-dimensional orthogonal conversion of L=H=4 situation is:
Wherein, M
x, M
y, M
zMean transformation matrix.
Preferably, for described square, be 4 * 4 * 4 situations, the transformation matrix of described integer transform is:
Preferably, described step S3 comprises: S301. carries out quantification treatment according to default quantization table matrix to described matrix of frequency coefficients, and establishing matrix of frequency coefficients is F, and quantized result is F
Q, the quantization table matrix is Q, and " ⊙ " represents that the element of matrix correspondence position is divided by, and the expression formula of quantification is: F
Q=F ⊙ Q; S302. by the three-dimensional matrix of frequency coefficients layout after quantification treatment, be one-dimensional vector; S303. contrast the entropy coding schedule described one-dimensional vector is carried out to the entropy coding; S304. by the matrix of frequency coefficients component frame data after the entropy coding.
Preferably, described quantization table matrix is:
Wherein, Q (i) means the i layer of Q, i=1,2,3,4.
Preferably, three-dimensional each component of matrix of frequency coefficients matrix is lower according to frequency component, the principle that sorting position is more forward, layout is one-dimensional vector; For stating square, be 4 * 4 * 4 situations, establish F
Q(i, j, k) represents F
QI capable, j row, k layer element, its preferred sortord is:
[F
Q(1,1,1),F
Q(1,1,2),F
Q(1,1,3),F
Q(1,2,1),F
Q(2,1,1,),F
Q(1,2,2),F
Q(2,1,2)F
Q(1,3,1),F
Q(2,2,1),F
Q(3,1,1),F
Q(1,1,4),F
Q(1,2,3),F
Q(2,1,3),F
Q(1,3,2),F
Q(2,2,2),F
Q(3,1,2),F
Q(1,4,1),F
Q(2,3,1),F
Q(3,2,1),F
Q(4,1,1),F
Q(1,2,4),F
Q(2,1,4),F
Q(1,3,3),F
Q(2,2,3),F
Q(3,1,3),F
Q(1,4,2),F
Q(2,3,2),F
Q(3,2,2),F
Q(4,1,2),F
Q(2,4,1),F
Q(3,3,1),F
Q(4,2,1),F
Q(1,3,4),F
Q(2,2,4),F
Q(3,1,4),F
Q(1,4,3),F
Q(2,3,3),F
Q(3,2,3),F
Q(4,1,3)F
Q(2,4,2),F
Q(3,3,2),F
Q(4,2,2),F
Q(3,4,1),F
Q(4,3,1),F
Q(1,4,4),F
Q(2,3,4),F
Q(3,2,4),F
Q(4,1,4),F
Q(2,4,3),F
Q(3,3,3),F
Q(4,2,3),F
Q(3,4,2),F
Q(4,3,2),F
Q(4,4,1),F
Q(2,4,4),F
Q(3,3,4),F
Q(4,2,4),F
Q(3,4,3),F
Q(4,3,4),F
Q(4,4,2),F
Q(3,4,4),F
Q(4,3,4),F
Q(4,4,3),F
Q(4,4,4)]。
The present invention also provides a kind of compression set of Bayer format-pattern, comprising: first module, and for the described Bayer format-pattern pixel to collecting, classify and be rearranged into three-dimensional matrice; Second unit, carry out the three-dimensional orthogonal conversion for the described three-dimensional matrice to rearranging and obtain matrix of frequency coefficients; Unit the 3rd, for described matrix of frequency coefficients is carried out to quantification treatment, the matrix of frequency coefficients after layout quantification treatment again it is carried out to the entropy coding, the component frame data then.
(3) beneficial effect
At first the compression method of a kind of Bayer format-pattern of the present invention carries out the classification of color space to view data and is rearranged into 3 dimension matrixes, next obtains resetting the matrix of frequency coefficients of 3 orthogonal dimension conversion of matrix, then, again the matrix of frequency coefficients after layout quantification treatment is also carried out the entropy coding to it, frame data the reconstructed image of finally decoding and being comprised of the matrix of frequency coefficients after the entropy coding.Method for compressing image of the present invention, utilized the characteristics of Bayer format-pattern at color space, under the prerequisite of low algorithm complex and high reduction picture quality, can provide very high image compression rate; Therefore, the present invention provides strong technical support for acquisition and the processing of medical image.
Embodiment
For the purpose, technical scheme and the advantage that make the embodiment of the present invention clearer, below in conjunction with the accompanying drawing in the embodiment of the present invention, technical scheme in the embodiment of the present invention is carried out to clear, complete description, obviously, described embodiment is a part of embodiment of the present invention, rather than whole embodiment.Based on the embodiment in the present invention, those of ordinary skills, not making under the creative work prerequisite the every other embodiment obtained, belong to the scope of protection of the invention.
As shown in Figure 2, the compression method of a kind of Bayer format-pattern provided by the invention mainly comprises the following steps:
S1. the described Bayer format-pattern pixel collected is classified and is rearranged into three-dimensional matrice according to the R-G1-G2-B space; This step mainly comprises:
S101. according to color space, the described Bayer format-pattern pixel collected is classified, be divided into R, G1, G2, tetra-parts of B; In the present embodiment with R-G1-G2-B (Red, Green1, Green2, the Blue of bayer image, RGB) four color spaces are for illustrating according to classifying: the data of obtaining initial pictures, original data is the view data meaned with the R-G-B color mode, each pixel comprises a numerical value in 2 * 2 repetitive, mean in red (R), green (G) of this pixel, blue (B) three primary colors wherein a kind of value, wherein G has two, distributes and is called G1, G2 to show differentiation.Generally, the R of image, G1, G2, B value by 8 or more the unsigned number of multidigit mean; Then take R-G1-G2-B tetra-color spaces as according to the pixel of whole original image is classified;
S102. the pixel of each part of take is a figure layer, folded at the enterprising windrow of direction perpendicular to the figure layer, forms three-dimensional matrice, as shown in Figure 1.
S2. the described three-dimensional matrice rearranged is carried out to the three-dimensional orthogonal conversion and obtain matrix of frequency coefficients; This step mainly comprises:
S201. to rearranging the described three-dimensional matrice piecemeal obtained, the square of L * L * H of take carries out the three-dimensional orthogonal conversion and obtains described matrix of frequency coefficients as unit, wherein L is figure layer plane number of lines of pixels or columns, H is the number of pixels of vertical view layer plane, for example thinks that 4 * 4 * 4 pixels or 8 * 8 * 4 pixels are a unit; 4 * 4 * 4 pixels of take in the present embodiment describe as a unit as example, when the length of original image is wide or high while not being 4 integral multiple, should first it be supplied to meet the conversion requirement, and the value of the pixel of supplying can be got the value of neighboring edge pixel; Wherein, described orthogonal transform is one or more in discrete cosine transform and integer transform; The integer transform of take in the present embodiment describes as example; Be specially: establishing above-mentioned 4 * 4 * 4 pixel cells is I, I(i, j, k) mean that the i in I is capable, j row, the element of k layer; Transformation results is F, F(i, j, k) mean that the i in F is capable, j row, the element of k layer.Variation as the formula (1), transform matrix M wherein
x, M
y, M
zShown in (2), (3):
Adopt the words of matrix operation can be divided into two steps, D means intermediate data, is similarly three-dimensional matrice; M
TTransposed matrix for M.
At first every one deck of along continuous straight runs in I is done to two-dimensional orthogonal transformation, I (::, k) mean the k layer in I, k=1,2,3,4
D(:,:,k)=M
xI(:,:,k)M
y T
Then along the longitudinal axis, be the D cutting 4 parts, along the y direction one dimension orthogonal transform that tries again.The direction of cutting can be along the yz plane or the xz plane cutting, and D is divided into to D (i: :) or D (:, j :) four parts, i=1 wherein, 2,3,4 or j=1,2,3,4
F (i: :)=M
zD (i: :) or F (:, j :)=M
zD (:, j :)
Preferred transformation matrix in the present embodiment:
S3. described matrix of frequency coefficients is carried out to quantification treatment, then the matrix of frequency coefficients after layout quantification treatment again it is carried out to the entropy coding, the component frame data; This step mainly comprises:
S301. according to default quantization table matrix, described matrix of frequency coefficients F is carried out to quantification treatment, establishing quantized result is F
Q, can be expressed as formula (4), " ⊙ " represents that the element of matrix correspondence position is divided by, and wherein the quantization table matrix is Q, and Q is similarly a three-dimensional matrice, and the preferred Q of the present embodiment is as the formula (5);
F
Q=F⊙Q (4)
Q (i) means the i layer of Q
S302. to the matrix of frequency coefficients F after quantizing
QCarry out layout again, become the one-dimensional vector form by matrix form; Its transformation rule is as follows, establishes F
Q(i, j, k) represents F
QI capable, j row, k layer element; The one-dimensional vector of formation is as the formula (6):
[F
Q(1,1,1),F
Q(1,1,2),F
Q(1,1,3),F
Q(1,2,1),F
Q(2,1,1,),F
Q(1,2,2),F
Q(2,1,2)F
Q(1,3,1),F
Q(2,2,1),F
Q(3,1,1),F
Q(1,1,4),F
Q(1,2,3),F
Q(2,1,3),F
Q(1,3,2),F
Q(2,2,2),F
Q(3,1,2),F
Q(1,4,1),F
Q(2,3,1),F
Q(3,2,1),F
Q(4,1,1),F
Q(1,2,4),F
Q(2,1,4),F
Q(1,3,3),F
Q(2,2,3),F
Q(3,1,3),F
Q(1,4,2),F
Q(2,3,2),F
Q(3,2,2),F
Q(4,1,2),F
Q(2,4,1),F
Q(3,3,1),F
Q(4,2,1),F
Q(1,3,4),F
Q(2,2,4),F
Q(3,1,4),F
Q(1,4,3),F
Q(2,3,3),F
Q(3,2,3),F
Q(4,1,3)F
Q(2,4,2),F
Q(3,3,2),F
Q(4,2,2),F
Q(3,4,1),F
Q(4,3,1),F
Q(1,4,4),F
Q(2,3,4),F
Q(3,2,4),F
Q(4,1,4),F
Q(2,4,3),F
Q(3,3,3),F
Q(4,2,3),F
Q(3,4,2),F
Q(4,3,2),F
Q(4,4,1),F
Q(2,4,4),F
Q(3,3,4),F
Q(4,2,4),F
Q(3,4,3),F
Q(4,3,4),F
Q(4,4,2),F
Q(3,4,4),F
Q(4,3,4),F
Q(4,4,3),F
Q(4,4,4)](6)
S303. contrast corresponding entropy coding schedule each element in described one-dimensional vector is carried out to the entropy coding.The fritter of 4*4*4 has 64 elements after becoming one-dimensional vector.
Wherein first three element adopts the DC coding in the huffman coding, and the coefficient between different piecemeals is first done the difference preliminary treatment and obtained predicated error.Take first element is example, supposes that image is divided into the fritter into n, forms a line first coefficient of each fritter to obtain
F
1=[F
1(1),F
1(2),F
1(3),……F
1(n)]
After doing the difference preliminary treatment, obtain predicated error D
1:
Then to predicated error D
1(n) in, each coefficient carries out entropy coding (principle of coding is the same with the jpeg image coding).Each coefficient can be expressed as the form of [representing the code word of binary code length, the binary code of this coefficient].A front part has meaned that this coefficient needs binary code how long stores, and concrete code word can be shown to obtain by inquiry DCTAB.The preferred code word of the present embodiment is in Table 1.
The coefficient of encoding |
Binary code length |
Code word |
0 |
0 |
00 |
-1,1 |
1 |
010 |
-3,-2,2,3 |
2 |
011 |
-7,...,-4,4,...,7 |
3 |
100 |
-15,...,-8,8,...,15 |
4 |
101 |
-31,...,-16,16,...,31 |
5 |
110 |
-63,...,-32,32,...,63 |
6 |
1110 |
-127,...,-64,64,...,127 |
7 |
11110 |
-255,...,-128,128,...,255 |
8 |
111110 |
-511,...,-256,256,...,511 |
9 |
1111110 |
-1023,...,-512,512,...,1023 |
10 |
11111110 |
-2047,...,-1024,1024,...,2047 |
11 |
111111110 |
Table 1DCTAB
Rear 61 elements adopt the AC coding (principle of coding is the same with the jpeg image coding) in the huffman coding.In each fritter, each nonzero coefficient is expressed as the form of [representing the code word of stroke/binary code length, the binary code of this coefficient].Stroke refers to 0 number of nonzero coefficient front.A front part has meaned that this coefficient front has how many 0 and this coefficient needs binary code how long stores, and concrete code word can be shown to obtain by inquiry ACTAB.Whenever stroke be more than or equal at 16 o'clock to insert a ZRL(, be 16/0) mean that 16 companies are zero; After last the nonzero coefficient end-of-encode of each fritter, insert end of block character EOB(0/0).The preferred code word of the present embodiment is in Table 2.
Stroke binary code length |
Code word |
0\0 |
11 |
0\1 |
00 |
0\2 |
010 |
0\3 |
1010 |
0\4 |
011010 |
0\5 |
01101100 |
0\6 |
0111111001 |
0\7 |
01111110000010 |
0\8 |
0111111000001100000011011011 |
0\9 |
0111111000001100000011011010 |
0\10 |
0111111000001100000011011001 |
1\1 |
100 |
1\2 |
10111 |
1\3 |
01101111 |
1\4 |
0111111101 |
1\5 |
0111111000110 |
1\6 |
0111111000001111 |
1\7 |
0111111000001100000011011000 |
1\8 |
0111111000001100000011010111 |
1\9 |
0111111000001100000011010110 |
1\10 |
0111111000001100000011010101 |
2\1 |
01100 |
2\2 |
011011010 |
2\3 |
011111110011 |
2\4 |
01111110000011011 |
2\5 |
0111111000001100000011010100 |
2\6 |
0111111000001100000011010011 |
2\7 |
0111111000001100000011010010 |
2\8 |
0111111000001100000011010001 |
2\9 |
0111111000001100000011010000 |
2\10 |
0111111000001100000011001111 |
3\1 |
10110 |
3\2 |
0110110111 |
3\3 |
011111100000010 |
3\4 |
011111100000110000000 |
3\5 |
0111111000001100000011001110 |
3\6 |
0111111000001100000011001101 |
3\7 |
0111111000001100000011001100 |
3\8 |
0111111000001100000011001011 |
3\9 |
0111111000001100000011001010 |
3\10 |
0111111000001100000011001001 |
4\1 |
011110 |
4\2 |
01111111000 |
4\3 |
0111111000001110 |
4\4 |
0111111000001100000011001000 |
4\5 |
0111111000001100000011000111 |
4\6 |
0111111000001100000011000110 |
4\7 |
0111111000001100000011000101 |
4\8 |
0111111000001100000011000100 |
4\9 |
0111111000001100000011000011 |
4\10 |
0111111000001100000011000010 |
5\1 |
011101 |
5\2 |
011111110010 |
5\3 |
0111111000001100011 |
5\4 |
0111111000001100000011000001 |
5\5 |
0111111000001100000011000000 |
5\6 |
0111111000001100000010111111 |
5\7 |
0111111000001100000010111110 |
5\8 |
0111111000001100000010111101 |
5\9 |
0111111000001100000010111100 |
5\10 |
0111111000001100000010111011 |
6\1 |
0111000 |
6\2 |
011111100010 |
6\3 |
011111100000110101 |
6\4 |
0111111000001100000010111010 |
6\5 |
0111111000001100000010111001 |
6\6 |
0111111000001100000010111000 |
6\7 |
0111111000001100000010110111 |
6\8 |
0111111000001100000010110110 |
6\9 |
0111111000001100000010110101 |
6\10 |
0111111000001100000010110100 |
7\1 |
0111110 |
7\2 |
01111110000000 |
7\3 |
01111110000011000101 |
7\4 |
0111111000001100000010110011 |
7\5 |
0111111000001100000010110010 |
7\6 |
0111111000001100000010110001 |
7\7 |
0111111000001100000010110000 |
7\8 |
0111111000001100000010101111 |
7\9 |
0111111000001100000010101110 |
7\10 |
0111111000001100000010101101 |
8\1 |
01101110 |
8\2 |
0111111000111 |
8\3 |
0111111000001100000010101100 |
8\4 |
0111111000001100000010101011 |
8\5 |
0111111000001100000010101010 |
8\6 |
0111111000001100000010101001 |
8\7 |
0111111000001100000010101000 |
8\8 |
0111111000001100000010100111 |
8\9 |
0111111000001100000010100110 |
8\10 |
0111111000001100000010100101 |
9\1 |
01110011 |
9\2 |
011111100000011 |
9\3 |
01111110000011000100 |
9\4 |
0111111000001100000010100100 |
9\5 |
0111111000001100000010100011 |
9\6 |
0111111000001100000010100010 |
9\7 |
0111111000001100000010100001 |
9\8 |
0111111000001100000010100000 |
9\9 |
0111111000001100000010011111 |
9\10 |
0111111000001100000010011110 |
10\1 |
011100101 |
10\2 |
011111100000110011 |
10\3 |
0111111000001100000010011101 |
10\4 |
0111111000001100000010011100 |
10\5 |
0111111000001100000010011011 |
10\6 |
0111111000001100000010011010 |
10\7 |
0111111000001100000010011001 |
10\8 |
0111111000001100000010011000 |
10\9 |
0111111000001100000010010111 |
10\10 |
0111111000001100000010010110 |
11\1 |
011111111 |
11\2 |
011111100000110010 |
11\3 |
0111111000001100000010010101 |
11\4 |
0111111000001100000010010100 |
11\5 |
0111111000001100000010010011 |
11\6 |
0111111000001100000010010010 |
11\7 |
0111111000001100000010010001 |
11\8 |
0111111000001100000010010000 |
11\9 |
0111111000001100000010001111 |
11\10 |
0111111000001100000010001110 |
12\1 |
011100100 |
12\2 |
011111100000110100 |
12\3 |
0111111000001100000010001101 |
12\4 |
0111111000001100000010001100 |
12\5 |
0111111000001100000010001011 |
12\6 |
0111111000001100000010001010 |
12\7 |
0111111000001100000010001001 |
12\8 |
0111111000001100000010001000 |
12\9 |
0111111000001100000010000111 |
12\10 |
0111111000001100000010000110 |
13\1 |
0111111011 |
13\2 |
01111110000011000011 |
13\3 |
0111111000001100000010000101 |
13\4 |
0111111000001100000010000100 |
13\5 |
0111111000001100000010000011 |
13\6 |
0111111000001100000010000010 |
13\7 |
0111111000001100000010000001 |
13\8 |
0111111000001100000010000000 |
13\9 |
011111100000110000001111111 |
13\10 |
011111100000110000001111110 |
14\1 |
0110110110 |
14\2 |
01111110000011000010 |
14\3 |
011111100000110000001111101 |
14\4 |
011111100000110000001111100 |
14\5 |
011111100000110000001111011 |
14\6 |
011111100000110000001111010 |
14\7 |
011111100000110000001111001 |
14\8 |
011111100000110000001111000 |
14\9 |
011111100000110000001110111 |
14\10 |
011111100000110000001110110 |
15\1 |
011111100001 |
15\2 |
01111110000011000001 |
15\3 |
011111100000110000001110101 |
15\4 |
011111100000110000001110100 |
15\5 |
011111100000110000001110011 |
15\6 |
011111100000110000001110010 |
15\7 |
011111100000110000001110001 |
15\8 |
011111100000110000001110000 |
15\9 |
011111100000110000001101111 |
15\10 |
011111100000110000001101110 |
16\0 |
0111111010 |
Table 2ACTAB
S304. by the matrix of frequency coefficients component frame data after the entropy coding, whole compression process finishes.
Apply method for compressing image of the present invention Bayer format-pattern (being the Wireless capsule endoscope image in the present embodiment) is processed, can obtain 94% image compression ratio
The reconstructed image objective quality can reach 41.6dB, and does not have blocking effect in reconstructed image; And other are applied to the compression method of Bayer format-pattern so far, in same picture quality situation, compression ratio is only 89%, and compression method of the present invention is by utilizing the correlation in color of image space, make compression ratio that obvious must the raising be arranged, the data after compression reduce more than 40%.Therefore, method for compressing image of the present invention, under the prerequisite of low algorithm complex and high reduction picture quality, can provide very high image compression rate.
The present invention also provides a kind of compression set of Bayer format-pattern, comprising: first module, and for the described Bayer format-pattern pixel to collecting, classify and be rearranged into three-dimensional matrice; Second unit, carry out the three-dimensional orthogonal conversion for the described three-dimensional matrice to rearranging and obtain matrix of frequency coefficients; Unit the 3rd, for described matrix of frequency coefficients is carried out to quantification treatment, the matrix of frequency coefficients after layout quantification treatment again it is carried out to the entropy coding, the component frame data then.
One of ordinary skill in the art will appreciate that: all or part of step that realizes above-described embodiment can complete by the hardware that program command is correlated with, aforesaid program can be stored in a computer read/write memory medium, this program, when carrying out, is carried out the step that comprises above-described embodiment; And aforesaid storage medium comprises: various media that can be program code stored such as ROM, RAM, magnetic disc or CDs.
With it should be noted that: above embodiment, only be used to technical scheme of the present invention is described, is not intended to limit; Although with reference to previous embodiment, the present invention is had been described in detail, those of ordinary skills are to be understood that: it still can be modified to the technical scheme that aforementioned each embodiment puts down in writing, or part technical characterictic wherein is equal to replacement; And these modifications or replacement, and the essence of appropriate technical solution breaks away from the spirit and scope of various embodiments of the present invention technical scheme frequently.