[go: up one dir, main page]

CN114332261A - Picture compression method - Google Patents

Picture compression method Download PDF

Info

Publication number
CN114332261A
CN114332261A CN202111657376.6A CN202111657376A CN114332261A CN 114332261 A CN114332261 A CN 114332261A CN 202111657376 A CN202111657376 A CN 202111657376A CN 114332261 A CN114332261 A CN 114332261A
Authority
CN
China
Prior art keywords
format
color
colors
storage
length
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202111657376.6A
Other languages
Chinese (zh)
Other versions
CN114332261B (en
Inventor
庄洵
李强
高圩
王立
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Isvision Hangzhou Technology Co Ltd
Original Assignee
Isvision Hangzhou Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Isvision Hangzhou Technology Co Ltd filed Critical Isvision Hangzhou Technology Co Ltd
Priority to CN202111657376.6A priority Critical patent/CN114332261B/en
Publication of CN114332261A publication Critical patent/CN114332261A/en
Application granted granted Critical
Publication of CN114332261B publication Critical patent/CN114332261B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

The invention discloses a picture compression method, which comprises the following steps: 1) determining the background color of a single picture, and dividing the picture elements; 2) screening the primitives with the pixels of the background color, filtering, and recording the remaining primitives as the primitives to be coded; 3) determining a basic color; replacing all basic colors in the graphic primitive with K; determining encoding format types of all non-K pixels in the primitive to be encoded according to the encoding level selected by a user, acquiring a format with the minimum storage length in each format in the same encoding level, and compressing and storing the primitive; when the format with the minimum storage length of each format in the same coding level is obtained, the storage lengths of the formats I to IV are obtained through calculation, and the storage length of the format five is obtained based on the coding result. The image compression method can compress the image to a certain degree in a short time, not only meets the requirement of a beat, but also reduces the transmission and storage pressure to a certain degree.

Description

Picture compression method
Technical Field
The invention relates to the field of visual detection, in particular to a picture compression method.
Background
When measuring and identifying high-speed objects by using machine vision, a gray-scale image is collected generally. At the moment, the acquisition frequency of the images is high, the quantity of the images is large, BMP coding is generally adopted, the BMP coding speed is high, the images are lossless, image data are not compressed, and the transmission and storage pressure is large. Currently, commonly used compression algorithms are JPEG, PNG, ZLIB, LZ4, and the like. JPEG is lossy compression, and in consideration of the fact that noise needs to be avoided in application, a lossless compression technology is adopted, so that JPEG is eliminated; PNG is lossless compression and is a special compression algorithm for images, but the compression speed is sacrificed due to pursuit of higher compression rate; ZLIB and LZ4 are general binary compression algorithms that are not stable to the compression rate of the image.
In practical use, the requirement of the production tact needs to be met, so that an image compression algorithm capable of giving consideration to both the compression rate and the compression speed is urgently needed.
Disclosure of Invention
In order to solve the above technical problems, the present invention provides a method for compressing an image, which can compress an image to a certain extent in a short time, so that the image meets the requirement of a beat, and the transmission and storage pressure is reduced to a certain extent.
Therefore, the technical scheme of the invention is as follows:
a picture compression method comprises the following steps:
1) determining the background color of a single picture, and dividing the picture elements according to the width x and the height y;
2) screening the primitives of which the internal pixels are all background colors, filtering, and recording the remaining primitives as the primitives to be coded;
3) taking the background color of a single picture, the background color of a primitive to be coded or the background color of a determined primitive to be coded in a specific area as a basic color; replacing all basic colors in the graphic elements with K, wherein K represents a color value with the lowest brightness; (usually K is 0)
Determining encoding format types of all non-K pixels in the primitive to be encoded according to the encoding level selected by a user, acquiring a format with the minimum storage length in each format in the same encoding level, and compressing and storing the primitive;
the storage content represented by the first format comprises the following sequentially recorded contents: primitive index, format one number, and color of pixel position arrangement; the original storage format of the primitive to be coded is format one;
the storage content represented by the second format comprises the following sequentially recorded contents: the method comprises the steps of primitive indexing, format two numbers, non-K color numbers, colors recorded in sequence and position numbers corresponding to the colors;
the storage content represented by the third format comprises the following sequentially recorded contents: primitive index, format three number, non-K color number, and each color, the number of positions where the corresponding color appears and each position recorded in sequence;
the storage content represented by the format four comprises the following sequentially recorded contents: primitive index, format four number, color total number, and variable length coding of difference value of each color, first position of corresponding color, subsequent position value and previous position value recorded in sequence, ending symbol; the variable length coding refers to that codes with different lengths are selected based on the occurrence frequency of the difference value during coding, the occurrence frequency is high, and the coding length is short;
the storage content represented by the fifth format comprises the following sequentially recorded contents: primitive index, format five number, number of colors contained in color group, and color sequence in each color group;
the colors in a single color group are determined as follows: determining from most to least according to the number of colors contained in the color group and the occurrence frequency of each pixel in the primitive to be coded;
the color sequence comprises colors in a color group, the total number of positions corresponding to all the colors, a color index array for recording the appearance sequence of the colors in the color group and a bitmap for recording the positions of the residual uncoded colors;
when the format with the minimum storage length of each format in the same coding level is obtained, the storage lengths of the formats I to IV are calculated and obtained according to the following method, and the storage length of the format V is obtained based on the coding result:
the length of the storage in format one is x y;
the total number of positions with length of 2 times of non-K colors is stored in format two;
the length of the storage in format three is 2 times of the total number of non-K colors and the total number of positions of the non-K colors;
the length stored in the format four is 2 times of the sum of the total number of the non-K colors and the variable length coding length of the position interval of each non-K color; the length of the position-distance variable-length codes is 1+ and the positions except the head position correspond to the distance of the previous position.
Further, when the format five is used for storing, the method also comprises the step of storing the residual uncoded colors and the corresponding positions thereof according to the format two or the format one;
wherein the remaining unencoded colors are determined as follows:
after the color sequence of each color group is determined, if the storage length is greater than or equal to the length of the pixel corresponding to the color in the color group stored according to the format one, the current color group and the color not yet coded are recorded as the residual uncoded color.
Further, when the format four is used for storage, the storage sequences of different colors are sorted from most to least according to the occurrence times of the colors in the primitive to be coded. Furthermore, when the format four is used for storage, the difference value of the first position value and the subsequent position value of a single color compared with the previous position value is recorded, the length of format storage of the ending symbol is Z, and if Z is larger than or equal to the total length of the storage of the current color related pixel according to the format one, the current color and other uncoded color related pixels are stored according to the format one.
Further, the encoding format type determined by the encoding level is:
coding level one: a first format;
coding level two: format one, format two;
coding level three: format one, format two and format three;
coding level four: format one, format two, format three and format four;
coding level five: format one, format two, format three, format four, and format five.
Further, when the primitives are divided, firstly, the single picture is expanded by using the background color, so that the width and the height of the single picture are respectively the minimum integral multiple of x and y, and then the primitives are divided.
Further, the number of colors included in the color group is 2, 4, 8, or 16.
Further, the storage of the primitive contains the position information of the single primitive in a single picture.
The image compression method can compress the image to a certain degree in a short time, so that the image compression method not only meets the requirement of the beat, but also reduces the transmission and storage pressure to a certain degree, and has a good compression effect on gray level images collected by an industrial camera, such as structured light images and images obtained by detecting a workpiece to be detected by a fixed position.
Drawings
FIG. 1 is a schematic diagram of five formats of stored contents in the compression method provided by the present invention;
FIG. 2 is an example of variable length coding;
fig. 3 is a graph of compression efficiency for different compression methods.
Detailed Description
The technical solution of the present invention is described in detail below with reference to the accompanying drawings and the detailed description.
A picture compression method comprises the following steps:
1) determining the background color of a single picture, and dividing the picture elements according to the width x and the height y; in order to ensure that a single picture is completely divided into a plurality of primitives, the width and the height of the single picture are respectively ensured to be minimum integral multiples of x and y, and the method for meeting the requirement comprises the following steps: firstly, expanding a single picture by using a background color, and then dividing a primitive;
2) screening the primitives of which the internal pixels are all background colors, filtering, and recording the remaining primitives as the primitives to be coded;
3) taking the background color of a single picture, the background color of a primitive to be coded or the background color of a determined primitive to be coded in a specific area as a basic color; replacing all basic colors in the graphic elements with K, wherein K represents a color value with the lowest brightness; (usually K is 0)
Determining encoding format types of all non-K pixels in the primitive to be encoded according to the encoding level selected by a user, acquiring a format with the minimum storage length in each format in the same encoding level, and compressing and storing the primitive;
specifically, the method comprises the following steps: the encoding format type determined by the encoding level is as follows:
coding level one: a first format;
coding level two: format one, format two;
coding level three: format one, format two and format three;
coding level four: format one, format two, format three and format four;
coding level five: format one, format two, format three, format four, and format five.
Only one embodiment is given here, and the user can set the format of different coding levels according to the requirement; any of formats one to five may be selected, and these encoding formats do not have to be used simultaneously.
As shown in fig. 1, each primitive includes position information of a single primitive in a single picture when stored, and the storage content in each format is as follows:
the storage content represented by the first format comprises the following sequentially recorded contents: primitive index, format one number, and color of pixel position arrangement; the original storage format of the primitive to be coded is format one;
the storage content represented by the second format comprises the following sequentially recorded contents: the method comprises the steps of primitive indexing, format two numbers, non-K color numbers, colors recorded in sequence and position numbers corresponding to the colors;
the storage content represented by the third format comprises the following sequentially recorded contents: primitive index, format three number, non-K color number, and each color, the number of positions where the corresponding color appears and each position recorded in sequence;
the storage content represented by the format four comprises the following sequentially recorded contents: primitive index, format four number, color total number, and variable length coding of difference value of each color, first position of corresponding color, subsequent position value and previous position value recorded in sequence, ending symbol; the variable length coding refers to that codes with different lengths are selected based on the occurrence frequency of the difference value during coding, the occurrence frequency is high, and the coding length is short;
the storage content represented by the fifth format comprises the following sequentially recorded contents: primitive index, format five number, number of colors contained in color group, and color sequence in each color group; the number of colors in the specific implementation can be set to 2, 4, 8 or 16, and the setting is carried out according to the picture characteristics.
The colors in a single color group are determined as follows: determining from most to least according to the number of colors contained in the color group and the occurrence frequency of each pixel in the primitive to be coded;
the color sequence comprises colors in the color group, the total number of positions corresponding to all the colors, a color index array for recording the appearance sequence of the colors in the color group and a bitmap for recording the positions of the residual uncoded colors;
when the format with the minimum storage length of each format in the same coding level is obtained, the storage lengths of the formats I to IV are calculated and obtained according to the following method, and the storage length of the format V is obtained based on the coding result:
the length of the storage in format one is x y;
the total number of positions with length of 2 times of non-K colors is stored in format two;
the length of the storage in format three is 2 times of the total number of non-K colors and the total number of positions of the non-K colors;
the length stored in the format four is 2 times of the sum of the total number of the non-K colors and the variable length coding length of the position interval of each non-K color; the length of the position-distance variable-length code is 1+ variable-length code corresponding to the distance between the other positions except the first position and the previous position.
In order to reduce the storage length of the compressed picture as much as possible, when the fifth format is used for storage, the method also comprises the step of storing the residual uncoded colors and the corresponding positions thereof according to the second format or the first format;
wherein the remaining uncoded colors are determined as follows:
after the color sequence of each color group is determined, if the storage length is greater than or equal to the length of the pixel corresponding to the color in the color group stored according to the format one, the current color group and the color not yet coded are recorded as the residual uncoded color.
In order to reduce the storage length of the compressed picture as much as possible, when the fourth format is used for storage, the storage sequences of different colors are sorted from most to least according to the occurrence times of the colors in the graphic element to be coded. Furthermore, when the format four is used for storage, the difference value of the first position value and the subsequent position value of a single color compared with the previous position value is recorded, the length of format storage of the ending symbol is Z, and if Z is larger than or equal to the total length of the storage of the current color related pixel according to the format one, the current color and other uncoded color related pixels are stored according to the format one.
The compression effect of the picture compression method provided by the invention is shown in figure 3, wherein BMP, LZ4, ZLIB and PNG in the figure are the existing compression coding method; the second, fourth and fifth formats represent the image compression method of the present invention, and we further explain the effect of the present invention with reference to fig. 3:
firstly, a second format method is adopted for compression, the compression ratio, the speed and the encoding rate are similar to BMP, the compression ratio is low, but the speed is extremely high, and the encoding rate is approximately 2-5 clocks/byte.
The compression rate of the format four and the compression rate of the format five are intermediate, the compression rate is similar to that of the LZ4 and the ZLIB, and compared with the LZ4 and the ZLIB, the compression rate and the coding rate of the format four and the compression rate of the format five are higher, wherein the compression rate is improved by about 40-100%. The same picture is compressed, the load of the four and five pairs of formats can be reduced by 30-50%, and the coding load of a CPU can be obviously reduced under the scenes of high-speed high-definition picture acquisition and the like.
And thirdly, although the PNG has the highest compression rate, the PNG has a lower compression speed, and the encoding rate is approximately 100-150 clocks/byte. The requirement of production rhythm during field detection can not be met.
In addition, when the whole picture is compressed, the LZ4, ZLIB and PNG are adopted, so that the method is only suitable for single-thread coding because the repetition and redundancy among different parts need to be analyzed. The method provided by the invention does not have mutual dependence when different primitives adopt which format to encode, and can utilize multi-thread parallel encoding and decoding. Ideally, if 2-thread parallel is adopted, compared with LZ4 and ZLIB, the compression speed of format four and five can be further improved to 200% -300%. And as the number of threads increases, the encoding speed can be further increased.
The foregoing descriptions of specific exemplary embodiments of the present invention have been presented for purposes of illustration and description. The foregoing description is not intended to be exhaustive or to limit the invention to the precise form disclosed, and obviously many modifications and variations are possible in light of the above teaching. The exemplary embodiments were chosen and described in order to explain certain principles of the invention and its practical application to enable others skilled in the art to make and use various exemplary embodiments of the invention and various alternatives and modifications thereof. It is intended that the scope of the invention be defined by the following claims and their equivalents.

Claims (8)

1. A picture compression method is characterized by comprising the following steps:
1) determining the background color of a single picture, and dividing the picture elements according to the width x and the height y;
2) screening the primitives of which the internal pixels are all background colors, filtering, and recording the remaining primitives as the primitives to be coded;
3) taking the background color of a single picture, the background color of a primitive to be coded or the background color of a determined primitive to be coded in a specific area as a basic color; replacing all basic colors in the graphic elements with K, wherein K represents a color value with the lowest brightness;
determining encoding format types of all non-K pixels in the primitive to be encoded according to the encoding level selected by a user, acquiring a format with the minimum storage length in each format in the same encoding level, and compressing and storing the primitive;
the storage content represented by the first format comprises the following sequentially recorded contents: primitive index, format one number, and color of pixel position arrangement; the original storage format of the primitive to be coded is format one;
the storage content represented by the second format comprises the following sequentially recorded contents: the method comprises the steps of primitive indexing, format two numbers, non-K color numbers, colors recorded in sequence and position numbers corresponding to the colors;
the storage content represented by the third format comprises the following sequentially recorded contents: primitive index, format three number, non-K color number, and each color, the number of positions where the corresponding color appears and each position recorded in sequence;
the storage content represented by the format four comprises the following sequentially recorded contents: primitive index, format four number, color total number, and variable length coding of difference value of each color, first position of corresponding color, subsequent position value and previous position value recorded in sequence, ending symbol; the variable length coding refers to that codes with different lengths are selected based on the occurrence frequency of the difference value during coding, the occurrence frequency is high, and the coding length is short;
the storage content represented by the fifth format comprises the following sequentially recorded contents: primitive index, format five number, number of colors contained in color group, and color sequence in each color group;
the colors in a single color group are determined as follows: determining from most to least according to the number of colors contained in the color group and the occurrence frequency of each pixel in the primitive to be coded;
the color sequence comprises colors in a color group, the total number of positions corresponding to all the colors, a color index array for recording the appearance sequence of the colors in the color group and a bitmap for recording the positions of the residual uncoded colors;
when the format with the minimum storage length in each format in the same coding level is obtained, the storage lengths of the formats I to IV are calculated and obtained according to the following method, and the storage length of the format V is obtained based on the coding result:
the length of the storage in format one is x y;
the total number of positions with length of 2 times of non-K colors is stored in format two;
the length of the storage in format three is 2 times of the total number of non-K colors and the total number of positions of the non-K colors;
the length stored in the format four is 2 times of the sum of the total number of the non-K colors and the variable length coding length of the position interval of each non-K color; the length of the position-distance variable-length codes is 1+ and the positions except the head position correspond to the distance of the previous position.
2. A method for compressing a picture as claimed in claim 1, characterized by:
when the format five is used for storing, the method also comprises the step of storing the residual uncoded colors and the corresponding positions thereof according to the format two or the format one;
wherein the remaining unencoded colors are determined as follows:
after the color sequence of each color group is determined, if the storage length is greater than or equal to the length of the pixel corresponding to the color in the color group stored according to the format one, the current color group and the color not yet coded are recorded as the residual uncoded color.
3. A method for compressing a picture as claimed in claim 1, characterized by: and when the format four is used for storage, the storage sequences of different colors are sorted from most to least according to the occurrence times of the colors in the graphic element to be coded.
4. A method for compressing a picture as claimed in claim 3, characterized by: when the format four is used for storage, the difference value of the initial position and the subsequent position value of a single color compared with the previous position value is recorded, the length of format storage of the ending symbol is Z, and if Z is larger than or equal to the total length of the storage of the current color related pixel according to the format one, the current color and other uncoded color related pixels are stored according to the format one.
5. A method for compressing a picture as claimed in claim 1, characterized by: the encoding format type determined by the encoding level is as follows:
coding level one: a first format;
coding level two: format one, format two;
coding level three: format one, format two and format three;
coding level four: format one, format two, format three and format four;
coding level five: format one, format two, format three, format four, and format five.
6. A method for compressing a picture as claimed in claim 1, characterized by: when the pixels are divided, firstly, the single picture is expanded by using the background color, so that the width and the height of the single picture are respectively the minimum integral multiple of x and y, and then the pixels are divided.
7. A method for compressing a picture as claimed in claim 1, characterized by: the number of colors included in a color group is 2, 4, 8 or 16.
8. A method for compressing a picture as claimed in claim 1, characterized by: the storage of the graphic elements comprises the position information of the single graphic element in a single picture.
CN202111657376.6A 2021-12-31 2021-12-31 Picture compression method Active CN114332261B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111657376.6A CN114332261B (en) 2021-12-31 2021-12-31 Picture compression method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111657376.6A CN114332261B (en) 2021-12-31 2021-12-31 Picture compression method

Publications (2)

Publication Number Publication Date
CN114332261A true CN114332261A (en) 2022-04-12
CN114332261B CN114332261B (en) 2024-05-31

Family

ID=81019723

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111657376.6A Active CN114332261B (en) 2021-12-31 2021-12-31 Picture compression method

Country Status (1)

Country Link
CN (1) CN114332261B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119342224A (en) * 2024-10-24 2025-01-21 易思维(杭州)科技股份有限公司 A method for lossless compression and decompression of images

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH1188700A (en) * 1997-09-04 1999-03-30 Hitachi Ltd Color image signal encoding method, decoding method, and color image processing apparatus
CA2363273A1 (en) * 1999-02-15 2000-08-24 Digital Accelerator Corporation Method and system of region-based image coding with dynamic streaming of code blocks
WO2000049571A2 (en) * 1999-02-15 2000-08-24 Digital Accelerator Corporation Method and system of region-based image coding with dynamic streaming of code blocks
US20070146380A1 (en) * 2003-08-21 2007-06-28 Jorn Nystad Differential encoding using a 3d graphics processor
US20180232849A1 (en) * 2017-02-10 2018-08-16 Microsoft Technology Licensing, Llc Buffer index format and compression

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH1188700A (en) * 1997-09-04 1999-03-30 Hitachi Ltd Color image signal encoding method, decoding method, and color image processing apparatus
CA2363273A1 (en) * 1999-02-15 2000-08-24 Digital Accelerator Corporation Method and system of region-based image coding with dynamic streaming of code blocks
WO2000049571A2 (en) * 1999-02-15 2000-08-24 Digital Accelerator Corporation Method and system of region-based image coding with dynamic streaming of code blocks
US20070146380A1 (en) * 2003-08-21 2007-06-28 Jorn Nystad Differential encoding using a 3d graphics processor
US20180232849A1 (en) * 2017-02-10 2018-08-16 Microsoft Technology Licensing, Llc Buffer index format and compression

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119342224A (en) * 2024-10-24 2025-01-21 易思维(杭州)科技股份有限公司 A method for lossless compression and decompression of images
CN119342224B (en) * 2024-10-24 2025-10-10 易思维(杭州)科技股份有限公司 A method for lossless compression and decompression of images

Also Published As

Publication number Publication date
CN114332261B (en) 2024-05-31

Similar Documents

Publication Publication Date Title
US12407844B2 (en) Methods and apparatuses for encoding and decoding a bytestream
US7373005B2 (en) Compression system for integrated sensor devices
US6243416B1 (en) Image coding and decoding methods, image coder, and image decoder
KR100554805B1 (en) Image Compression System and Methods
JPH06231234A (en) Compression method of image frame and data processing system
Hu et al. A new lossless compression scheme based on Huffman coding scheme for image compression
CN112637600A (en) Method and apparatus for encoding and decoding data with lossy or lossless compression
CN114332261A (en) Picture compression method
Hu et al. Improved vector quantization scheme for grayscale image compression
JP2011234363A (en) Image processing system and method
US6577766B1 (en) Method and apparatus for motion detection in the discrete cosine transform domain
WO2023047119A1 (en) Point cloud data frames compression
CN107801031A (en) A kind of lossless compression-encoding method to pure three primary colors image data
US7286264B2 (en) None-of-the-above digital halftone compression and decompression
GB2366472A (en) Improvements relating to representations of compressed video
CN118018877A (en) An efficient data stream processing method for pulse cameras
CN113518222B (en) Encoding and decoding method and device for different types of strings using different length binarization schemes
Bist et al. Improved image compression using lossless Huffman encoding (I2COM)
CN120726146B (en) Remote acquisition method and system for inkjet printing image data
US20050018910A1 (en) Method and apparatus for reducing the bandwidth required to transmit image data
US6219445B1 (en) Multi-color image encoding and/or decoding apparatus containing color order table and the method thereof
JPH0496575A (en) Image encoding method
Chen et al. Nearly lossless HDR images compression by background image segmentation
JPH0311883A (en) Decoding system for variable length code, and facsimile equipment and still picture transmission system
JP2708252B2 (en) Image data compression method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Country or region after: China

Address after: Room 495, building 3, 1197 Bin'an Road, Binjiang District, Hangzhou City, Zhejiang Province 310051

Applicant after: Yi Si Si (Hangzhou) Technology Co.,Ltd.

Address before: Room 495, building 3, 1197 Bin'an Road, Binjiang District, Hangzhou City, Zhejiang Province 310051

Applicant before: ISVISION (HANGZHOU) TECHNOLOGY Co.,Ltd.

Country or region before: China

GR01 Patent grant
GR01 Patent grant