Background technology
Along with the progress of society and the development of technology, people more and more with image even video etc. more vividly, form substitutes traditional literal and records and transmission of information intuitively, and amount of information is also increasing, because the data volume of image and video itself is very large, brought a lot of inconvenience for storage and transmission, therefore, transmit or store and all need data are effectively compressed.
Image compression is the application of data compression technique on digital picture, thereby its purpose is the redundant information that reduces in the view data stores and the transmission of data with more efficient form, realizes that at network fast transport and in real time processing have great importance for digital image information.
Why view data can be compressed, exactly because exist redundancy in the data.The redundant main manifestations of view data is: the spatial redundancy that the correlation in the image between neighbor causes; The time redundancy that exists correlation to cause between the different frame in the image sequence; The spectral redundancy that the correlation of different color planes or spectral band causes.The purpose of data compression is exactly to reduce the required bit number of expression data by removing these data redundancies.
In the application of image compression, the compression that it would be desirable that image volume is little, quality is high (clear), this need to select different output formats according to the character of different images.The online picture format of commonly using now has JPG, GIF, PNG.
Wherein, JPG is a kind of lossy compression method form, can be with image compression in very little storage area, and repetition or unessential data can be lost in the image, therefore easily cause the damage of view data.Be applicable to the compression storage of color complexity, the large figure of landscape class.
GIF is a kind of nondestructive compression type of the continuous tone based on lzw algorithm.Generally about 50%, it does not belong to any application program to its compression ratio.Present nearly all related software is all supported it, and the public sphere has a large amount of software using the GIF image file.Be applicable to the compression storage of the simple button of color, icon small icon, transparent background.
PNG is the online latest image file format of accepting.PNG can provide the Lossless Compression image file of Length Ratio GIF little 30%.It provides 24 and 48 true color image supports and other many technical supports simultaneously.Be applicable to the compression storage of the gradual change of large tracts of land rule, quartzy style button, transparent, semitransparent background.
Can find out to only have for the image of particular type and select suitable compress mode, just can take full advantage of the characteristics of each compressed format, obtain the compressed file that quality is high, capacity is little.
Existing Image Compression is many from of the compressing file algorithm itself, by modes such as data analysis, packing, clusters view data is compressed, be the Chinese patent application of CN101594537A, CN101563926A such as publication number, the technology of compression and decompression realizes all more complicated, needs larger data to process and supports.
Summary of the invention
In view of the above problems, the purpose of this invention is to provide a kind of Images Classification compression method and system, the classification of the image of compression selects suitable tool of compression to carry out relatively high-quality compression processing as required.
According to an aspect of the present invention, provide a kind of method for compressing image, having comprised:
By being scanned, image obtains described Characteristic of Image value;
Judge the classification of described image according to described Characteristic of Image value;
Classification according to described image is compressed described image.
Wherein, preferred scheme is that described Characteristic of Image value comprises former bitmap-format, unit are number of colours, homochromy regional percentage, picture size and the ratio of described image.
Wherein, preferred scheme is in the process of the classification of judging described image according to described Characteristic of Image value, according to described Characteristic of Image value and default threshold value, image to be divided into lines class image and photo class image.
Wherein, preferred scheme is in the classification according to described image the process that described figure compresses further to be comprised:
If described image is lines class image, then boil down to GIF/PNG form;
If described image is photo class image, then boil down to JPG form.
According to a further aspect in the invention, provide a kind of image compression system, having comprised:
The characteristics of image acquiring unit is used for obtaining the Characteristic of Image value by image is scanned;
The image category judging unit is for the classification of judging described image according to described Characteristic of Image value;
Image compression unit is used for according to the classification of described image described image being compressed.
Utilize above-mentioned according to method for compressing image of the present invention and system, the classification of the image of compression selects suitable tool of compression to carry out relatively high-quality compression processing as required, can obtain with less file volume the more image of high display quality, especially in occasions higher to the image file volume requirement such as large nuber of images storage or slow speed networks, can bring more significantly processing speed and picture quality doulbe-sides' victory effect.
In order to realize above-mentioned and relevant purpose, one or more aspects of the present invention comprise the feature that the back will describe in detail and particularly point out in the claims.Following explanation and accompanying drawing describe some illustrative aspects of the present invention in detail.Yet, the indication of these aspects only be some modes that can use in the variety of way of principle of the present invention.In addition, the present invention is intended to comprise all these aspects and their equivalent.
Embodiment
Below with reference to accompanying drawing specific embodiments of the invention are described in detail.
Select suitable tool of compression to carry out relatively high-quality compression for the classification of the image of compression as required and process, the present invention according to characteristics such as the color of image, sizes image single cent lines class image and the photo class image two large classes of needs compression.Wherein, lines class image is fit to GIF, PNG format compression, and photo class image is fit to compress with JPEG.
Can judge according to parameters such as what and COLOR COMPOSITION THROUGH DISTRIBUTION rule of the color of image itself, sizes for the differentiation of lines class image and photo class image, generally speaking, the color of photo class image more and change complicated, such as the photo in the common cognition; The color category of lines class image is less, and change color is more regular, such as functional icon commonly used on the network, PPT, chart etc.
Because GIF and PNG utilize the toning platemaking technology to carry out image compression, when color of image is less, can reach very high compression ratio, but image effect is bad and compression ratio is very low (wherein GIF only supports 256 looks) when color of image is more, therefore is fit to compression lines class image.JPG utilize reduction image high-frequency signal method compress, irrelevant with the color of image number, comparison film has very high compression ratio, and display effect is fine (human eye is insensitive to high-frequency signal) also, but lines class picture is had very poor effect (show as image blurring, have variegated), and compression ratio is not high yet, therefore is more suitable for compressing photo class image.
Therefore, the unified form of certain form or employing original image that adopts does not come image is compressed if distinguish image type, and the image file after can causing compressing is larger, and the image display effect after decompressing is poor.
Fig. 1 is the Images Classification compression method schematic flow sheet according to the embodiment of the invention.As shown in Figure 1, Images Classification compression method provided by the invention comprises following basic procedure:
S110: obtain this Characteristic of Image value by image is scanned;
S120: the classification of judging this image according to the Characteristic of Image value of obtaining;
S130: the classification according to the image of judging is compressed this image.
Wherein, in order to judge the classification of image, the Characteristic of Image value that need to obtain comprises former bitmap-format, unit are number of colours, homochromy regional percentage, picture size and ratio.In addition, other also can be used as the foundation that characteristics of image becomes Images Classification such as characteristics of image such as brightness, histograms, generally speaking, the characteristics of image of classification institute foundation is more, the needed data processing amount of classifying is larger, but the effect of classification is also better, thereby provides the reference frame that more suits for sorted image compression.
The unit are number of colours is the color sum that comprises of image and the ratio of image area.
Homochromy regional percentage is the gross area in all homochromy zones in the image and the ratio of total image area, is the value of scope between 0~1.Herein, homochromy zone refers to the identical connected region of color in the image, that is to say, if the color of all pixels of a connected region (by forming more than a pixel) is identical in the image, and any one pixel is all different from pixel color on this zone on should the external boundary in zone, and then this zone is a homochromy zone.
Picture size and ratio refer to width, height and both ratio of image.
By image is scanned obtain above-mentioned Characteristic of Image value after, analyze this image feature value, judge the type of image according to default threshold value, image is divided into lines class image and photo class image.
Should be used for from common, the former figure of image generally adopts GIF, PNG or JPG form, and the image feature value that obtains according to the analysis to the former figure of image can be Images Classification lines class image and photo class image with default threshold value (as above shown in the table).
Because JPG is the lossy compression method form, and GIF and PNG are nondestructive compression types, and two class images have very big-difference, need to be that the situation of JPG or GIF/PNG is processed respectively to former figure therefore, and each overlap threshold value with one.By compression debugging and the test processes to great amount of images, the present invention is to adopt characteristic value and the threshold ratio shown in the following table one to judge parameter and criteria for classification image is classified:
Table one
Criteria for classification shown in the upper table is an exemplary illustration, it is not unique criteria for classification, also can use more senior artificial intelligence sorting technique to reach more careful concrete classification results, for example use artificial neural network technology, thereby make the better effects if of classified compression.
When using artificial neural network technology that picture is classified, can end user's artificial neural networks generation threshold value replace manually formulating threshold value.Such as, first manually to picture classification, then by the training of human artificial neural networks, make the artificial neural net classification results as far as possible near the manual sort, wherein, artificial neural net also can use some threshold values, and can be according to the automatic correction threshold of study analysis process of himself, make its classification constantly near manual sort's result, and criteria for classification is more objective and quantize.
After having determined the classification of image according to default threshold value, just can select corresponding compressed format to compress processing according to specific classification, be lines class image compression GIF or PNG namely, be photo class image compression JPG.
As above described according to Images Classification compression method of the present invention with reference to Fig. 1.Above-mentioned Images Classification compression method of the present invention can adopt software to realize, also can adopt hardware to realize, or adopts the mode of software and hardware combination to realize.
In addition, the present invention also provides a kind of Images Classification compressibility corresponding with said method, and Fig. 2 shows the block diagram according to the Images Classification compressibility 200 of the embodiment of the invention.As shown in Figure 2, Images Classification compressibility 200 comprises characteristics of image acquiring unit 210, image category judging unit 220 and image compression unit 230, and wherein, image compression unit 230 comprises GIF/PNG format compression unit 232 and JPG format compression unit 234.
Wherein, characteristics of image acquiring unit 210 is used for obtaining this Characteristic of Image value by image is scanned; Image category judging unit 220 is used for judging according to the Characteristic of Image value that characteristics of image acquiring unit 210 obtains the classification of this image; Image compression unit 230 is compressed this image for the classification of the image of judging according to image category judging unit 220.
In the present invention, characteristics of image acquiring unit 210 comprises the unit are number of colours of this image, homochromy regional percentage, picture size and ratio by image being scanned the image feature value that obtains, image category judging unit 220 is divided into lines class image and photo class image to image according to the Characteristic of Image value of obtaining and default threshold value.
Image compression unit 230 comprises again GIF/PNG format compression unit 232 and JPG format compression unit 234, when image category judging unit 220 is judged this image and is lines class image according to the former figure of image, be this image compression the GIF/PNG form by GIF/PNG format compression unit 232; When image category judging unit 220 is judged this image and is photo class image according to the former figure of image, be this image compression the JPG form by JPG format compression unit 232.
Fig. 3 is the relevant parameter schematic diagram that the former figure of two types image is compressed according to the different compress mode of the employing of the embodiment of the invention.
As shown in Figure 3, be the JPG image (this is exemplified as " entering microblogging " icon on the webpage) of 3.5KB for the former figure in the example one, by analysis, its characteristics of image is:
Homochromy regional percentage: 0.54
Unit are number of colours: 0.037
Long (W): 82; High (H): 21; W/H>2
Then according to the characteristic value of table one and threshold ratio, can find out, this icon image is lines class image, if with its boil down to JPG form, the file size after the compression is 1.5KB; If boil down to GIF form, the file size after the compression are 0.7KB.
For the GIF image that a former figure is 31.2KB, by analysis, its characteristics of image is:
Homochromy regional percentage: 0.478275
Unit are number of colours: 0.006375
Long (W): 200; High (H): 200
Then according to the characteristic value of table one and threshold ratio, can find out, this icon image is photo class image, if with its boil down to JPG form, the file size after the compression is 4.10KB; If boil down to GIF form, the file size after the compression are 4.22KB.
Parameter comparison by two image compression front and back among Fig. 3 can be found out, select suitable compressed format according to different image types, contribution to the file volume after the image compression is apparent, perhaps for a small amount of image storage or the very fast environment of network speed, the sensory effects of such little moment that the contribution of this file volume brings, but especially outstanding to the high occasion of image file volume requirement at large nuber of images storage or slow speed network etc.
The present invention carries out being chosen as with compressed format the classification of purpose to image by technological means, then different classes of image is adopted different compression methods, thereby by solved the classified compression storage to mass picture from technological layer, on the basis that ensures image displaying quality, greatly reduced the file volume of picture, can greatly save the memory space of mass picture, transmission speed that simultaneously also can the Effective Raise image file.
In addition, need to prove, the related three kinds of picture formats (GIF, PNG, JPG) of the above embodiment of the present invention are the main picture format that uses on the present the Internet, a kind of new lattice are arranged in addition WEBP (similar but higher compression ratio is arranged with JPG), also there is not at present the website to use, but can be considered as the picture format with JPEG one class, be equally applicable to classified compression method provided by the present invention and carry out the compression of image.And, the method of classified compression provided by the present invention is not limited to the classified compression of GIF, PNG, JPG, WEBP format-pattern, can also above-mentioned technology according to the present invention explain the compression that the thought that provides is applied to the technology of this classified compression the extended formatting image, with according to the own characteristic of image from the angle Selection of technology tool of compression more suitably, obtain the most rational compression effectiveness.
As above describe according to Images Classification compression method of the present invention and system in the mode of example with reference to accompanying drawing.But, it will be appreciated by those skilled in the art that the Images Classification compression method and the system that propose for the invention described above, can also make various improvement on the basis that does not break away from content of the present invention.Therefore, protection scope of the present invention should be determined by the content of appending claims.