Summary of the invention
The embodiment of the invention provides a kind of coding method of image and devices, at least to solve in the prior art to figure
When picture is encoded, due to the technical problem for being difficult to that corresponding encoder is selected to cause encoding efficiency low.
According to an aspect of an embodiment of the present invention, a kind of coding method of image is provided, comprising: by image to be encoded
Carry out piecemeal, and classification belonging to each piece of determination, wherein classification includes: picture block, character block and other blocks;It is any
One or more at least two candidate encoders of classification and matching, at least two candidate encoders respectively with the subclassification pair of classification
It answers;The corresponding subject encoder of block is determined from least two candidate encoders;Using subject encoder to block coding.
Further, the code efficiency of each candidate encoder is obtained;Determine that the highest candidate encoder of code efficiency is
Subject encoder.
Further, the coding parameter of each candidate encoder is obtained, wherein the coding parameter packet of each candidate encoder
It includes: encoding code stream size parameter and coding performance parameter;The ratio between coding performance parameter and encoding code stream size parameter are determined to compile
Code parameter determines the code efficiency of each candidate encoder.
Further, the coding parameter of each candidate encoder is obtained, wherein the coding parameter packet of each candidate encoder
It includes: encoding code stream size parameter and coding performance parameter;Successively compare the coding parameter of two candidate encoders, and according to comparing
As a result a candidate encoder is selected from two candidate encoders for participating in comparing;By the candidate encoder of selection with it is next
Candidate encoder is compared, until all candidate encoders all compare, determines the candidate encoder of final choice
For subject encoder.
Further, in the case where the first code stream is less than the second code stream, if the first coding efficiency is greater than or equal to the
Two coding efficiencies then select the first candidate encoder, wherein the first code stream and the first coding efficiency are two times for participating in comparing
The coding parameter of the first candidate encoder in encoder is selected, the second code stream and the second coding efficiency are two times for participating in comparing
Select the coding parameter of the second candidate encoder in encoder;In the case where the first code stream is less than the second code stream, if first
Whether coding efficiency then judges the ratio of the first code stream and the second code stream less than the first preset value, In less than the second coding efficiency
Ratio less than the first preset value in the case where select the first candidate encoder;In the case where the first code stream is greater than the second code stream,
If the first coding efficiency is less than or equal to the second coding efficiency, the second candidate encoder is selected;It is greater than the in the first code stream
In the case where two code streams, if the first coding efficiency is greater than the second coding efficiency, the ratio of the second code stream and the first code stream is judged
Whether value in the case where ratio less than second preset value selects first candidate encoder less than the second preset value.
Further, the corresponding candidate encoder of picture block includes: chart type image encoder, and/or picture type image
Encoder.
Further, the corresponding candidate encoder of character block includes: Chinese character-shaped image encoder, and/or alpha type image
Encoder.
According to another aspect of an embodiment of the present invention, a kind of code device of image is additionally provided, comprising: determining module,
For by image to be encoded carry out piecemeal, and determine each piece belonging to classification, wherein classification include: picture block, character block with
And other blocks;Matching module, for being any one or more at least two candidate encoders of classification and matching, at least two is candidate
Encoder is corresponding with the subclassification of classification respectively;Determining module, for determining that block is corresponding from least two candidate encoders
Subject encoder;Coding module, for using subject encoder to block coding.
According to another aspect of an embodiment of the present invention, a kind of storage medium is additionally provided, storage medium includes the journey of storage
Sequence, wherein equipment where controlling the storage medium in described program operation executes the coding method of the image.
According to another aspect of an embodiment of the present invention, a kind of processor is additionally provided, processor is used to run program,
In, the coding method of the image is executed when described program is run.
In embodiments of the present invention, image to be encoded is subjected to piecemeal, and classification belonging to each piece of determination, is any one
A or multiple at least two candidate encoders of classification and matching, at least two candidate encoders subclassification pair with the classification respectively
It answers, the corresponding subject encoder of block is determined from least two candidate encoder, described piece is compiled using subject encoder
Code.Above scheme is a variety of candidate encoders of sorted Block- matching, and from candidate encoder selection target encoder, is selected
To subject encoder be the block optimum code device, current block is encoded using subject encoder, so as to solve
Certainly in the prior art when being encoded to image, due to the technology for being difficult to that corresponding encoder is selected to cause encoding efficiency low
Problem.
Embodiment 1
According to embodiments of the present invention, a kind of embodiment of the coding method of image is provided, it should be noted that in attached drawing
Process the step of illustrating can execute in a computer system such as a set of computer executable instructions, although also,
Logical order is shown in flow charts, but in some cases, can be executed with the sequence for being different from herein it is shown or
The step of description.
Fig. 1 is the flow chart of the coding method of image according to an embodiment of the present invention, as shown in Figure 1, this method includes such as
Lower step:
Image to be encoded is carried out piecemeal, and classification belonging to each piece of determination by step S102, wherein the classification packet
It includes: picture block, character block and other blocks.
Specifically, above-mentioned image to be encoded can be the frame image in video flowing, treating coded image progress piecemeal can
To be to determine classification belonging to block according to the characteristic of writings and image in current frame image.The classification belonging to determining each piece it
Afterwards, different labels can be carried out to different classes of block.
In an alternative embodiment, image to be encoded can be divided into the macro block of 8*8, and determined belonging to each piece
Classification.
Step S104 is any one or more at least two candidate encoders of classification and matching, at least two candidate codes
Device is corresponding with the subclassification of the classification respectively.
In above-mentioned steps, can first it determine in classification with the presence or absence of subclassification, in classification there are in the case where subclassification,
Corresponding candidate encoder is matched for each subclassification.
In an alternative embodiment, by taking picture block as an example, the classification of picture block can also continue to classify, and obtain
Two seed classifications, two seed classifications are respectively therefore picture type and chart type can be the matched candidate encoder packet of picture block
It includes: picture type encoder and chart type encoder.
In an alternative embodiment, by taking character block as an example, the classification of character block can continue to classify, and obtain
To two seed classifications, two seed classifications are respectively Chinese character-shaped and alpha type, can be the matched candidate encoder of character block therefore
It include: Chinese character-shaped image encoder and alpha type image encoder
Step S106 determines the corresponding subject encoder of block from least two candidate encoder.
For a block, after for a variety of candidate encoders of Block- matching, need to select from a variety of candidate encoders
One subject encoder encodes the block.The needs of subject encoder compile block compression ratio with higher, i.e. target
Code stream after code device coding is smaller and has preferable encoding efficiency.
By taking the candidate encoder of character block is Chinese character-shaped image encoder and alpha type image encoder as an example, for current
The block for needing to encode can have better encoding efficiency using Chinese character-shaped image encoder if the Chinese character in the block is more,
If the letter in the block is more, there is better encoding efficiency using alpha type image encoder.But due to each text
In block, the distribution proportion of Chinese character or letter might not be identical, so if directly using Chinese character to the character block in image
Type encoder or the encoding efficiency that directly character block in image cannot be all optimal using alpha type encoder, therefore,
It needs that it is selected to correspond to subject encoder according to block itself.
Specifically, the index for selection target encoder can be set, such as;Code efficiency determines each time
Code efficiency when encoder being selected to encode current block, thus selection target encoder.
Step S108, using subject encoder to the block coding.
In above-mentioned steps, due to subject encoder be with the most matched candidate encoder of current block, use target
Encoder encodes block, can reach higher code efficiency.
In practical applications, identify that the result after macro block cannot be changed again, and the order of accuarcy identified also will affect volume
The performance of code compression, therefore, above scheme is controllably handled recognition result, that is, carrying out one to it according to recognition result
Mapping to more (classification results correspond to a variety of candidate encoders), so that use is corresponding after macro block determines classification every time
A variety of candidate encoders all carry out coded treatment, there are two kinds of processing modes of the same macro block, and in the two results,
It is preferentially chosen, in the method that this realizes adaptive coding, and then reaches reduction compression efficiency, protect coding efficiency
Purpose.
From the foregoing, it will be observed that image to be encoded is carried out piecemeal, and classification belonging to each piece of determination by the above embodiments of the present application,
For any one or more at least two candidate encoders of classification and matching, at least two candidate encoders respectively with the classification
Subclassification is corresponding, and the corresponding subject encoder of block is determined from least two candidate encoder, uses subject encoder pair
The block coding.Above scheme is a variety of candidate encoders of sorted Block- matching, and encodes from candidate encoder selection target
Device, the subject encoder selected are the optimum code device of the block, are encoded using subject encoder to current block, from
And be able to solve in the prior art when being encoded to image, due to being difficult to that corresponding encoder is selected to cause encoding efficiency low
Under technical problem.
Optionally, according to the above embodiments of the present application, the corresponding mesh of block is determined from least two candidate encoder
Mark encoder, comprising:
Step S1061 obtains the code efficiency of each candidate encoder.
Specifically, above-mentioned code efficiency can be used for characterizing when candidate encoder encodes block
Step S1063 determines that the highest candidate encoder of code efficiency is subject encoder.
In above-mentioned steps, with the index of code efficiency alternatively subject encoder, to be determined according to code efficiency
With the most matched subject encoder of current block.
Optionally, according to the above embodiments of the present application, the code efficiency of each candidate encoder is obtained, comprising:
Step S10611 obtains the coding parameter of each candidate encoder, wherein each candidate encoder
Coding parameter includes: encoding code stream size parameter and coding performance parameter.
Specifically, encoding code stream size can indicate the occupied bandwidth in transmission, code stream is smaller, occupied bandwidth
It is smaller, therefore wish that the encoding code stream after encoding is smaller in an encoding process;And coding performance parameter can be for evaluation figure
The PSNR of image quality amount can be obtained by calculating the Y-PSNR of candidate encoder, therefore be wished have in an encoding process
Higher coding efficiency.
Step S10613 determines the ratio between the coding performance parameter and the encoding code stream size parameter for coding ginseng
Number determines the code efficiency of each candidate encoder.
In above-mentioned steps, it regard the ratio between coding performance parameter and encoding code stream size as code efficiency, that is, passes through coding
Parameter has obtained the index for determining subject encoder, and in the case where this index is code efficiency, code efficiency is bigger,
Code stream after illustrating coding is smaller or coding efficiency is higher, can reach higher coding efficiency using lesser code stream.
Optionally, according to the above embodiments of the present application, the corresponding mesh of block is determined from least two candidate encoder
Mark encoder, comprising:
Step S1065 obtains the coding parameter of each candidate encoder, wherein the coding parameter of each candidate encoder
It include: encoding code stream size parameter and coding performance parameter.
Specifically, above-mentioned coding parameter has identical meaning with the coding parameter in step S10611.
Step S1067 successively compares the coding parameter of two candidate encoders, and compared according to comparison result from participation
A candidate encoder is selected in two candidate encoders.
In above-mentioned steps, coding parameter includes encoding code stream size parameter and coding performance parameter, when being compared,
It needs for two parameters to be all compared.The candidate code opposite for the comparison result of encoding code stream size and coding efficiency
Device selects encoding code stream size smaller, the biggish encoder of coding efficiency;And for the ratio of encoding code stream size and coding efficiency
Candidate encoder identical compared with result, then it needs to be determined that the encoding code stream size of candidate encoder higher for coding efficiency with
The ratio between the encoding code stream size of the lower candidate encoder of coding efficiency, to be selected according to ratio.
The candidate encoder of selection is compared by step S1069 with next candidate encoder, until all is described
Candidate encoder all compares, and determines that the candidate encoder of final choice is the subject encoder.
In classification tool there are two in the case where candidate encoder, subject encoder can be obtained by once comparing, having
In the case where having n candidate encoder, need that subject encoder can be obtained by n-1 comparison.
Optionally, according to the above embodiments of the present application, the coding parameter of each candidate encoder includes: successively to compare
The coding parameter of two candidate encoders, and waited for selection one from two candidate encoders for participating in comparing according to comparison result
Select encoder, comprising:
Step S10671, in the case where the first code stream is less than the second code stream, if the first coding efficiency is greater than or equal to
Second coding efficiency then selects the first candidate encoder, wherein first code stream and first coding efficiency are to participate in ratio
Compared with two candidate encoders in the first candidate encoder coding parameter, second code stream and second coding efficiency are
Participate in the coding parameter of the second candidate encoder in two candidate encoders compared.
In above-mentioned steps, in the case where the first code stream is less than the second code stream, if the first coding efficiency is greater than or waits
In the second coding efficiency, illustrate that the first candidate encoder is able to use lesser code stream and obtains higher or equal coding efficiency,
In order to save bandwidth, the first candidate encoder is selected.
Step S10673, in the case where first code stream is less than second code stream, if described first is Encoding
Second coding efficiency can be less than, then judge the ratio of the first code stream and second code stream whether less than the first preset value,
First candidate encoder is selected in the case where ratio is less than the first preset value.
In above-mentioned steps, the first code stream is less than the second code stream, while the first coding efficiency is less than the second coding efficiency, because
This can determine that the second candidate encoder has obtained preferable coding efficiency using biggish code stream, in order to select one of time
Select encoder, it is thus necessary to determine that, the corresponding code stream of the second candidate encoder code stream whether corresponding with the first candidate encoder
Differ larger, if difference is larger, It is not necessary to exchange the promotion of coding efficiency for using biggish code stream, if difference compared with
It is small, then it can choose the second candidate encoder.
In order to determine whether biggish second candidate encoder of necessary choice code stream, can by judge the first code stream with
Whether the ratio of second code stream determine less than the first preset value, specifically, since the first code stream is less than the second code stream, because
The ratio of this first code stream and the second code stream is in section (0,1), can be set above-mentioned first preset value be (1/1.5), when than
When value is less than the first preset value, illustrate that the gap of the first code stream and the second code stream is larger, is then exchanged for without using biggish code stream
Coding efficiency is promoted, and selects the first candidate encoder;When ratio is greater than or equal to the first preset value, illustrate the first code stream and the
The gap of two code streams is smaller, can choose the second candidate encoder
Step S10675, in the case where first code stream is greater than second code stream, if described first is Encoding
Second coding efficiency can be less than or equal to, then select second candidate encoder.
In above-mentioned steps, in the case where the first code stream is greater than the second code stream, if the first coding efficiency is less than or waits
In the second coding efficiency, illustrate that the second candidate encoder is able to use lesser code stream and obtains higher or equal coding efficiency,
In order to save bandwidth, then the second candidate encoder is selected.
Step S10677, in the case where first code stream is greater than second code stream, if described first is Encoding
Second coding efficiency can be greater than, then judge whether the ratio of second code stream and first code stream is default less than second
Value, first candidate encoder is selected in the case where the ratio is less than the second preset value.
Above-mentioned steps S10677 is identical as the principle of step S10673, since the first code stream is greater than the second code stream, the
The ratio of two code streams and the first code stream also belongs to section (0,1), and it is (1/1.5) that the second preset value, which equally can be set,.
Optionally, according to the above embodiments of the present application, the corresponding candidate encoder of the picture block includes: chart type picture
Encoder, and/or picture type image encoder.
Optionally, according to the above embodiments of the present application, the corresponding candidate encoder of the character block includes: Chinese character-shaped picture
Encoder, and/or alpha type image encoder.
Fig. 2 as shown in connection with fig. 2, is shown at this according to a kind of flow chart of optional coding method of the embodiment of the present application
In example by taking character block as an example, coding method provided by the above embodiment is described in detail;
Step S21 generates the block of m*n.In above-mentioned steps, the frame W × H in screen video is obtained, and be divided into m
The block of × n.
Step S22, the type of decision block.In above-mentioned steps, block is divided by the characteristic that can use text and picture
Character block, picture block and other blocks, having a size of (W/m) × (H/n).If block type is character block, S23 is entered step, such as
Fruit block type is picture block, then enters step S26, if block type is other blocks, enters step S29.
In this example, for i-th of macro block, if its result has been divided into character block, then utilizing Chinese character-shaped text
Encoder and alphabet type letters encoder carry out compressed encoding processing to the macro block as candidate encoder.Below to how right
Selection target coding is illustrated:
Step S23 selects coding mode.S24 is entered step when selecting coding mode to encode for Chinese character-shaped image, is being selected
The coding mode selected is that alpha type image enters step S25 when encoding.
The performance fiducial value for obtaining two different candidate encoders, such as encoding code stream size S and coding efficiency P.It compiles
Code code stream size can be directly obtained by the coding result of literal code device, and coding efficiency can calculate the peak of candidate encoder
Value signal-to-noise ratio carries out calculating acquisition, that is, evaluates the PSNR of picture quality.
According to above-mentioned steps, if the first encoder 1 and second encoder 2 be expressed as Chinese character-shaped candidate encoder and
Alpha type candidate encoder, then encoding code stream the size parameter Si1 and Si2 of the text macro block can be obtained respectively, while can also
Obtain coding performance parameter Pi1 and Pi2.
As Si1<Si2, if Pi1>Pi2, candidate encoder 1 is chosen as subject encoder, the block is carried out finally
Coded treatment;If Pi1=Pi2, candidate encoder 1 is still chosen as subject encoder, the block is carried out at final coding
Reason;If when Pi1 < Pi2, if (Si1/Si2) < (1/1.5), chooses candidate encoder 1, otherwise, choosing candidate encoder
2。
As Si1>Si2, if Pi1>Pi2, if (Si2/Si1)<(1/1.5), chooses candidate encoder 2, otherwise, choosing
Take candidate encoder 1;If Pi1=Pi2, candidate encoder 2 is chosen as subject encoder and carries out final coding to the block
Processing;If when Pi1 < Pi2, choosing candidate encoder 2 as subject encoder and carrying out final coded treatment to the block.
Step S24 calls Chinese character-shaped image encoder to encode block.
Step S25 calls alpha type image encoder to encode block.
Step S26 selects coding mode picture block to can be used the side similar with step S23 in above-mentioned steps
The coding mode of formula selection block.
Step S27 calls picture type image encoder.
Step S28, calling figure phenotype image encoder.
Step S29 calls other image encoders.
Step S210 is encoded by the corresponding encoder of block.