Detailed description of the invention
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is carried out
Clearly and completely describe, it is clear that described embodiment is only a part of embodiment of the present invention, and
It is not all, of embodiment.Based on the embodiment in the present invention, those of ordinary skill in the art are not doing
Go out the every other embodiment obtained under creative work premise, broadly fall into the scope of protection of the invention.
Fig. 1 is the schematic flow sheet of a kind of two-value prospect compaction coding method that the embodiment of the present invention provides.
As it is shown in figure 1, the method comprises the steps:
Step 101: the foreground pixel section in labelling two-value foreground image.Concretely, by two-value foreground picture
In the one-row pixels of picture pixel value be continuously 1 pixel be labeled as a foreground pixel section of current line.When one
Row pixel has multiple pixel value be continuously 1 pixel fragment time, then this row pixel contains multiple prospect picture
Element section.
In an embodiment of the present invention, often the foreground pixel section in row pixel is marked in order.That is,
The labelling of each foreground pixel section can uniquely represent that this foreground pixel section is in current line all foreground pixels section
Serial number.
Step 102: record origin coordinates and the end coordinate of each described foreground pixel section.
Detailed process can be: travels through the pixel value of each pixel in described two-value foreground image by row;If finding
Pixel value is the pixel of 1, then using pixel coordinate that this pixel value is 1 as a foreground pixel section
Origin coordinates;During the pixel finding pixel value to be 0 the most again, upper by pixel that this pixel value is 0
One pixel coordinate is as the end coordinate of current foreground pixel section, and continues to look for next pixel value and be
The pixel of 1;Or, when then traveling through the edge pixel point to current line, by the edge pixel point of current line
Coordinate is as the end coordinate of current foreground pixel section, and to continue to look for next pixel value be the pixel of 1.
Fig. 2 show origin coordinates and the knot of one foreground pixel section of record that one embodiment of the invention is provided
The schematic flow sheet of bundle coordinate.As in figure 2 it is shown, this recording process includes:
S201: be 0 by line order i initial assignment;Owing to this recording process is for by row traversal two-value foreground image
In each element, therefore need record current line numbering in all row with line order i;
S202: make N (i)=0, k=0, j=0;N (i) therein represents the foreground pixel section comprised in the i-th row
Quantity, k represents the marker number of foreground pixel section in current line, and j represents and currently travels through picture in current line
The numbering of element;Owing to the most not yet starting the ergodic process of current line, therefore three above parameter is initially composed
Value is 0;
S203:j increases by 1, until the some P finding pixel value to be 1, or arrive the edge of current i-th row;
S204: judge j whether < W-1;W represents the width of two-value foreground picture, owing to the initial value of j is 0,
As j < W-1, explanation not yet travels through the edge to current line, i.e. means have found one of current i-th row
The starting point of foreground pixel section, now enters S205;As j=W-1, then show to travel through the edge to current line
The foreground pixel the most not finding pixel value to be 1, illustrates that current line does not comprise foreground pixel section, now enters
Enter S209;
S205: by origin coordinates S (i, k) .kl that the coordinate record of P is a foreground pixel section;
S206:j increases, and during until the some P ' finding pixel value to be 0, is sat by a upper pixel of P '
Mark is recorded as end coordinate S (i, k) .kr of current foreground pixel section;Or, until the edge of current i-th row is all
During the point P ' not finding pixel value to be 0, before the edge pixel point coordinates of current i-th row being recorded as currently
End coordinate S (i, k) .kr of scape pixel fragment;
S207: (i, k) (i, k) .kr, ought for .kl and end coordinate S for the origin coordinates S of storage foreground pixel section
Foreground pixel hop count amount N (i) of front i-th row adds 1, and marker number k of foreground pixel section adds 1;
S208: judge j whether < W-1;The most then illustrate not arrive yet the edge of current i-th row, now
Return S203 and look for starting point P of next foreground pixel section;If it is not, then illustrate to have arrived current i-th row
Edge, enters S209;
S209:i increases by 1;
S210: < the H that whether judges i;H is the maximum number of lines of current two-value foreground image;The most then illustrate
The most treated i-th-1 row is not last column of two-value foreground image, now return S202 start right
The traversal of pixel in current i-th row;If it is not, then the pixel of all row has been the most time in explanation two-value foreground image
Go through, terminated flow process.
Step 103: the origin coordinates of each described foreground pixel section is encoded with end coordinate.
What Fig. 3 showed that one embodiment of the invention provided is compressed coding to a two-value foreground image
Schematic flow sheet.As it is shown on figure 3, this cataloged procedure is carried out by row scan sequence, and current line is encoded
Journey can be with the origin coordinates of foreground pixel section in lastrow and end coordinate as reference;That is, lastrow can conduct
The reference line of current line.This coding flow process specifically includes:
S301: the line number Lstart that the first foreground pixel section of calculating two-value foreground image is expert at is with last
The line number Lend that one foreground pixel section is expert at, and Lstart and Lend is enrolled code stream, can use
Columbus without symbol index encodes;
S302: be Lstart by line number i initial assignment;
S303: quantity N (i) of the foreground pixel section comprised in current i-th row is enrolled code stream;
S304: judge whether the N (i) of current i-th row is 0;The most then illustrate current i-th row does not wrap
Containing foreground pixel section, now enter S310;If it is not, then enter S305;
S305: the foreground pixel segment mark of current i-th row is numbered and is initially 0;
S306: calculate copy_flag, and copy_flag is enrolled code stream;Detailed process is, it is judged that current
Whether the origin coordinates of the foreground pixel section of the i-th numbered k of line flag and end coordinate number also with reference line
Origin coordinates for the foreground pixel section of k is identical with the abscissa of end coordinate;If it is identical, then by copy_flag
Being entered as 1 and enroll code stream, so can directly be numbered by lastrow when decoding is also the foreground pixel section of k
Origin coordinates and the abscissa of end coordinate be copied to current line;If differing, then by copy_flag assignment
It is 0 and enrolls code stream;
S307: judge whether copy_flag is 0;If then entering step 308;If being otherwise directly entered step
Rapid 309;
S308: by the origin coordinates S of the foreground pixel section of the current i-th numbered k of line flag (i, k) .kl and
(i, k) .kr enrolls code stream to end coordinate S;
S309:k increases by 1;
S310: judge that whether current k is less than N (i);If being less than, then before explanation marker number is k-1
Scape pixel fragment is not last foreground pixel section of current i-th row, now returns S306 and judges current the
The copy_flag of k foreground pixel section;If being equal to, then explanation marker number is that the foreground pixel section of k-1 is
Last foreground pixel section, now enters S311;
S311: the origin coordinates of reference line and coordinate logarithm N (ref) of end coordinate are entered as current
Foreground pixel hop count amount N (i) of i row, by origin coordinates and the coordinate of end coordinate of reference line foreground pixel section
Value Ref is entered as origin coordinates and the coordinate figure of end coordinate of current i-th row all foreground pixels section;This
Sample current line can be used as reference line during next line pixel coder;
S312:i increases by 1;
S313: whether judge i≤Lend;The most then illustrate not yet to encode to last foreground pixel section
It is expert at, now returns step 304 and judge whether the N (i) of current i-th row is 0;If it is not, then illustrate to have compiled
Code to last foreground pixel section is expert at, and terminates flow process.
In an embodiment of the present invention, for origin coordinates and the coding of end coordinate of current foreground pixel section
Can be particularly as follows: with reference to the end coordinate of a foreground pixel section on current line, current foreground pixel section be risen
Beginning coordinate and end coordinate carry out lateral prediction coding.This lateral prediction cataloged procedure can use without symbol index
Columbus's coded system.
The detailed process of this lateral prediction coding can be: before current foreground pixel section origin coordinates and upper one
The abscissa difference of scape pixel fragment end coordinate is as starting point lateral prediction difference;By described starting point lateral prediction
Difference enrolls code stream to represent the origin coordinates of current foreground pixel section;And/or, by current foreground pixel section
It is current to represent that end coordinate and the abscissa difference of origin coordinates enroll code stream as end lateral prediction difference
The end coordinate of foreground pixel section.More than coding flow process can use without symbol index Columbus's coded system.
In an alternative embodiment of the invention, for origin coordinates and the volume of end coordinate of current foreground pixel section
Code may further be embodied as: with reference to origin coordinates and the end coordinate of lastrow all foreground pixels section, before current
The origin coordinates of scape pixel fragment and end coordinate carry out longitudinal predictive coding.
This longitudinal direction predictive coding process can be: by the initial seat of foreground pixel section that current line marker number is k
Abscissa difference between the origin coordinates/end coordinate of mark/end coordinate and lastrow all foreground pixels section
On origin coordinates/end coordinate as longitudinal prediction residual and corresponding with described longitudinal prediction residual is relative
One line number is also the coordinate offset value of the origin coordinates/end coordinate of the foreground pixel section of k;By described longitudinal direction
Longitudinal prediction residual and coordinate offset value that the absolute value sum of prediction residual and coordinate offset value is minimum enroll code
Stream is with the origin coordinates/end coordinate representing current foreground pixel section.More than coding flow process can use symbol to refer to
Number Columbus's coded system.
In an alternative embodiment of the invention, the coding for a two-value foreground image can use above-mentioned horizontal stroke simultaneously
To predictive coding and longitudinal predictive coding.But due to lateral prediction coding only need by starting point lateral prediction difference and/
Or the size terminating lateral prediction difference enrolls code stream, and need not use signed coded system,
So can occupy less data volume in concrete cataloged procedure;Thus more incline in actual cataloged procedure
To in using lateral prediction coded method.
Now, can be by judging the minima and of the absolute value sum of longitudinal prediction residual and coordinate offset value
Individual constant and whether less than starting point lateral prediction difference and/or terminate lateral prediction difference determines which uses
Plant predictive coding method.And if should being worth less than starting point lateral prediction difference and/or terminating lateral prediction difference, then
Illustrate that the data volume of the required coding of longitudinal predictive coding is less than lateral prediction coding, now use longitudinally prediction
Coding.Otherwise, then lateral prediction coded method origin coordinates/end coordinate to current foreground pixel section is used
Encode.
It will be understood by those skilled in the art that the constant for trying to achieve this and value can be Any Digit, user
This constant can be adjusted accordingly according to the priority of lateral prediction to be used coding.This constant is the biggest, then mean
More possible employing lateral prediction codings, this constant is the least, the most more possible employing longitudinal direction predictive codings.This
Invent the size to this constant not limit.
In an alternative embodiment of the invention, a longitudinal discrimination mark can also be introduced to record current foreground pixel
Origin coordinates/the end coordinate of section have employed lateral prediction coding or longitudinal predictive coding.When using laterally
During predictive coding, this longitudinal direction discrimination mark is entered as 0, and this discrimination mark is enrolled code stream;Vertical when using
When predictive coding, this longitudinal direction discrimination mark is entered as 1, and this discrimination mark is enrolled code stream.
What Fig. 4 showed that one embodiment of the invention provided sits the origin coordinates of a foreground pixel section/end
Mark carries out the schematic flow sheet encoded.As shown in Figure 4, this is the foreground pixel of k to current line marker number
The flow process that the origin coordinates/end coordinate of section carries out encoding includes:
S401: be 0 by the coordinate numbering m initial assignment of reference line, by longitudinal direction prediction residual and coordinate offset
The minima min_cost initial assignment of the absolute value sum of value is a maximum integer;Due in reference line
May include N (ref) to origin coordinates and end coordinate, therefore 0≤m≤2*N (ref);
S402: calculate the horizontal seat of current foreground pixel section origin coordinates and a upper foreground pixel section end coordinate
Mark difference is as starting point lateral prediction difference e 0;Or, calculate the end coordinate of current foreground pixel section with initial
The abscissa difference of coordinate is as terminating lateral prediction difference e 0;
S403: calculate origin coordinates/end coordinate and the reference line m-th coordinate of current foreground pixel section
Abscissa difference is as longitudinal prediction residual e1 (m), and rise corresponding with described longitudinal prediction residual e1 (m)
Beginning coordinate/end coordinate is also the origin coordinates/end coordinate of the foreground pixel section of k relative to lastrow numbering
(here, V (m)=2k-m when for encoding origin coordinates, when for end coordinate for coordinate offset value V (m)
V (m)=2k+1-m during coding);Try to achieve longitudinal decision value cost=| e1 (m) |+| V (m) |;
S404: judge that whether decision value cost is less than current min_cost;If being less than, then enter S405;
If being more than or equal to, then it is directly entered S406, and does not store the value of current m;
S405: the value recording current m with M, makes min_cost=cost;
S406:m increases by 1;
S407: judge that whether m is less than 2*N (ref);If being less than, then explanation also has the foreground pixel of reference line
Origin coordinates/the end coordinate of section is not yet referenced calculating, now returns S403 referring initially under reference line
Origin coordinates/the end coordinate of one foreground pixel section carries out calculating cost;If being more than or equal to, then reference is described
Row all foreground pixel Duan Douyi with reference to complete, the now longitudinal direction corresponding to pixel of the numbered M of reference line
The absolute value sum of prediction residual and coordinate offset value is minimum, enters S408;
S408: min_e1 is entered as e1 (M), is entered as V (M) by min_V;Min_e1 is the most pre-
Surveying longitudinal prediction residual that the absolute value sum of residual sum coordinate offset value is minimum, min_V is and min_e1
Corresponding coordinate offset value;Min_cost=| min_e1 |+| min_V | now;
S409: judge that whether min_cost+3 is less than e0;If less than, the longitudinal discrimination mark of order
Coding_flag=1, enrolls code stream to represent current foreground pixel by coding_flag, min_e1 and min_V
Origin coordinates/the end coordinate of section, flow process terminates;If being more than or equal to, then make coding_flag=0, will
Coding_flag and e0 enrolls code stream to represent the origin coordinates/end coordinate of current foreground pixel section, flow process
Terminate.
The compressed encoding code stream that the two-value prospect compaction coding method provided for above example is formed,
One embodiment of the invention additionally provides a kind of coding/decoding method.
Fig. 5 show the decoding side of a kind of two-value prospect compaction coding method that one embodiment of the invention is provided
Method schematic flow sheet.As it is shown in figure 5, this coding/decoding method includes:
Step 501: compressed encoding code stream is decoded obtaining origin coordinates and the knot of each foreground pixel section
Bundle coordinate.Owing to compressed encoding code stream containing origin coordinates and the end coordinate of each foreground pixel section,
This compressed encoding code stream decoding can be obtained these origin coordinates and end coordinate.
Step 502: in the value of all pixels is all the image of 0, by each described foreground pixel
Pixel value between origin coordinates and the end coordinate of section is revised as 1.Obtaining all foreground pixel sections
After origin coordinates and end coordinate, owing in each foreground pixel section, the pixel value of all pixels should be 1,
Therefore only the pixel value between origin coordinates and the end coordinate of each described foreground pixel section need to be revised as 1
Two-value foreground image originally can be gone out by fast restore.
In an embodiment of the present invention, it has been also possible that longitudinal judgement due to compressed encoding code stream when coding
Labelling, now can resolve the discrimination mark in compressed encoding code stream;It is the prospect of 1 for longitudinal discrimination mark
Data segment, obtains lastrow prospect number referenced when encoding according to the coordinate offset value in compressed encoding code stream
Origin coordinates/end coordinate according to section;Longitudinal prediction residual in compressed encoding code stream is referenced with during coding
Lastrow foreground data section origin coordinates/end coordinate and initial seat as current foreground pixel section
Mark/end coordinate;For the foreground data section that longitudinal discrimination mark is 0, according to rising in compressed encoding code stream
Point lateral prediction difference/end lateral prediction difference obtains the origin coordinates/longitudinal coordinate of current foreground pixel section.
In an embodiment of the present invention, owing to compressed encoding code stream has been also possible that copy labelling when coding,
Now resolve the copy labelling in compressed encoding code stream;Copy is labeled as the foreground data of the numbered k of 1
The origin coordinates of section and the abscissa value of end coordinate are entered as the foreground data section that lastrow numbering is also k
Origin coordinates and the abscissa value of end coordinate.
Fig. 6 show the decoding side of a kind of two-value prospect compaction coding method that one embodiment of the invention is provided
Method schematic flow sheet.As shown in Figure 6, the method includes:
S601: resolve Lstart and Lend in encoding code stream, make decoded row numbering i=Lstart;
S602: resolve foreground pixel hop count amount N (i) that in encoding code stream, the row of line number i is comprised;
S603: judge that whether N (i) is equal to 0;If it is not, then enter S604;The most then explanation current line is not
There is foreground pixel section, enter S615;
S604: be 0 by the foreground pixel segment mark numbering k initial assignment of the row that current number is i;
S605: resolve the copy_flag of the foreground pixel section of marker number k in the row that current number is i;
S606: judge whether this copy_flag is 1;The most then enter S607;If it is not, then enter S608;
S607: (i, during k) .kl is entered as reference line, marker number is also the initial seat of the foreground pixel section of k by S
Mark Ref [2*k], by S, (i, during k) .kr is entered as reference line, marker number is also the end of the foreground pixel section of k
Coordinate Ref [2*k+1], enters S612;
S608: resolve the origin coordinates of the foreground pixel section of marker number k in the row that current number is i
coding_flag;
S609: judge the origin coordinates of the foreground pixel section of marker number k in the row that current number is i
Whether coding_flag is 0;The most then illustrate that the origin coordinates of this foreground pixel section uses lateral prediction to compile
Code, now resolves lateral prediction difference c0 in encoding code stream, obtains current foreground pixel section according to c0
Origin coordinates S (i, k) .kl;If it is not, then illustrate that the origin coordinates of this foreground pixel section is to use longitudinally prediction to compile
Code, now resolves coordinate offset value min_L and min_c1, and obtains when encoding according to this min_L referenced
The origin coordinates of lastrow foreground data section;By longitudinal prediction residual min_c1 in compressed encoding code stream
With during coding the origin coordinates of referenced lastrow foreground data section and rising as current foreground pixel section
Beginning coordinate S (i, k) .kl;
S610: resolve the end coordinate of the foreground pixel section of marker number k in the row that current number is i
coding_flag;
S611: judge the end coordinate of the foreground pixel section of marker number k in the row that current number is i
Whether coding_flag is 0;The most then illustrate that the end coordinate of this foreground pixel section uses lateral prediction to compile
Code, now resolves lateral prediction difference d0 in encoding code stream, obtains current foreground pixel section according to d0
End coordinate S (i, k) .kr;If it is not, then illustrate that the end coordinate of this foreground pixel section is to use longitudinally prediction to compile
Code, now resolves coordinate offset value min_R and min_d1, and is joined when obtaining coding according to this min_R
The end coordinate of the lastrow foreground data section examined;By longitudinal prediction residual min_d1 in compressed encoding code stream
With during coding the end coordinate of referenced lastrow foreground data section and knot as current foreground pixel section
Bundle coordinate S (i, k) .kr;
S612:k increases by 1;
S613: judge that whether k is less than N (i);The most then explanation current line there is also the prospect not being decoded
Pixel fragment, now returns and judges whether the copy_flag of next foreground pixel section is 1;If it is not, then illustrate
Current line all of foreground pixel section is all decoded complete, enters S614;
S614: the origin coordinates of reference line and coordinate logarithm N (ref) of end coordinate are entered as current
Foreground pixel hop count amount N (i) of i row, by origin coordinates and the coordinate of end coordinate of reference line foreground pixel section
Value Ref is entered as origin coordinates and the coordinate figure of end coordinate of current i-th row all foreground pixels section;
S615:i increases by 1;
S616: whether judge i≤Lend;The most then illustrate that the i-th-1 the most decoded row is not last
Individual foreground pixel section is expert at, and now returns S602 and starts to be decoded current i-th row;If it is not, then say
Bright all provisional capitals have been decoded complete, terminate flow process.
The embodiment of the present invention provides a kind of two-value prospect compaction coding method, only to labeled foreground pixel
The origin coordinates of section encodes with end coordinate, before so utilizing in two-value foreground image when decoding
Scape pixel value is all the principle of 1, it is only necessary to by the origin coordinates of foreground pixel section in one 0 value image
And the coordinate between end coordinate is entered as 1 can fast restore two-value foreground image.This compares existing skill
The method directly two-value foreground image encoded in art, the data volume of the compressed encoding code stream formed
It is greatly reduced, bigger bandwidth will not be taken during transmission.
These are only presently preferred embodiments of the present invention, not in order to limit the present invention, all in the present invention
Spirit and principle within, any amendment of being made, equivalent etc., should be included in the guarantor of the present invention
Within the scope of protecting.