CN109308724A - A kind of method for compressing image and device - Google Patents

A kind of method for compressing image and device Download PDF

Info

Publication number
CN109308724A
CN109308724A CN201710615308.0A CN201710615308A CN109308724A CN 109308724 A CN109308724 A CN 109308724A CN 201710615308 A CN201710615308 A CN 201710615308A CN 109308724 A CN109308724 A CN 109308724A
Authority
CN
China
Prior art keywords
image
fragment
result
pixel
mask matrix
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.)
Pending
Application number
CN201710615308.0A
Other languages
Chinese (zh)
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.)
Hefei Map Duck Mdt Infotech Ltd
Original Assignee
Hefei Map Duck Mdt Infotech 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 Hefei Map Duck Mdt Infotech Ltd filed Critical Hefei Map Duck Mdt Infotech Ltd
Priority to CN201710615308.0A priority Critical patent/CN109308724A/en
Publication of CN109308724A publication Critical patent/CN109308724A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T9/00Image coding

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

The embodiment of the invention provides a kind of method for compressing image and devices, which comprises carries out fragment to image;To each fragment, the discrete cosine transform with coefficient is made to every a line of the fragment, each column respectively, obtains transformation results;Obtain the corresponding mask matrix of the fragment;Discrete cosine transform with coefficient is made to every a line of the mask matrix, each column respectively, obtains the transformation results of the mask matrix;The final transformation results of the fragment are obtained divided by the transformation results of the mask matrix with the transformation results of the fragment;The final transformation results are quantified, are encoded, obtain compressed as a result, it is possible to effectively promote the compression ratio of image.

Description

A kind of method for compressing image and device
Technical field
The present invention relates to compression of images field, in particular to a kind of method for compressing image.
Background technique
Inefficient when being predicted at present using image pyramid, compression speed is slower.
Summary of the invention
To solve the above-mentioned problems, the embodiment of the invention provides a kind of method for compressing image.
According to the first aspect of the invention, a kind of method for compressing image is provided, which comprises
Fragment is carried out to image;
To each fragment, its least surrounding boxes is calculated;
To each fragment, corresponding mask matrix is calculated according to the least surrounding boxes;
To each fragment, sample code is carried out to the mask matrix, obtains corresponding image pyramid;
To each fragment, since the pyramidal top of described image, by this layer under image pyramid One layer is predicted, prediction result is obtained;
The pyramidal boundary of the tomographic image is calculated, pixel corresponding with the boundary in the prediction result is obtained, by institute It states and the corresponding pixel in boundary is compared with the value of corresponding location of pixels in the mask matrix, obtain comparing knot accordingly Fruit, for being in the pixel of non-boundary, it is true that its comparison result, which is directly arranged,;
The prediction result is modified according to the mask matrix, obtains revised prediction result;
The pyramidal each layer of iterative processing described image, until the bottom;
It is corresponding that with other each layer comparison results described image pyramid is obtained according to the pyramidal top layer of described image Channel binary coding string;
The binary coding string is compressed, intermediate compression result is obtained;
The first compression result of described image is obtained according to the intermediate compression result of all fragments.
According to the second aspect of the invention, a kind of image compressing device is provided, comprising:
Sharding unit, for carrying out fragment to image;
The least surrounding boxes computing unit, for calculating its least surrounding boxes to each fragment;
Mask matrix calculation unit, for being calculated according to the least surrounding boxes corresponding to each fragment Mask matrix;
Sampling unit, for carrying out sample code to the mask matrix, obtaining corresponding image to each fragment Pyramid;
Predicting unit is used for each fragment, since the pyramidal top of described image, by the layer to figure As pyramidal next layer is predicted, prediction result is obtained;
Computing unit, for calculating the pyramidal boundary of the tomographic image, obtain in the prediction result with the boundary pair The corresponding pixel in described and boundary is compared with the value of corresponding location of pixels in the mask matrix, obtains by the pixel answered To corresponding comparing result, for being in the pixel of non-boundary, it is true that its comparison result, which is directly arranged,;
Amending unit is modified the prediction result according to the mask matrix, obtains revised prediction result;
Iteration unit is used for the pyramidal each layer of iterative processing described image, until the bottom;
Coding unit, for obtaining the figure according to the pyramidal top layer of described image and other each layer comparison results As the binary coding string in the corresponding channel of pyramid;
First compression unit obtains intermediate compression result for compressing to the binary coding string;
Second combining unit obtains the first compression knot of described image for the intermediate compression result according to all fragments Fruit.
The embodiment of the present invention provides the method that a kind of pair of image is compressed, and accelerates image pyramid by edge detection It predicts versus speed, the speed of compression of images can be effectively improved.
Detailed description of the invention
To describe the technical solutions in the embodiments of the present invention more clearly, make required in being described below to embodiment Attached drawing is briefly described, it should be apparent that, drawings in the following description are only some embodiments of the invention, for For those of ordinary skill in the art, without creative efforts, it can also be obtained according to these attached drawings other Attached drawing.
Fig. 1 is method flow diagram provided in an embodiment of the present invention;
Fig. 2 is method flow diagram provided in an embodiment of the present invention;
Fig. 3 is method flow diagram provided in an embodiment of the present invention;
Fig. 4 is schematic device provided in an embodiment of the present invention.
Specific embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with attached in the embodiment of the present invention Figure, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is only this Invention a part of the embodiment, instead of all the embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art exist Every other embodiment obtained under the premise of creative work is not made, shall fall within the protection scope of the present invention.
Embodiment one
The embodiment of the invention provides a kind of method for compressing image, as shown in Figure 1, which comprises
Step 102, fragment is carried out to image.
Fragment can be carried out to image using any way, such as fragment be carried out by deep learning method, or pass through SLIC algorithm carry out fragment, the embodiment of the present invention to specific sharding method without limitation.
Step 104, to each fragment, its least surrounding boxes is calculated.
Specifically, including:
Obtain the coordinate value (x, y) of each pixel in the fragment;
Obtain the maximum value x in all abscissasmaxWith minimum value xmin
Obtain the maximum value y in all ordinatesmaxWith minimum value ymin
By (xmax, ymax)、(xmax, ymin)、(xmin, ymax)、(xmin, ymin) rectangle composed by 4 points is exactly the fragment The least surrounding boxes.
Step 106, to each fragment, corresponding mask matrix is calculated according to the least surrounding boxes.
Specifically, for each pixel in the least surrounding boxes, it is described if the value of the pixel is not sky Value corresponding with the pixel is 1 in mask matrix, and otherwise, value corresponding with the pixel is 0 in the mask matrix.
Step 108, to each fragment, sample code is carried out to the mask matrix, obtains corresponding image gold word Tower.
Specifically, the image pyramid of the mask matrix is established by sampling, until the pyramidal top layer of described image Until only 1 pixel.Image pyramid is one kind of Image Multiscale expression, is a kind of to carry out interpretation of images with multiresolution Resulting structure.The pyramid of piece image is that a series of resolution ratio with Pyramid arrangement gradually reduce, and derive from same The image collection of one original graph.It is obtained by echelon to down-sampling, just stops sampling until reaching some termination condition.It will Image in layer is likened into pyramid, and level is higher, then image is smaller, and resolution ratio is lower.Pyramidal bottom is wait locate The high-resolution for managing image indicates, and top is the approximation of low resolution.
It uses in the embodiment of the present invention and samples step by step, until the pyramidal top layer of described image only has 1 pixel.Show Example property, it is assumed that the resolution ratio of original image is 512 × 512, it is carried out obtain after first time sampling resolution ratio be 256 × 256 image obtains the image that resolution ratio is 128 × 128 after sampling again, it is 64 × 64 that resolution ratio is obtained after sampling again Image obtains the image that resolution ratio is 32 × 32 after sampling again, the image that resolution ratio is 16 × 16 is obtained after sampling again, then The image that resolution ratio is 8 × 8 is obtained after secondary sampling, and the image that resolution ratio is 4 × 4 is obtained after sampling again, after sampling again The image for being 2 × 2 to resolution ratio finally obtains the image that resolution ratio is 1 × 1, i.e. image pyramid top layer after sampling again The image of only 1 pixel.
Step 110, to each fragment, since the pyramidal top of described image, by the layer to image gold Next layer of word tower is predicted, prediction result is obtained.
Specifically, the pixel value using this layer is filled next layer of pixel of image pyramid, obtain described pre- Survey result.
Step 112, the pyramidal boundary of the tomographic image is calculated, picture corresponding with the boundary in the prediction result is obtained The corresponding pixel in described and boundary is compared with the value of corresponding location of pixels in the mask matrix, obtains corresponding by element Comparing result, for be in non-boundary pixel, it is true that its comparison result, which is directly arranged,.
Usually, in the prediction result obtained by above-mentioned fill method most pixel be all in mask matrix Corresponding pixel is consistent, it is possible to the image side in the most filled layer appeared in for filling in inconsistent place occurs At boundary because these boundary pixels value it is possible that mutation.Using this characteristic, the speed of comparison can be accelerated Degree.
Specifically, calculating the pyramidal boundary of the tomographic image, picture corresponding with the boundary in the prediction result is obtained These (this) pixels are compared with the value of corresponding location of pixels in the mask matrix, are compared accordingly by element As a result, it is true that its comparison result, which is directly arranged, for the pixel for being in non-boundary.
Step 114, the prediction result is modified according to the mask matrix, obtains revised prediction result.
Step 116, the pyramidal each layer of iterative processing described image, until the bottom.
Specifically, the next layer of progress according to the revised prediction result, using the above method to image pyramid It predicts and compares, obtain comparing result and revised prediction result, so recycle, until the pyramidal most bottom of described image Layer.
Step 118, described image gold is obtained according to the pyramidal top layer of described image and other each layer comparison results The binary coding string in the corresponding channel of word tower.
Step 120, the binary coding string is compressed, obtains intermediate compression result.
Specifically, can be compressed by the way of arithmetic coding to the binary coding string, the embodiment of the present invention Without limitation to specific compression method.
Step 122, the first compression result of described image is obtained according to the intermediate compression result of all fragments.
Specifically, merging the compression result of all fragments, the first compression result of described image is obtained.The embodiment of the present invention It is without restriction to specific merging method.
The embodiment of the present invention provides the method that a kind of pair of image is compressed, and accelerates image pyramid by edge detection It predicts versus speed, the speed of compression of images can be effectively improved.
Embodiment two
The embodiment of the invention provides a kind of method for compressing image, as shown in Figure 2, which comprises
Step 202, fragment is carried out to image.
Fragment can be carried out to image using any way, such as fragment be carried out by deep learning method, or pass through SLIC algorithm carry out fragment, the embodiment of the present invention to specific sharding method without limitation.
Step 204, to each fragment, its least surrounding boxes is calculated.
Specifically, including:
Obtain the coordinate value (x, y) of each pixel in the fragment;
Obtain the maximum value x in all abscissasmaxWith minimum value xmin
Obtain the maximum value y in all ordinatesmaxWith minimum value ymin
By (xmax, ymax)、(xmax, ymin)、(xmin, ymax)、(xmin, ymin) rectangle composed by 4 points is exactly the fragment The least surrounding boxes.
Step 206, to each fragment, corresponding mask matrix is calculated according to the least surrounding boxes.
Specifically, for each pixel in the least surrounding boxes, it is described if the value of the pixel is not sky Value corresponding with the pixel is 1 in mask matrix, and otherwise, value corresponding with the pixel is 0 in the mask matrix.
Step 208, to each fragment, sample code is carried out to the mask matrix.
Specifically, the image pyramid of the mask matrix is established by sampling, until the pyramidal top layer of described image Until only 1 pixel.Image pyramid is one kind of Image Multiscale expression, is a kind of to carry out interpretation of images with multiresolution Resulting structure.The pyramid of piece image is that a series of resolution ratio with Pyramid arrangement gradually reduce, and derive from same The image collection of one original graph.It is obtained by echelon to down-sampling, just stops sampling until reaching some termination condition.It will Image in layer is likened into pyramid, and level is higher, then image is smaller, and resolution ratio is lower.Pyramidal bottom is wait locate The high-resolution for managing image indicates, and top is the approximation of low resolution.
It uses in the embodiment of the present invention and samples step by step, until the pyramidal top layer of described image only has 1 pixel.Show Example property, it is assumed that the resolution ratio of original image is 512 × 512, it is carried out obtain after first time sampling resolution ratio be 256 × 256 image obtains the image that resolution ratio is 128 × 128 after sampling again, it is 64 × 64 that resolution ratio is obtained after sampling again Image obtains the image that resolution ratio is 32 × 32 after sampling again, the image that resolution ratio is 16 × 16 is obtained after sampling again, then The image that resolution ratio is 8 × 8 is obtained after secondary sampling, and the image that resolution ratio is 4 × 4 is obtained after sampling again, after sampling again The image for being 2 × 2 to resolution ratio finally obtains the image that resolution ratio is 1 × 1, i.e. image pyramid top layer after sampling again The image of only 1 pixel.
Step 210, it to each fragment, is compressed according to the mask matrix and the sample code.
Specifically, processing method is as follows for each image pyramid:
Firstly, being carried out by this layer to next layer of image pyramid pre- since the pyramidal top of described image It surveys, obtains prediction result.
Specifically, the pixel value using this layer is filled next layer of pixel of image pyramid, obtain described pre- Survey result.Illustratively, it is assumed that the pixel value of the 1 × 1 of top is 1, then 2 × 2 pixel of next layer obtained by filling The prediction result of image are as follows:
Secondly, comparing according to the prediction result and the mask matrix, comparison result is obtained.
Specifically, the prediction result is compared with the value of corresponding location of pixels in the mask matrix, example The corresponding mask matrix value of above-mentioned 2 × 2 pixel image of hypothesis of property are as follows:
Then (1) is compared with (2), obtained comparing result is 1110 (it is true that this sentences 1 representative, represents vacation with 0).
Again, the prediction result is modified according to the mask matrix, obtains revised prediction result:
Finally, the next layer of progress according to the revised prediction result (3), using the above method to image pyramid It predicts and compares, obtain comparing result and revised prediction result, so recycle, until the pyramidal most bottom of described image Layer.
Finally, described image pyramid is obtained according to the pyramidal top layer of described image and other each layer comparison results The binary coding string in corresponding channel.
The binary coding string is compressed.
Illustratively, the binary coding string can be compressed by the way of arithmetic coding, the present invention is implemented Example to specific compression method without limitation.
Step 212, the first compression result of described image is obtained according to the compression result of all fragments.
Specifically, merging the compression result of all fragments, the first compression result of described image is obtained.The embodiment of the present invention It is without restriction to specific merging method.
Further, after step 202, further includes:
Each Color Channel of each fragment is compressed.
Specifically, the Color Channel includes: RGB channel or the channel YUV, if the color space of the image is RGB Color space, then the three of the image channel is respectively R, G, channel B, if the color space of the image is YUV color space, Then three channels of the image are respectively the channel Y, U, V.
The compression result for merging all colours channel of all fragments obtains the second compression result of described image.
First compression result and second compression result are merged into the compression result of described image.
The embodiment of the present invention provides the method that a kind of pair of image carries out fragment and compressed to every shape, Neng Gouyou Effect ground characterization nonlinear characteristic, and promote the compression ratio of image.
Embodiment three
The embodiment of the invention provides a kind of method for compressing image, as shown in Figure 2, which comprises
Step 202, fragment is carried out to image.
Fragment can be carried out to image using any way, such as fragment be carried out by deep learning method, or pass through SLIC algorithm carry out fragment, the embodiment of the present invention to specific sharding method without limitation.
Step 204, to each fragment, its least surrounding boxes is calculated.
Specifically, including:
Obtain the coordinate value (x, y) of each pixel in the fragment;
Obtain the maximum value x in all abscissasmaxWith minimum value xmin
Obtain the maximum value y in all ordinatesmaxWith minimum value ymin
By (xmax, ymax)、(xmax, ymin)、(xmin, ymax)、(xmin, ymin) rectangle composed by 4 points is exactly the fragment The least surrounding boxes.
Step 206, to each fragment, corresponding mask matrix is calculated according to the least surrounding boxes.
Specifically, for each pixel in the least surrounding boxes, it is described if the value of the pixel is not sky Value corresponding with the pixel is 1 in mask matrix, and otherwise, value corresponding with the pixel is 0 in the mask matrix.
Step 208, to each fragment, sample code is carried out to the mask matrix.
Specifically, the image pyramid of the mask matrix is established by sampling, until the pyramidal top layer of described image Until only 1 pixel.Image pyramid is one kind of Image Multiscale expression, is a kind of to carry out interpretation of images with multiresolution Resulting structure.The pyramid of piece image is that a series of resolution ratio with Pyramid arrangement gradually reduce, and derive from same The image collection of one original graph.It is obtained by echelon to down-sampling, just stops sampling until reaching some termination condition.It will Image in layer is likened into pyramid, and level is higher, then image is smaller, and resolution ratio is lower.Pyramidal bottom is wait locate The high-resolution for managing image indicates, and top is the approximation of low resolution.
It uses in the embodiment of the present invention and samples step by step, until the pyramidal top layer of described image only has 1 pixel.Show Example property, it is assumed that the resolution ratio of original image is 512 × 512, it is carried out obtain after first time sampling resolution ratio be 256 × 256 image obtains the image that resolution ratio is 128 × 128 after sampling again, it is 64 × 64 that resolution ratio is obtained after sampling again Image obtains the image that resolution ratio is 32 × 32 after sampling again, the image that resolution ratio is 16 × 16 is obtained after sampling again, then The image that resolution ratio is 8 × 8 is obtained after secondary sampling, and the image that resolution ratio is 4 × 4 is obtained after sampling again, after sampling again The image for being 2 × 2 to resolution ratio finally obtains the image that resolution ratio is 1 × 1, i.e. image pyramid top layer after sampling again The image of only 1 pixel.
Step 210, it to each fragment, is compressed according to the mask matrix and the sample code.
Specifically, processing method is as follows for each image pyramid:
Firstly, being carried out by this layer to next layer of image pyramid pre- since the pyramidal top of described image It surveys, obtains prediction result.
Specifically, the pixel value using this layer is filled next layer of pixel of image pyramid, obtain described pre- Survey result.Illustratively, it is assumed that the pixel value of the 1 × 1 of top is 1, then 2 × 2 pixel of next layer obtained by filling The prediction result of image are as follows:
Secondly, comparing according to the prediction result and the mask matrix, comparison result is obtained.
Specifically, the prediction result is compared with the value of corresponding location of pixels in the mask matrix, example The corresponding mask matrix value of above-mentioned 2 × 2 pixel image of hypothesis of property are as follows:
Then (1) is compared with (2), obtained comparing result is 1110 (it is true that this sentences 1 representative, represents vacation with 0).
Again, the prediction result is modified according to the mask matrix, obtains revised prediction result:
Finally, the next layer of progress according to the revised prediction result (3), using the above method to image pyramid It predicts and compares, obtain comparing result and revised prediction result, so recycle, until the pyramidal most bottom of described image Layer.
Finally, described image pyramid is obtained according to the pyramidal top layer of described image and other each layer comparison results The binary coding string in corresponding channel.
The binary coding string is compressed.Illustratively, can by the way of arithmetic coding to described two into Coded strings processed are compressed, the embodiment of the present invention to specific compression method without limitation.
Step 212, the first compression result of described image is obtained according to the compression result of all fragments.
Specifically, merging the compression result of all fragments, the first compression result of described image is obtained.The embodiment of the present invention It is without restriction to specific merging method.
Further, after step 202, further includes:
Each Color Channel of each fragment is compressed.
Specifically, the Color Channel includes: RGB channel or the channel YUV, if the color space of the image is RGB Color space, then the three of the image channel is respectively R, G, channel B, if the color space of the image is YUV color space, Then three channels of the image are respectively the channel Y, U, V.
Each Color Channel to each fragment carries out compression
DCT (Discrete Cosine Transform, discrete cosine transform) is to every a line of the Color Channel to become It changes, obtains transformed result.
Specifically, described every a line to the Color Channel does dct transform, obtaining transformed result includes:
Obtain the number of pixels of every row in the fragment.
Illustratively, it is assumed that the fragment shares i row, then the number of pixels of every row is denoted as ni
Dct transform is done for every row pixel, obtains intermediate conversion result.
Illustratively, calculation formula is as follows:
To the intermediate conversion result multiplied byObtain transformation results.
90 ° of transposition are carried out to the fragment.
The number of pixels of every row in the fragment after obtaining transposition.
Illustratively, it is assumed that the fragment shares j row, then the number of pixels of every row is denoted as nj
Dct transform is done for every row pixel, obtains intermediate conversion result.
Illustratively, calculation formula is as follows:
To the intermediate conversion result multiplied byObtain transformation results.
Obtain the corresponding mask matrix of the fragment, i.e., each picture in the least surrounding boxes corresponding for the fragment Element, if the value of the pixel is not sky, value corresponding with the pixel is 1, otherwise, the mask square in the mask matrix Value corresponding with the pixel is 0 in battle array.
To the mask matrix, dct transform is also carried out according to the method described above, obtains corresponding transformation results.
The channel of the fragment is obtained divided by the transformation results of the mask matrix with the transformation results of the fragment Final transformation results.
The final transformation results are quantified, are encoded, compressed result is obtained.
The compression result for merging all colours channel of all fragments obtains the second compression result of described image.
First compression result and second compression result are merged into the compression result of described image.
The embodiment of the present invention provides a kind of method for compressing image, and the shape based on each image slices carries out dct transform Optimization, compared to traditional dct transform compression method, can effectively promote the compression ratio of image.
Example IV
The embodiment of the invention provides a kind of method for compressing image, as shown in Figure 3, which comprises
Step 302, fragment is carried out to image.
Fragment can be carried out to image using any way, such as fragment be carried out by deep learning method, or pass through SLIC algorithm carry out fragment, the embodiment of the present invention to specific sharding method without limitation.
Step 304, to each fragment, its least surrounding boxes is calculated.
Specifically, including:
Obtain the coordinate value (x, y) of each pixel in the fragment;
Obtain the maximum value x in all abscissasmaxWith minimum value xmin
Obtain the maximum value y in all ordinatesmaxWith minimum value ymin
By (xmax, ymax)、(xmax, ymin)、(xmin, ymax)、(xmin, ymin) rectangle composed by 4 points is exactly the fragment The least surrounding boxes.
Step 306, to each fragment, corresponding mask matrix is calculated according to the least surrounding boxes.
Specifically, for each pixel in the least surrounding boxes, it is described if the value of the pixel is not sky Value corresponding with the pixel is 1 in mask matrix, and otherwise, value corresponding with the pixel is 0 in the mask matrix.
Step 308, to each fragment, sample code is carried out to the mask matrix.
Specifically, the image pyramid of the mask matrix is established by sampling, until the pyramidal top layer of described image Until only 1 pixel.Image pyramid is one kind of Image Multiscale expression, is a kind of to carry out interpretation of images with multiresolution Resulting structure.The pyramid of piece image is that a series of resolution ratio with Pyramid arrangement gradually reduce, and derive from same The image collection of one original graph.It is obtained by echelon to down-sampling, just stops sampling until reaching some termination condition.It will Image in layer is likened into pyramid, and level is higher, then image is smaller, and resolution ratio is lower.Pyramidal bottom is wait locate The high-resolution for managing image indicates, and top is the approximation of low resolution.
It uses in the embodiment of the present invention and samples step by step, until the pyramidal top layer of described image only has 1 pixel.Show Example property, it is assumed that the resolution ratio of original image is 512 × 512, it is carried out obtain after first time sampling resolution ratio be 256 × 256 image obtains the image that resolution ratio is 128 × 128 after sampling again, it is 64 × 64 that resolution ratio is obtained after sampling again Image obtains the image that resolution ratio is 32 × 32 after sampling again, the image that resolution ratio is 16 × 16 is obtained after sampling again, then The image that resolution ratio is 8 × 8 is obtained after secondary sampling, and the image that resolution ratio is 4 × 4 is obtained after sampling again, after sampling again The image for being 2 × 2 to resolution ratio finally obtains the image that resolution ratio is 1 × 1, i.e. image pyramid top layer after sampling again The image of only 1 pixel.
Step 310, it to each fragment, is compressed according to the mask matrix and the sample code.
Specifically, processing method is as follows for each image pyramid:
Firstly, being carried out by this layer to next layer of image pyramid pre- since the pyramidal top of described image It surveys, obtains prediction result.
Specifically, the pixel value using this layer is filled next layer of pixel of image pyramid, obtain described pre- Survey result.Illustratively, it is assumed that the pixel value of the 1 × 1 of top is 1, then 2 × 2 pixel of next layer obtained by filling The prediction result of image are as follows:
Secondly, comparing according to the prediction result and the mask matrix, comparison result is obtained.
Specifically, the prediction result is compared with the value of corresponding location of pixels in the mask matrix, example The corresponding mask matrix value of above-mentioned 2 × 2 pixel image of hypothesis of property are as follows:
Then (1) is compared with (2), obtained comparing result is 1110 (it is true that this sentences 1 representative, represents vacation with 0).
Again, the prediction result is modified according to the mask matrix, obtains revised prediction result:
Finally, the next layer of progress according to the revised prediction result (3), using the above method to image pyramid It predicts and compares, obtain comparing result and revised prediction result, so recycle, until the pyramidal most bottom of described image Layer.
Finally, described image pyramid is obtained according to the pyramidal top layer of described image and other each layer comparison results The binary coding string in corresponding channel.
The binary coding string is compressed.Illustratively, can by the way of arithmetic coding to described two into Coded strings processed are compressed, the embodiment of the present invention to specific compression method without limitation.
Step 312, the first compression result of described image is obtained according to the compression result of all fragments.
Specifically, merging the compression result of all fragments, the first compression result of described image is obtained.The embodiment of the present invention It is without restriction to specific merging method.
Step 314, the fragment in step 302 is merged according to preset rules, the new fragment after being merged.
Specifically, can be merged adjacent fragment according to the boundary of each fragment, the present invention merges to specific Method is without restriction.
Step 316, it each new fragment, is handled according to the method for step 304 to step 312, obtains institute State the intermediate compression result of image.
Step 318, the intermediate compression in the first compression result and step 316 in comparison step 312 is as a result, selection is more excellent Result be described image the first new compression result.
Step 320, step 314 is repeated to step 318, until restraining, using the compression result after restraining as described image First compression result.
Further, after step 302, further includes:
Each Color Channel of each fragment is compressed.
Specifically, the Color Channel includes: RGB channel or the channel YUV, if the color space of the image is RGB Color space, then the three of the image channel is respectively R, G, channel B, if the color space of the image is YUV color space, Then three channels of the image are respectively the channel Y, U, V.
Each Color Channel to each fragment carries out compression
DCT (Discrete Cosine Transform, discrete cosine transform) is to every a line of the Color Channel to become It changes, obtains transformed result.
Specifically, described every a line to the Color Channel does dct transform, obtaining transformed result includes:
Obtain the number of pixels of every row in the fragment.
Illustratively, it is assumed that the fragment shares i row, then the number of pixels of every row is denoted as ni
Dct transform is done for every row pixel, obtains intermediate conversion result.
Illustratively, calculation formula is as follows:
To the intermediate conversion result multiplied byObtain transformation results.
90 ° of transposition are carried out to the fragment.
The number of pixels of every row in the fragment after obtaining transposition.
Illustratively, it is assumed that the fragment shares j row, then the number of pixels of every row is denoted as nj
Dct transform is done for every row pixel, obtains intermediate conversion result.
Illustratively, calculation formula is as follows:
To the intermediate conversion result multiplied byObtain transformation results.
Obtain the corresponding mask matrix of the fragment, i.e., each picture in the least surrounding boxes corresponding for the fragment Element, if the value of the pixel is not sky, value corresponding with the pixel is 1, otherwise, the mask square in the mask matrix Value corresponding with the pixel is 0 in battle array.
To the mask matrix, dct transform is also carried out according to the method described above, obtains corresponding transformation results.
The channel of the fragment is obtained divided by the transformation results of the mask matrix with the transformation results of the fragment Final transformation results.
The final transformation results are quantified, are encoded, compressed result is obtained.
The compression result for merging all colours channel of all fragments obtains the second compression result of described image.
First compression result and second compression result are merged into the compression result of described image.
The embodiment of the present invention provides a kind of method for compressing image, by merging to image slices, compare compression result come Optimal sliced fashion is selected, so as to preferably promote the compression ratio of image.
Embodiment five
The embodiment of the invention provides a kind of method for compressing image, as shown in Figure 3, which comprises
Step 302, fragment is carried out to image.
Fragment can be carried out to image using any way, such as fragment be carried out by deep learning method, or pass through SLIC algorithm carry out fragment, the embodiment of the present invention to specific sharding method without limitation.
Step 304, to each fragment, its least surrounding boxes is calculated.
Specifically, including:
Obtain the coordinate value (x, y) of each pixel in the fragment;
Obtain the maximum value x in all abscissasmaxWith minimum value xmin
Obtain the maximum value y in all ordinatesmaxWith minimum value ymin
By (xmax, ymax)、(xmax, ymin)、(xmin, ymax)、(xmin, ymin) rectangle composed by 4 points is exactly the fragment The least surrounding boxes.
Step 306, to each fragment, corresponding mask matrix is calculated according to the least surrounding boxes.
Specifically, for each pixel in the least surrounding boxes, it is described if the value of the pixel is not sky Value corresponding with the pixel is 1 in mask matrix, and otherwise, value corresponding with the pixel is 0 in the mask matrix.
Step 308, to each fragment, sample code is carried out to the mask matrix.
Specifically, the image pyramid of the mask matrix is established by sampling, until the pyramidal top layer of described image Until only 1 pixel.Image pyramid is one kind of Image Multiscale expression, is a kind of to carry out interpretation of images with multiresolution Resulting structure.The pyramid of piece image is that a series of resolution ratio with Pyramid arrangement gradually reduce, and derive from same The image collection of one original graph.It is obtained by echelon to down-sampling, just stops sampling until reaching some termination condition.It will Image in layer is likened into pyramid, and level is higher, then image is smaller, and resolution ratio is lower.Pyramidal bottom is wait locate The high-resolution for managing image indicates, and top is the approximation of low resolution.
It uses in the embodiment of the present invention and samples step by step, until the pyramidal top layer of described image only has 1 pixel.Show Example property, it is assumed that the resolution ratio of original image is 512 × 512, it is carried out obtain after first time sampling resolution ratio be 256 × 256 image obtains the image that resolution ratio is 128 × 128 after sampling again, it is 64 × 64 that resolution ratio is obtained after sampling again Image obtains the image that resolution ratio is 32 × 32 after sampling again, the image that resolution ratio is 16 × 16 is obtained after sampling again, then The image that resolution ratio is 8 × 8 is obtained after secondary sampling, and the image that resolution ratio is 4 × 4 is obtained after sampling again, after sampling again The image for being 2 × 2 to resolution ratio finally obtains the image that resolution ratio is 1 × 1, i.e. image pyramid top layer after sampling again The image of only 1 pixel.
Step 310, it to each fragment, is compressed according to the mask matrix and the sample code.
Specifically, processing method is as follows for each image pyramid:
Firstly, being carried out by this layer to next layer of image pyramid pre- since the pyramidal top of described image It surveys, obtains prediction result.
Specifically, the pixel value using this layer is filled next layer of pixel of image pyramid, obtain described pre- Survey result.
Secondly, comparing according to the prediction result and the mask matrix, comparison result is obtained.
Usually, in the prediction result obtained by above-mentioned fill method most pixel be all in mask matrix Corresponding pixel is consistent, it is possible to the image side in the most filled layer appeared in for filling in inconsistent place occurs At boundary because these boundary pixels value it is possible that mutation.Using this characteristic, the speed of comparison can be accelerated Degree.
Specifically, calculating the pyramidal boundary of the tomographic image, picture corresponding with the boundary in the prediction result is obtained These (this) pixels are compared with the value of corresponding location of pixels in the mask matrix, are compared accordingly by element As a result, it is true that its comparison result, which is directly arranged, for the pixel for being in non-boundary.
Again, the prediction result is modified according to the mask matrix, obtains revised prediction result;
Finally, being carried out using the above method to next layer of image pyramid pre- according to the revised prediction result It surveys and compares, obtain comparing result and revised prediction result, so recycle, until the pyramidal bottom of described image.
Finally, described image pyramid is obtained according to the pyramidal top layer of described image and other each layer comparison results The binary coding string in corresponding channel.
The binary coding string is compressed.Illustratively, can by the way of arithmetic coding to described two into Coded strings processed are compressed, the embodiment of the present invention to specific compression method without limitation.
Step 312, the first compression result of described image is obtained according to the compression result of all fragments.
Specifically, merging the compression result of all fragments, the first compression result of described image is obtained.The embodiment of the present invention It is without restriction to specific merging method.
Step 314, the fragment in step 302 is merged according to preset rules, the new fragment after being merged.
Specifically, can be merged adjacent fragment according to the boundary of each fragment, the present invention merges to specific Method is without restriction.
Step 316, it each new fragment, is handled according to the method for step 304 to step 312, obtains institute State the intermediate compression result of image.
Step 318, the intermediate compression in the first compression result and step 316 in comparison step 312 is as a result, selection is more excellent Result be described image the first new compression result.
Step 320, step 314 is repeated to step 318, until restraining, using the compression result after restraining as described image First compression result.
Further, after step 302, further includes:
Each Color Channel of each fragment is compressed.
Specifically, the Color Channel includes: RGB channel or the channel YUV, if the color space of the image is RGB Color space, then the three of the image channel is respectively R, G, channel B, if the color space of the image is YUV color space, Then three channels of the image are respectively the channel Y, U, V.
Each Color Channel to each fragment carries out compression
DCT (Discrete Cosine Transform, discrete cosine transform) is to every a line of the Color Channel to become It changes, obtains transformed result.
Specifically, described every a line to the Color Channel does dct transform, obtaining transformed result includes:
Obtain the number of pixels of every row in the fragment.
Illustratively, it is assumed that the fragment shares i row, then the number of pixels of every row is denoted as ni
Dct transform is done for every row pixel, obtains intermediate conversion result.
Illustratively, calculation formula is as follows:
To the intermediate conversion result multiplied byObtain transformation results.
90 ° of transposition are carried out to the fragment.
The number of pixels of every row in the fragment after obtaining transposition.
Illustratively, it is assumed that the fragment shares j row, then the number of pixels of every row is denoted as nj
Dct transform is done for every row pixel, obtains intermediate conversion result.
Illustratively, calculation formula is as follows:
To the intermediate conversion result multiplied byObtain transformation results.
Obtain the corresponding mask matrix of the fragment, i.e., each picture in the least surrounding boxes corresponding for the fragment Element, if the value of the pixel is not sky, value corresponding with the pixel is 1, otherwise, the mask square in the mask matrix Value corresponding with the pixel is 0 in battle array.
To the mask matrix, dct transform is also carried out according to the method described above, obtains corresponding transformation results.
The channel of the fragment is obtained divided by the transformation results of the mask matrix with the transformation results of the fragment Final transformation results.
The final transformation results are quantified, are encoded, compressed result is obtained.
The compression result for merging all colours channel of all fragments obtains the second compression result of described image.
First compression result and second compression result are merged into the compression result of described image.
The embodiment of the present invention provides a kind of method for compressing image, is accelerated by way of obtaining edge to described image gold word Predetermined speed that each layer of tower can effectively promote the compression speed of image.
Embodiment six
The embodiment of the invention provides a kind of image compressing devices, as shown in figure 4, described device includes:
Sharding unit 402 carries out fragment to image.
Fragment can be carried out to image using any way, such as fragment be carried out by deep learning method, or pass through SLIC algorithm carry out fragment, the embodiment of the present invention to specific sharding method without limitation.
Converter unit 404, to each fragment, to every a line of the fragment, each column make respectively with coefficient from Cosine transform is dissipated, transformation results are obtained.
Specifically, including:
Obtain the number of pixels of every row in the fragment;
Dct transform is done for every row pixel, obtains the first intermediate conversion result;
To the first intermediate conversion result multiplied by the first transformation coefficient, the first transformation results are obtained;
90 ° of transposition are carried out to the fragment;
The number of pixels of every row in the fragment after obtaining transposition;
Dct transform is done for every row pixel, obtains the second intermediate conversion result;
To the second intermediate conversion result multiplied by the second transformation coefficient, the transformation results of the fragment are obtained.
Mask matrix acquiring unit 406 obtains the corresponding mask matrix of the fragment.
Specifically, including:
Obtain the coordinate value (x, y) of each pixel in the fragment;
Obtain the maximum value x in all abscissasmaxWith minimum value xmin
Obtain the maximum value y in all ordinatesmaxWith minimum value ymin
By (xmax, ymax)、(xmax, ymin)、(xmin, ymax)、(xmin, ymin) rectangle composed by 4 points is exactly the fragment The least surrounding boxes;
For each pixel in the least surrounding boxes, if the value of the pixel is not empty, the mask square Value corresponding with the pixel is 1 in battle array, and otherwise, value corresponding with the pixel is 0 in the mask matrix.
Mask matrixing unit 408 is made every a line of the mask matrix, each column discrete remaining with coefficient respectively String transformation, obtains the transformation results of the mask matrix.
Specifically, including:
Obtain the number of pixels of every row in the mask;
Dct transform is done for every row pixel of the mask matrix, obtains third intermediate conversion result;
To the third intermediate conversion result multiplied by third transformation coefficient, third transformation results are obtained;
90 ° of transposition are carried out to the mask matrix;
The number of pixels of every row in the mask matrix after obtaining transposition;
Dct transform is done for every row pixel, obtains the 4th intermediate conversion result;
To the 4th intermediate conversion result multiplied by the 4th transformation coefficient, the transformation results of the mask matrix are obtained.
Computing unit 410 obtains described point divided by the transformation results of the mask matrix with the transformation results of the fragment The final transformation results of piece.
Compression unit 412 quantifies the final transformation results, is encoded, obtains compressed result.
The embodiment of the present invention provides the dct transform compression set that a kind of pair of image carries out fragment and optimize to every, The compression ratio of image can effectively be promoted.

Claims (7)

1. a kind of method for compressing image, which is characterized in that the described method includes:
Fragment is carried out to image;
To each fragment, its least surrounding boxes is calculated;
To each fragment, corresponding mask matrix is calculated according to the least surrounding boxes;
To each fragment, sample code is carried out to the mask matrix, obtains corresponding image pyramid;
To each fragment, since the pyramidal top of described image, by this layer to next layer of image pyramid It is predicted, obtains prediction result;
Calculate the pyramidal boundary of the tomographic image, obtain pixel corresponding with the boundary in the prediction result, will it is described with The corresponding pixel in boundary is compared with the value of corresponding location of pixels in the mask matrix, obtains corresponding comparing result, For being in the pixel of non-boundary, it is true that its comparison result, which is directly arranged,;
The prediction result is modified according to the mask matrix, obtains revised prediction result;
The pyramidal each layer of iterative processing described image, until the bottom;
It is corresponding logical that described image pyramid is obtained according to the pyramidal top layer of described image and other each layer comparison results The binary coding string in road;
The binary coding string is compressed, intermediate compression result is obtained;
The first compression result of described image is obtained according to the intermediate compression result of all fragments.
2. the method according to claim 1, wherein described corresponding according to the least surrounding boxes calculating Mask matrix includes:
For each pixel in the least surrounding boxes, if the value of the pixel be not it is empty, in the mask matrix Value corresponding with the pixel is 1, and otherwise, value corresponding with the pixel is 0 in the mask matrix.
3. the method according to claim 1, wherein described include: to mask matrix progress sample code
The image pyramid of the mask is established by sampling, is until the pyramidal top layer of described image only has 1 pixel Only.
4. the method according to claim 1, wherein being carried out by this layer to next layer of image pyramid pre- It surveys, obtaining prediction result includes:
Next layer of pixel of image pyramid is filled using the pixel value of this layer, obtains the prediction result.
5. the method according to claim 1, wherein the method also includes:
Each Color Channel of each fragment is compressed;
The compression result for merging all colours channel of all fragments obtains the second compression result of described image;
First compression result and second compression result are merged into the compression result of described image.
6. a kind of image compressing device characterized by comprising
Sharding unit, for carrying out fragment to image;
The least surrounding boxes computing unit, for calculating its least surrounding boxes to each fragment;
Mask matrix calculation unit, for calculating corresponding mask square according to the least surrounding boxes to each fragment Battle array;
Sampling unit, for carrying out sample code to the mask matrix, obtaining corresponding image gold word to each fragment Tower;
Predicting unit is used for each fragment, since the pyramidal top of described image, by the layer to image gold Next layer of word tower is predicted, prediction result is obtained;
Computing unit obtains corresponding with the boundary in the prediction result for calculating the pyramidal boundary of the tomographic image The corresponding pixel in described and boundary is compared with the value of corresponding location of pixels in the mask matrix, obtains phase by pixel The comparing result answered, for being in the pixel of non-boundary, it is true that its comparison result, which is directly arranged,;
Amending unit is modified the prediction result according to the mask matrix, obtains revised prediction result;
Iteration unit is used for the pyramidal each layer of iterative processing described image, until the bottom;
Coding unit, for obtaining described image gold according to the pyramidal top layer of described image and other each layer comparison results The binary coding string in the corresponding channel of word tower;
First compression unit obtains intermediate compression result for compressing to the binary coding string;
Second combining unit obtains the first compression result of described image for the intermediate compression result according to all fragments.
7. device according to claim 6, which is characterized in that described device further include:
Second compression unit is compressed for each Color Channel to each fragment;
Second combining unit, the compression result in all colours channel for merging all fragments, obtains the second of described image Compression result;
Third combining unit, for first compression result and second compression result to be merged into the compression of described image As a result.
CN201710615308.0A 2017-07-26 2017-07-26 A kind of method for compressing image and device Pending CN109308724A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710615308.0A CN109308724A (en) 2017-07-26 2017-07-26 A kind of method for compressing image and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710615308.0A CN109308724A (en) 2017-07-26 2017-07-26 A kind of method for compressing image and device

Publications (1)

Publication Number Publication Date
CN109308724A true CN109308724A (en) 2019-02-05

Family

ID=65201712

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710615308.0A Pending CN109308724A (en) 2017-07-26 2017-07-26 A kind of method for compressing image and device

Country Status (1)

Country Link
CN (1) CN109308724A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030072366A1 (en) * 2001-09-20 2003-04-17 Stmicroelectronics S.R.L. Process and system for the compression of digital video signals, a system and a computer program product therefor
US20040096117A1 (en) * 2000-03-08 2004-05-20 Cockshott William Paul Vector quantization of images
CN103065336A (en) * 2013-01-23 2013-04-24 中国矿业大学(北京) Directional pyramid coding method of image
CN103455624A (en) * 2013-09-16 2013-12-18 湖北文理学院 Implement method of lightweight-class global multi-dimensional remote-sensing image network map service
CN106097251A (en) * 2016-06-22 2016-11-09 深圳信息职业技术学院 Non-homogeneous sparse sampling video super-resolution method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040096117A1 (en) * 2000-03-08 2004-05-20 Cockshott William Paul Vector quantization of images
US20030072366A1 (en) * 2001-09-20 2003-04-17 Stmicroelectronics S.R.L. Process and system for the compression of digital video signals, a system and a computer program product therefor
CN103065336A (en) * 2013-01-23 2013-04-24 中国矿业大学(北京) Directional pyramid coding method of image
CN103455624A (en) * 2013-09-16 2013-12-18 湖北文理学院 Implement method of lightweight-class global multi-dimensional remote-sensing image network map service
CN106097251A (en) * 2016-06-22 2016-11-09 深圳信息职业技术学院 Non-homogeneous sparse sampling video super-resolution method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
TIAN-HU YU; JIANHUA CHEN; S.K. MITRA: "The contrast pyramid based image code", 《PROCEEDINGS OF INTERNATIONAL CONFERENCE ON IMAGE PROCESSING》 *
赵毅力等: "使用游程编码和SIMD指令集的快速图像融合", 《计算机辅助设计与图形学学报》 *

Similar Documents

Publication Publication Date Title
CN110853047B (en) Intelligent image segmentation and classification method, device and computer readable storage medium
CN107122826B (en) Processing method and system and storage medium for convolutional neural networks
CN111868751A (en) Using non-linear functions applied to quantization parameters in a machine learning model for video coding
Hosseini et al. Medical ultrasound image compression using contextual vector quantization
US8478057B1 (en) Image compression and decompression using block prediction
CN110800299B (en) Scan order adaptation for entropy coding blocks of image data
US8356114B2 (en) Region of interest-based image transfer
CN111837140A (en) Video coded field consistent convolution model
WO2023010831A1 (en) Method, system and apparatus for improving image resolution, and storage medium
CN105959686A (en) Video feature extracting method and device as well as video matching method and device
JP2000151418A (en) Method for detecting whether or not image is compressed
US11212527B2 (en) Entropy-inspired directional filtering for image coding
KR20110091849A (en) Reduced dc gain mismatch and dc leakage in overlap transform processing
WO2019192071A1 (en) Method and device for video processing
CN103745443B (en) The method and apparatus for improving picture quality
CN101976340A (en) License plate positioning method based on compressed domain
Zyto et al. Semi-discrete matrix transforms (SDD) for image and video compression
CN117974414A (en) Digital watermark signature verification method, device and equipment based on converged news material
CN104837014B (en) Compress the method and image processing equipment of image
CN109308724A (en) A kind of method for compressing image and device
KR100582595B1 (en) Method for detecting and classifying block edges from dct-compressed images
CN109309835A (en) A kind of method for compressing image and device
CN109308723A (en) A kind of method for compressing image and device
Kim et al. A lossless color image compression method based on a new reversible color transform
Poolakkachalil et al. Comparative analysis of lossless compression techniques in efficient DCT-based image compression system based on Laplacian Transparent Composite Model and An Innovative Lossless Compression Method for Discrete-Color Images

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
AD01 Patent right deemed abandoned
AD01 Patent right deemed abandoned

Effective date of abandoning: 20230714