Image coding method and device

文档序号:912771 发布日期:2021-02-26 浏览:22次 中文

阅读说明:本技术 图像编码方法及装置 (Image coding method and device ) 是由 郭鲲 于 2020-10-28 设计创作,主要内容包括:本公开提供一种图像编码方法及装置,涉及图像处理技术领域,能够解决相关技术中使用小波变换对图像进行编码时编码速度慢的问题。具体技术方案为:本公开实施例提供的图像编码方法,包括:对图像进行三级小波变换后,将LL3子带按照预设更新方式进行更新;扫描所有子带,获取预设数值的出现频率,并根据出现频率产生哈夫曼编码表;对LL3子带和非LL3子带分别采用不同的编码方式进行编码;根据每一个子带对应的编码数据得到图像的编码码流;其中,根据三级小波变换后图片的特点,对不同子带采用不同的编码方法,从而可以达到编码速度快、码流较低的效果。(The present disclosure provides an image encoding method and apparatus, which relates to the technical field of image processing and can solve the problem of slow encoding speed when encoding an image by using wavelet transform in the related art. The specific technical scheme is as follows: the image coding method provided by the embodiment of the disclosure comprises the following steps: after the image is subjected to three-level wavelet transform, updating the LL3 sub-band according to a preset updating mode; scanning all sub-bands, acquiring the occurrence frequency of a preset numerical value, and generating a Huffman coding table according to the occurrence frequency; respectively encoding the LL3 sub-band and the non-LL 3 sub-band by adopting different encoding modes; obtaining an encoding code stream of the image according to the encoding data corresponding to each sub-band; according to the characteristics of the image after the three-level wavelet transform, different coding methods are adopted for different sub-bands, so that the effects of high coding speed and low code stream can be achieved.)

1. An image encoding method, characterized in that the method comprises:

after the image is subjected to three-level wavelet transform, updating the LL3 sub-band according to a preset updating mode;

scanning all sub-bands, acquiring the occurrence frequency of a preset numerical value, and generating a Huffman coding table according to the occurrence frequency;

encoding each of said sub-bands;

obtaining the coding code stream of the image according to the coding data corresponding to each sub-band;

wherein said encoding each of said sub-bands comprises:

acquiring a sub-band to be coded, and judging whether the current sub-band to be coded is an LL3 sub-band;

if the LL3 sub-band is adopted, the Huffman coding mode is used for coding;

if the sub-band is not the LL3 sub-band, encoding by using a run length encoding improvement algorithm to obtain intermediate encoded data;

and coding the intermediate coded data by using an adaptive arithmetic coding mode.

2. The method according to claim 1, wherein the updating LL3 sub-band according to a preset updating manner comprises:

and replacing the current element with a result of subtracting the adjacent previous element from the current element in the LL3 sub-band.

3. The method of claim 1, wherein encoding using a run-length coding refinement algorithm to obtain the inter-coded data if the sub-band other than LL3 is not included, comprises:

performing the following encoding for each element to be encoded in the sub-band other than the LL3 sub-band:

judging whether the current element to be coded is zero or not;

if the current element to be coded is zero, adding one to the counter;

if the current element to be coded is not zero, converting the value of the counter into binary digits;

replacing the binary digits with preset symbols to obtain replacement data;

clearing the counter;

and obtaining the intermediate coded data of the current element to be coded according to the replacement data and the Huffman code corresponding to the current element to be coded.

4. The method of claim 3, wherein the replacing the binary digits with the preset symbols results in replacement data, comprising:

replacing a 1 in the binary digit with a positive sign;

a negative sign is used to replace a 0 in the binary digit.

5. The method according to any one of claims 1 to 4, wherein the predetermined value is a value other than 0.

6. An image encoding device characterized by comprising:

the updating module is used for updating the LL3 sub-band according to a preset updating mode after the three-level wavelet transformation is carried out on the image;

the encoding table generating module is used for scanning all sub-bands, acquiring the occurrence frequency of a preset numerical value and generating a Huffman encoding table according to the occurrence frequency;

an encoding module for encoding each of the sub-bands;

the code stream generating module is used for obtaining the coding code stream of the image according to the coding data corresponding to each sub-band;

wherein the encoding module comprises:

the first judgment submodule is used for acquiring a sub-band to be coded and judging whether the sub-band to be coded is an LL3 sub-band or not;

the first coding sub-module is used for coding by using a Huffman coding mode if the current sub-band to be coded is the LL3 sub-band;

the second coding submodule is used for coding by using a run length coding improvement algorithm to obtain intermediate coded data if the current sub-band to be coded is not the LL3 sub-band;

and the third coding submodule is used for coding the intermediate coded data by using an adaptive arithmetic coding mode.

7. The apparatus of claim 6, wherein the update module comprises:

and the updating submodule is used for replacing the current element by a result obtained by subtracting the adjacent previous element from the current element in the LL3 sub-band.

8. The apparatus of claim 6, wherein the second encoding submodule comprises:

the second judgment submodule is used for judging whether the current element to be coded is zero or not;

a first processing submodule, configured to increment a counter by one if the current element to be encoded is zero;

the conversion submodule is used for converting the value of the counter into binary digits if the current element to be coded is not zero;

the replacing submodule is used for replacing the binary digits with preset symbols to obtain replacing data;

the second processing submodule is used for resetting the counter;

and the obtaining submodule is used for obtaining the intermediate coded data of the current element to be coded according to the replacement data and the Huffman code corresponding to the current element to be coded.

9. The apparatus of claim 8, wherein the replacement sub-module comprises:

a first replacement subunit for replacing a 1 in the binary digit with a positive sign;

a second replacement subunit for replacing a 0 in the binary digit with a negative sign.

10. The device according to any one of claims 6 to 9, wherein the predetermined value is a value other than 0.

Technical Field

The present disclosure relates to the field of image processing, and in particular, to an image encoding method and apparatus.

Background

Currently, image coding methods for wavelet transform are: ECBOT, used in JPEG2000, embeds zero-tree wavelets (EZW) and a multilevel tree Set splitting algorithm (SPIHT).

However, in the above coding scheme, the coding method used by ECBOT is too slow; the EZW coding speed is also slower; the SPIHT method requires that the length and width of a picture are both 2n, and the larger the picture, the slower the encoding speed.

Disclosure of Invention

The embodiment of the disclosure provides an image coding method and device, which can solve the problem of low coding speed when wavelet transform is used for coding an image in the related art. The technical scheme is as follows:

according to a first aspect of embodiments of the present disclosure, there is provided an image encoding method, the method including:

after the image is subjected to three-level wavelet transform, updating the LL3 sub-band according to a preset updating mode;

scanning all sub-bands, acquiring the occurrence frequency of a preset numerical value, and generating a Huffman coding table according to the occurrence frequency;

encoding each of said sub-bands;

obtaining the coding code stream of the image according to the coding data corresponding to each sub-band;

wherein said encoding each of said sub-bands comprises:

acquiring a sub-band to be coded, and judging whether the current sub-band to be coded is an LL3 sub-band;

if the LL3 sub-band is adopted, the Huffman coding mode is used for coding;

if the sub-band is not the LL3 sub-band, coding by using a run length coding improvement algorithm to obtain intermediate coded data;

and coding the intermediate coded data by using an adaptive arithmetic coding mode.

The image coding method provided by the embodiment of the disclosure comprises the following steps: after the image is subjected to three-level wavelet transform, updating the LL3 sub-band according to a preset updating mode; scanning all sub-bands, acquiring the occurrence frequency of a preset numerical value, and generating a Huffman coding table according to the occurrence frequency; encoding each sub-band; obtaining an encoding code stream of the image according to the encoding data corresponding to each sub-band; wherein encoding each sub-band comprises: acquiring a sub-band to be coded, and judging whether the current sub-band to be coded is an LL3 sub-band; if the LL3 sub-band is adopted, the Huffman coding mode is used for coding; if the sub-band is not the LL3 sub-band, encoding by using a run length encoding improvement algorithm to obtain intermediate encoded data; the intermediate encoded data is encoded using an adaptive arithmetic coding scheme. According to the characteristics of the image after the three-level wavelet transform, different coding methods are adopted for different sub-bands, so that the effects of high coding speed and low code stream can be achieved.

In one embodiment, the updating the LL3 sub-band according to a preset updating manner includes:

and replacing the current element with the result of subtracting the adjacent previous element from the current element in the LL3 sub-band.

In one embodiment, if the sub-band is not the LL3 sub-band, the encoding using the run-length coding improvement algorithm to obtain the inter-coded data includes:

performing the following encoding for each element to be encoded in the sub-band other than the LL3 sub-band:

judging whether the current element to be coded is zero or not;

if the current element to be coded is zero, adding one to the counter;

if the current element to be coded is not zero, converting the value of the counter into binary digits;

replacing the binary digits with preset symbols to obtain replacement data;

clearing the counter;

and obtaining the intermediate coded data of the current element to be coded according to the replacement data and the Huffman coding corresponding to the current element to be coded.

In one embodiment, the replacing the binary digits with the preset symbols obtains replacement data, including:

replacing a 1 in the binary digit with a positive sign;

a negative sign is used to replace a 0 in the binary digit.

In one embodiment, the predetermined value is a non-0 value.

According to a second aspect of the embodiments of the present disclosure, there is provided an image encoding device including:

the updating module is used for updating the LL3 sub-band according to a preset updating mode after three-level wavelet transformation is carried out on the image;

the coding table generating module is used for scanning all sub-bands, acquiring the occurrence frequency of a preset value and generating a Huffman coding table according to the occurrence frequency;

an encoding module for encoding each of the sub-bands;

the code stream generating module is used for obtaining the coding code stream of the image according to the coding data corresponding to each sub-band;

wherein the encoding module comprises:

the first judgment submodule is used for acquiring a sub-band to be coded and judging whether the sub-band to be coded is an LL3 sub-band or not;

the first coding sub-module is used for coding by using a Huffman coding mode if the current sub-band to be coded is the LL3 sub-band;

the second coding submodule is used for coding by using a stroke length coding improvement algorithm to obtain intermediate coded data if the current sub-band to be coded is not the LL3 sub-band;

and the third coding sub-module is used for coding the intermediate coded data by using an adaptive arithmetic coding mode.

In one embodiment, the update module comprises:

and the updating submodule is used for replacing the current element by a result obtained by subtracting the adjacent previous element from the current element in the LL3 sub-band.

In one embodiment, the second encoding submodule includes:

the second judgment submodule is used for judging whether the current element to be coded is zero or not;

a first processing submodule, configured to increment a counter by one if the current element to be encoded is zero;

the conversion submodule is used for converting the value of the counter into binary digits if the current element to be coded is not zero;

the replacing submodule is used for replacing the binary digits with preset symbols to obtain replacing data;

the second processing submodule is used for resetting the counter;

and the obtaining submodule is used for obtaining the intermediate coded data of the current element to be coded according to the replacement data and the Huffman code corresponding to the current element to be coded.

In one embodiment, the replacement sub-module comprises:

a first replacement subunit for replacing a 1 in the binary digit with a positive sign;

a second replacement subunit for replacing a 0 in the binary digit with a negative sign.

In one embodiment, the predetermined value is a non-0 value.

It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.

Drawings

The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure.

Fig. 1 is a flowchart of an image encoding method provided by an embodiment of the present disclosure;

FIG. 2 is a schematic diagram of the distribution of sub-bands after a three-level wavelet transform provided by the embodiment of the present disclosure;

fig. 3 is a flowchart of an image encoding method provided by an embodiment of the present disclosure;

fig. 4 is a flowchart of an image encoding method provided by an embodiment of the present disclosure;

fig. 5 is a flowchart of an image encoding method provided by an embodiment of the present disclosure;

fig. 6 is a block diagram of an image encoding apparatus according to an embodiment of the present disclosure;

fig. 7 is a block diagram of an update module in an image encoding apparatus according to an embodiment of the present disclosure;

fig. 8 is a structural diagram of a second encoding sub-module in the image encoding apparatus according to the embodiment of the present disclosure.

Fig. 9 is a structural diagram of an alternative sub-module in an image encoding device according to an embodiment of the present disclosure.

Detailed Description

Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.

An embodiment of the present disclosure provides an image encoding method, as shown in fig. 1, the image encoding method including the steps of:

101. and after the image is subjected to three-level wavelet transform, updating the LL3 sub-band according to a preset updating mode.

After the image is subjected to three-level wavelet transform, the distribution of each subband (subband) is shown in fig. 2.

102. And scanning all sub-bands, acquiring the occurrence frequency of a preset numerical value, and generating a Huffman coding table according to the occurrence frequency.

Exemplary, wherein the preset value is a non-0 value. That is, all sub-bands are scanned, the occurrence frequencies of all values except 0 are counted, and a Huffman code table is generated according to the frequencies.

103. Each subband is encoded.

104. And obtaining the coding code stream of the image according to the coding data corresponding to each sub-band.

The statistical finding shows that: the LL3 subband has the least number of 0 and the remaining subbands have more 0, and since the processing of the subbands with more 0 does not greatly affect the size of the encoded code, a respective coding algorithm is designed according to the characteristics of each subband, and specifically, each subband is encoded, including the following sub-steps:

1031. and acquiring a sub-band to be coded, and judging whether the current sub-band to be coded is the LL3 sub-band.

1032. If the LL3 sub-band is used, the encoding is performed by using a Huffman encoding method.

1033. If not the LL3 sub-band, the intermediate coded data is encoded using a run-length coding refinement algorithm.

1034. The intermediate encoded data is encoded using an adaptive arithmetic coding scheme.

When the sub-band to be coded is judged to be the LL3 sub-band, the sub-band to be coded can be directly coded by using a Huffman coding mode, and when the sub-band to be coded is judged not to be the LL3 sub-band, the sub-band to be coded can be coded by using a Run Length Encoding (RLE) improved algorithm to obtain intermediate coded data, which can also be called as an intermediate result, and then the intermediate result is coded by using an adaptive arithmetic coding mode.

The method of encoding using the adaptive arithmetic coding method is similar to that in the related art, and is not described herein again.

It should be noted that the above steps 1031-1034 are performed in a loop, that is, after the steps 1031-1034 are performed on the current sub-band to be encoded, the encoded data corresponding to the current sub-band to be encoded is obtained, and then the steps 1031-1034 are continuously performed on the next sub-band to be encoded, so as to obtain the encoded data corresponding to the next sub-band to be encoded, and so on until all the sub-bands to be encoded are processed.

In the process of obtaining the coding code stream of the image, the coded data can be directly stored in the coding code stream of the image after each sub-band to be coded is coded, or the coded data can be uniformly put in the coding code stream of the image after all the sub-bands to be coded are coded, and the disclosure does not limit the data.

The image coding method provided by the embodiment of the disclosure comprises the following steps: after the image is subjected to three-level wavelet transform, updating the LL3 sub-band according to a preset updating mode; scanning all sub-bands, acquiring the occurrence frequency of a preset numerical value, and generating a Huffman coding table according to the occurrence frequency; encoding each sub-band; obtaining an encoding code stream of the image according to the encoding data corresponding to each sub-band; wherein encoding each sub-band comprises: acquiring a sub-band to be coded, and judging whether the current sub-band to be coded is an LL3 sub-band; if the LL3 sub-band is adopted, the Huffman coding mode is used for coding; if the sub-band is not the LL3 sub-band, encoding by using a run length encoding improvement algorithm to obtain intermediate encoded data; the intermediate encoded data is encoded using an adaptive arithmetic coding scheme. According to the characteristics of the image after the three-level wavelet transform, different coding methods are adopted for different sub-bands, so that the effects of high coding speed and low code stream can be achieved.

In one embodiment, the LL3 sub-band is updated according to a preset update mode, which includes the following sub-steps:

the current element is replaced by the result of subtracting the adjacent previous element from the current element in the LL3 sub-band.

After the image is subjected to three-level wavelet transform, the LL3 sub-band is transformed, the former element is subtracted from the latter element in the sub-band, and the processed result is stored in the original LL3 sub-band position.

For example: {100, 103, 105}, after processing becomes {100, 3, 2 }.

By replacing the current element with the result of subtracting the adjacent previous element from the current element in the LL3 sub-band, the magnitude of the current element can be significantly reduced, thereby significantly reducing the bandwidth required to obtain encoded data.

In one embodiment, as shown in FIG. 3, the above step 1033 includes the following sub-steps:

for each element to be encoded in a sub-band other than the LL3 sub-band, the following encoding is performed:

10331. and judging whether the current element to be coded is zero or not.

10332. If the current element to be encoded is zero, the counter is incremented by one.

10333. If the current element to be encoded is not zero, the value of the counter is converted into a binary digit.

10334. The binary digits are replaced with preset symbols to obtain replacement data.

For example, replacing binary digits with preset symbols results in replacement data, including:

replacing a 1 in the binary digit with a positive sign; a negative sign is used to replace a 0 in a binary digit.

That is, a "-" is used in place of "0", and a "+" is used in place of "1".

For example: the counter has a value of 6. Converted to binary and then to "110". Replacing "0" with "-", and replacing "1" with "+" yields "+ + -".

It should be noted that the correspondence between the preset symbols and the binary digits is only an example, and in practical applications, the preset symbols of the previous day may also be used, for example: replacing 1 in binary digits with a by using characters as preset symbols; b replaces 0's in binary digits, etc.

10335. The counter is cleared.

10336. And obtaining intermediate coded data of the current element to be coded according to the replacement data and the Huffman code corresponding to the current element to be coded.

It should be noted that the above-mentioned steps 10331 and 10336 are performed in a loop, that is, after the steps 10331 and 10336 are performed on the current element to be encoded, the intermediate encoded data corresponding to the current element to be encoded is obtained, then the steps 10331 and 10336 are performed on the next element to be encoded continuously, the intermediate encoded data corresponding to the next element to be encoded is obtained, and so on until all the elements to be encoded are processed.

By improving the existing RLE algorithm, intermediate coded data is obtained first, and then the intermediate coded data is coded in a self-adaptive arithmetic coding mode, so that the size of a code stream obtained after coding can be effectively reduced.

An embodiment of the present disclosure provides an image encoding method, as shown in fig. 4, the image encoding method including the steps of:

1. after performing a three-level wavelet transform on the image, the LL3 subband is first transformed by subtracting the previous element from the next element in the subband.

For example: {100, 103, 105}, after processing becomes {100, 3, 2 }. The processed result is stored in the original LL3 subband position.

2. Scanning all sub-bands, counting the occurrence frequency of all values except 0, and generating a Huffman code table according to the frequency.

3. An uncoded sub-band is obtained and a determination is made as to whether the currently coded sub-band is the LL3 sub-band.

3.1 if it is currently the LL3 sub-band. And directly coding by using a Huffman coding mode, and then storing the coded code stream.

3.2 if not currently the LL3 sub-band. The middle result is obtained by using an RLE (run length encoding) improved algorithm. Then, the code is coded by arithmetic coding, and the coded code stream is stored.

4. If all sub-bands have been encoded, the procedure is ended. Otherwise go to step 2.

The embodiment of the present disclosure provides an implementation method of an RLE improvement algorithm, as shown in fig. 5, the implementation method of the RLE improvement algorithm includes the following steps:

1. one element that has not yet been encoded is obtained from the subband.

2. It is determined whether the element is zero.

2.1 if the element is 0, increment the counter by one.

2.2 if the element is not 0, the value of the counter is converted into the following form. First, the value of the counter is converted into a binary form. Then, "-" is used in place of "0", and "+" is used in place of "1".

For example: the counter has a value of 6. Converted to binary and then to "110". Replacing "0" with "-", and replacing "1" with "+" yields "+ + -". The counter is then cleared. Finally, the above run length conversion result and the Huffman coding result of the current value are recorded.

3. It is determined whether all elements have been processed. If all processing is completed, the routine ends. If not, go to step 1.

Based on the image encoding methods described in the embodiments corresponding to fig. 1-5 above, the following are embodiments of the apparatus of the present disclosure, which may be used to perform the embodiments of the method of the present disclosure.

An embodiment of the present disclosure provides an image encoding apparatus, as shown in fig. 6, including:

the updating module 11 is configured to update the LL3 subband according to a preset updating mode after performing three-level wavelet transform on an image;

the encoding table generating module 12 is configured to scan all sub-bands, obtain an occurrence frequency of a preset value, and generate a huffman encoding table according to the occurrence frequency;

an encoding module 13 for encoding each of said sub-bands;

a code stream generating module 14, configured to obtain an encoded code stream of the image according to the encoded data corresponding to each sub-band;

wherein the encoding module 13 comprises:

the first determining submodule 131 is configured to obtain a sub-band to be encoded, and determine whether the sub-band to be encoded currently is an LL3 sub-band;

a first encoding sub-module 132, configured to perform encoding using a huffman encoding method if the subband to be encoded currently is the LL3 subband;

the second encoding submodule 133 is configured to, if the subband to be encoded currently is not the LL3 subband, perform encoding by using a run-length encoding improvement algorithm to obtain intermediate encoded data;

a third encoding sub-module 134 for encoding the intermediate encoded data using adaptive arithmetic coding.

In one embodiment, as shown in fig. 7, the update module 11 includes:

and an update submodule 111 for replacing the current element with a result of subtracting an adjacent previous element from the current element in the LL3 subband.

In one embodiment, as shown in fig. 8, the second encoding submodule 133 includes:

a second determining submodule 1331, configured to determine whether the current element to be encoded is zero;

a first processing submodule 1332, configured to increment a counter by one if the current element to be encoded is zero;

a conversion sub-module 1333, configured to convert the value of the counter into a binary number if the current element to be encoded is not zero;

a replacing submodule 1334, configured to replace the binary digits with preset symbols to obtain replaced data;

a second processing submodule 1335, configured to zero the counter;

an obtaining submodule 1336, configured to obtain the intermediate encoded data of the current element to be encoded according to the replacement data and the huffman code corresponding to the current element to be encoded.

In one embodiment, as shown in fig. 9, the replacement submodule 1334 includes:

a first replacement subunit 13341 for replacing a 1 in the binary digit with a positive sign;

a second replacement subunit 13342 for replacing a 0 in the binary digit with a negative sign.

In one embodiment, the predetermined value is a non-0 value.

Based on the image encoding method described in the embodiments corresponding to fig. 1 to fig. 5, embodiments of the present disclosure further provide a computer-readable storage medium, for example, the non-transitory computer-readable storage medium may be a Read Only Memory (ROM), a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like. The storage medium stores computer instructions for executing the image encoding method described in the embodiment corresponding to fig. 1 to 5, which is not described herein again.

Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.

It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

17页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种结合卷积神经网络的HEVC视频质量增强算法框架

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类