Specific embodiment
Various image compression algorithms generally control the compression degree to image using mass parameter.With JPEG
Quality in (Joint Photographic Experts Group, Joint Photographic Experts Group) compression algorithm
As a example by the factor, JPEG removes redundancy in image using the mode for quantifying to be combined with lossless compression-encoding
Information, by quality factor, JPEG can control quantization step, produce the pressure of different quality and size
Contract drawing picture.Using same mass parameter different images are compressed when, compress image size and
Quality often because in image clean mark and fuzzy, color change substantially with close to etc. factor different and
There is certain difference.Therefore, if it is desired on the premise of compression image reaches certain visual effect as far as possible
Raising compression ratio, it is critical only that for certain specific image, selection is adapted to the compression quality of the image
Parameter.
In embodiments herein, the visual effect of compressed images is weighed using visual quality fraction.
Visual quality fraction can be generated by an index to several reflection visual effects, according to practical application
The need for scene, can be using the evaluation index of various picture qualities in the prior art, it would however also be possible to employ from
The image quality evaluation index of definition generates visual quality fraction.For example, can select to reflect compression figure
Visual quality fraction is generated as the index of visual continuity and the index of reflection compression image clearly degree.
The specific algorithm for generating visual quality fraction can also determine according to application scenarios, for example, can will be several
The product of individual selected index is used as visual quality fraction, it is also possible to make the exponential weighting product of selected index
It is visual quality fraction.
For such as JPEG, BPG (Better Portable Graphics, more preferable portable figure),
The splits' positions such as WEBP (a kind of while there is provided lossy compression method and the picture file format of Lossless Compression)
Algorithm, can be according to the saltus step journey between compression intensity of variation, each compression blocks of the image relative to original image
Spend with the intensity of variation inside compression blocks to determine visual quality fraction.In other words, visual quality fraction can
With by reflection compression image (S is set to relative to the index of the intensity of variation of original imagePWD), reflect each pressure
The index of the saltus step degree between contracting block (is set to SAAE) and reflection compression blocks inside intensity of variation finger
Mark (is set to STD) generate.
Wherein, SPWDThe change of divergence of overall importance of original image and compression image is embodied, when two figures
Global sex differernce it is big to a certain extent after, the visual effect of compression image can be significantly affected;Splits' positions are calculated
" disconnected line " phenomenon between method is likely to result in compression blocks in compression process (belongs to different compression blocks
Adjacent pixel jumping phenomenon), cause compress image visual effect be deteriorated, SAAEIt is used for embodying
The change of compression blocks marginal information;When compression quality parameter is too low, mould occurs inside compression blocks
The situation of paste so that compression image seems unintelligible, STDSchemed with compression using the compression blocks in original image
Compression blocks as in carry out the degree that inner vein relatively embodies change.Above three index has reacted figure
The global perception of picture, local edge are perceived and local a sense of texture is known, people has been reacted well to the comprehensive of image
Close visually-perceptible.
Similar, these three indexs can be using the image matter of the existing same content of reflection in the prior art
Figureofmerit, it is also possible to self-defining, provides a specific example of these three indexs individually below.
Index S to reflection compression image relative to the intensity of variation of original imagePWD, existing skill can be based on
PSNR (Peak Signal to Noise Ratio, Y-PSNR) index in art, using setting in advance
Fixed snr threshold THRPSNRAfter being normalized to PSNR, S is obtainedPWD。
PSNR embodies the mean square error between original image and compression image, a kind of specific computational methods
For:Corresponding each pixel obtains difference I in subtracting compression image with each pixel in original imageD, difference
Can be the difference, or RGB (Red, Green, Blue, RGB) of each grey scale pixel value
The difference of value.Assuming that M, N are respectively picture traverse and height in units of pixel, MAXIFor institute
There is difference I in pixelDMaximum, then PSNR can be calculated by formula 1:
Formula 1
According to formula 2, using snr threshold THRPSNRPSNR is normalized, S is obtainedPWD:
Formula 2
The index S of the saltus step degree reflected between each compression blocksAAEA kind of computational methods be:Belong to different
Continuity ratio is no more than continuity threshold value THR between the block of the neighbor pixel of compression blocksAAEPoint it is right
Number, accounts for ratio of all neighbor pixels for belonging to different compression blocks to number;Wherein, it is continuous between block
Property ratio is:Belong to the difference and the point between the laterally or longitudinally neighbor pixel pair of different compression blocks
To two pixels and in respective compression blocks the difference sum of adjacent pixel in the same direction ratio.
By taking JPEG splits' positions algorithms as an example, 8*8 is divided the image into when JPEG compression quantization encoding
Fritter carry out.Assuming that compression blocks A, compression blocks B, compression blocks C and compression blocks D are a compressions
Partial shrinkage block in image, each compression blocks include the pixel of 8*8.For example, in compression blocks A
Pixel includes:A11, A12To A18;A21, A22To A28;Until A81, A82To A88Totally 64 pixels.
Compression blocks A, B, C, D neighbouring relations therebetween are as shown in Figure 1.
Belong to the pixel A of compression blocks A18With the pixel B for belonging to compression blocks B11It is horizontal neighbor pixel
Right, continuity ratio can be calculated by formula 3 between its block:
Formula 3
Belong to the pixel A of compression blocks A81With the pixel C for belonging to compression blocks C11It is the neighbor pixel of longitudinal direction
Right, continuity ratio can be calculated by formula 4 between its block:
Formula 4
Refer to formula 3 and formula 4 calculates in the compression image all laterally adjacent pixels pair and all vertical
To neighbor pixel block continuity ratio.
Assuming that the width of the compression image in units of pixel and height are respectively M, N, the compression figure
As being divided into K*L compression blocks, then the compression image has that (K-1) * is N number of to belong to different compression blocks
Laterally adjacent pixel pair, M longitudinally adjacent pixel pair for belonging to different compression blocks of total (L-1) *,
The S of the imageAAEIndex can be calculated by formula 5:
Formula 5
Wherein, AAE is the mark value of the neighbor pixel pair for belonging to different compression blocks:Work as neighbor pixel
Block continuity ratio be no more than continuity threshold value THRAAEWhen, the AAE of the neighbor pixel pair
It is 1 to be worth, otherwise it is assumed that the continuity between the neighbor pixel pair is destroyed, its AAE value is 0.
The index S of the intensity of variation inside reflection compression blocksTDA kind of computational methods be:Calculate original image block
Interior change average value VARIWith change average value VAR in compressed picture blocksTRatio change lower limit in block
Threshold value VARTD1With change upper limit threshold VAR in blockTD2Between compression blocks, account for the ratio of all compression blocks.
Wherein, change average value VAR is in block:The difference of each pixel and all pixels average in compression blocks
After totalling, the ratio with number of pixels in compression blocks.
Specifically, it is assumed that the width and height of compression blocks in an image in units of pixel
Respectively M, N, then the average MEAN inside the compression blocks can be drawn by formula 6:
Formula 6
Wherein, I (m, n) is the value (can be gray value or rgb value) of pixel (m, n).
Change average value VAR can be drawn by formula 7 in the block of the compression blocks:
Formula 7
Each compression blocks is calculated respectively changes average value VAR in the block in original imageIAnd each compression blocks
Change average value VAR in block in image is compressedT。
Assuming that having T compression blocks in the compression image, the S of the compression image can be drawn by formula 8TD:
Formula 8
Wherein, when a compression blocks change average value VAR in block in original imageIAnd the compression blocks exist
Change average value VAR in block in compression imageTRatio when meeting formula 9, the S of the compression blocksblockTDFor
1, the otherwise S of the compression blocksblockTDIt is 0:
Formula 9
In above three example, snr threshold THRPSNR, continuity threshold value THRAAE, change in block
Lower threshold VARTD1With change upper limit threshold VAR in blockTD2Specific value, can be according to concrete application
Scene is realized determining.
A kind of computational methods based on above-mentioned formula 2, formula 5 and the middle finger target visual quality fraction s of formula 8 can
With such as formula 10:
S=(SPWD)α*(SAAE)β*(STD)γFormula 10
Wherein, α, β and γ are three weighting parameters of index, can be carried out according to concrete application scene
Regulation, the value of regulation can be determined by realizing.In application scenes, it is convenient for the sake of, can be with
Make alpha+beta+γ=1.
For a specific image, (pressed with the different same compression algorithms of mass parameter application
Except mass parameter changes in compression algorithm, other specification is constant), can obtain corresponding to mass parameter
Compression image, the visual quality fraction of the compression image is the visual quality point corresponding to mass parameter
Number.Mass parameter is represented with Q, visual quality fraction is represented with s, foot is chosen in the span of Q
Enough values are compressed, it is possible to obtain the relation curve of Q and s.
By inventor to different images, a large amount of compressed detecteds of different visual quality fraction generating modes,
Statistics finds:For same original image, same compression algorithm, the mass parameter used during compression with
The relation for compressing the visual quality fraction of image can be fitted to Gaussian function;The height of different image fittings
This function often has different parameters.
In a kind of implementation of the embodiment of the present application, Gaussian function uses the probability density letter of normal distribution
Several expression-forms, as shown in Equation 11:
Formula 11
Wherein, μ, k, σ are the parameter of the Gaussian function.
It is the process of Gaussian function by actual Q-s curve matchings, actually determines to best match to actual Q-s
The parameter μ of curve, the process of k, σ.It is the fitting precision needed according to concrete application scene, can be by
Undetermined parameter when these three parameters are all as fitting, it is also possible in these three variables is set to and is set
Definite value, using remaining two parameters as fitting when undetermined parameter.For example, μ is set into setting value can
The need for meet major applications scene.
For a determination s value, the compression of gained is compressed with corresponding Q on actual Q-s curves
Image and with according to be fitted the curve Gaussian function determine Q be compressed gained compression image,
Therebetween difference visually can identification very little.For example in fig. 2, the span of Q is 0
To 100, several different Q values are chosen, obtain compressing image after being compressed same original image
Visual quality fraction s value, to mark be point by each Q-s value, several Q-s values are to shape
Into the actual Q-s curves of point-like.Solid line in Fig. 2 is the Gaussian function curve for being fitted Q-s curves.
When s values are 0.9, correspondence Q values are 80 on actual Q-s curves, and the Gaussian function curve being fitted
Upper corresponding Q values are 74, are schemed with using obtained by Q=80 compressions using image obtained by Q=74 compressions
As almost not seeing difference visually.
So, in embodiments herein, visual quality fraction can be selected according to concrete application scene
Preset target value st, the usual preset target value can make the visual effect of compressed images meet actual
The minimum requirements of application;Assuming that the Gaussian function of fitting Q-s curves has n undetermined parameter, can use
The test value of n Q is compressed to original image, obtains corresponding n s values;With n known Q-s
Value is to obtaining the value of n undetermined parameter of the image Gaussian function;Afterwards can be according to the Gaussian function
Calculate stCorresponding mass parameter desired value Qt, using QtOriginal image is compressed, you can realize full
Compression ratio as far as possible high is used on the premise of visual effect needed for foot application, to reduce the rule of image file
Mould.
Embodiments herein proposes a kind of new method for compressing image, and its flow is as shown in Figure 3.The party
Method can be applied in any equipment with computing capability, such as terminal or server.Wherein, terminal can
Being the equipment such as mobile phone, panel computer, PC (Personal Computer, PC), notebook;
Server can be physically or logically server, not limit.
Step 310, using the test value of at least one mass parameter, is compressed original image with compression algorithm
It is test image.
As it was previously stated, being treated in Gaussian function of the number of mass parameter s test values according to fitting Q-s curves
Determine the number of parameter to determine.Due to original image Q values and s values can as determine Gaussian function in treat
A Q-s value for determining parameter is right, if the number of undetermined parameter is n in Gaussian function, as long as using (n-1)
Individual test value, (n-1) second compression is carried out to original image, obtain (n-1) individual test Q-s values to.
It is of course also possible to use it is more than (n-1) individual test value, to improve the levels of precision of fitting.
Step 320, visual quality fraction, corresponding mass parameter test value, base according to test image
Determine the corresponding mass parameter desired value of the preset target value of visual quality fraction in Gaussian function.Wherein,
Visual quality fraction is used for weighing the visual effect of compressed images, Gaussian function by visual quality fraction with
The relation fitting of mass parameter is obtained.
The index of the reflection visual effect used according to visual quality fraction and according to these quota students
Into the mode of visual quality fraction, the visual quality fraction of each test image is calculated, and obtain the test
It is right that the mass parameter test value for being used of image forms a Q-s value.
Using Q-s values are tested to, the Gaussian function expression formula including undetermined parameter, vision matter can be obtained
Measure the preset target value s of fractiontCorresponding mass parameter desired value Qt.Specific calculating process the application's
Embodiment is not limited, for example, Q-s values that can first according to test image are to calculating for being fitted Q-s
The undetermined parameter of the Gaussian function of relation, then by stGaussian function known to substituting into parameter, calculates Qt;
Can also first derive with several Q-s values to, stTo calculate QtExpression formula, by actual test chart
As Q-s values Q is can obtain to substituting into the expression formulat.It should be noted that may make in calculating process
With the Q values and s values of original image.
Step 330, using mass parameter desired value, is compressed with the compression algorithm to the original image.
Mass parameter desired value Q is being obtained by Gaussian functiontAfterwards, by QtIt is applied to the pressure in step 310
Compression algorithm, is compressed to original image, you can be met the preset target value s of visual quality fractiont's
Compression image.
It can be seen that, in embodiments herein, original image is compressed using the test value of mass parameter s
Obtain test Q-s values it is right, using test Q-s values to can determine be fitted original image Q-s relations height
This function, to calculate the preset target value s corresponding to visual quality fractiontCorresponding mass parameter mesh
Scale value Qt, using QtIt is as small as possible to compress original image, you can obtain in the case where visual effect requirement is met
Compression image, so as to compression image quality and compression ratio between reach good balance.
In an application example of the application, the computational methods of visual quality fraction s are the table in formula 10
Up to formula:
S=(SPWD)α*(SAAE)β*(STD)γFormula 10
Wherein, alpha+beta+γ=1.
Using the Gaussian function in formula 11 come the Q-s relations of fitting compaction image:
Formula 11
In this application example, μ is set to setting value 1.0;K and σ is undetermined parameter, its actual value and survey
Visual quality fraction, the corresponding mass parameter test value for attempting picture are related.
Assuming that to an image and JPEG compression algorithm, two different quality parameter Q values correspond to two
S values, obtain (s1, Q (s1)) and (s2, Q (s2)) two Q-s values are right.By the two Q-s values to substituting into
Formula 11, parameter k can be removed by being divided by, such as formula 12:
Formula 12
To the preset target value s of visual quality fractiontWith corresponding mass parameter desired value QtIt is worth right, formula 13
Set up:
Formula 13
Parameter σ in subtractive 13 and formula 12, can obtain calculating Q (st) formula 14:
Formula 14
In this application example, using the Q values of original image and corresponding s values as (s1, Q (s1)) value pair, then
s1=1, Q (s1)=100.When certain original image is compressed, original image Q (s are different from one1) Q (s2)
As mass parameter test value, with JPEG compression algorithm by the original image boil down to test image.With formula
The 10 visual quality fraction s for drawing test image2, obtain (s2, Q (s2)) value pair.By s1、Q(s1)、s2、
Q(s2) and visual quality parameter preset target value stSubstitution formula 14, obtains corresponding to stQ (st).Using
With QtIt is the JPEG compression compression algorithm original image of mass parameter, you can obtain final compression image.
So, tested only by first compression, it is possible to the Q values needed for obtaining final compression, to meter
Equipment (such as mobile phone) limited in one's ability and requirement of real-time application scenario high, compress the performance of image
Great guarantee is obtained.
Corresponding with the realization of above-mentioned flow, embodiments herein additionally provides one kind and applies in terminal or service
Image compressing device on device.The device can be realized by software, it is also possible to by hardware or soft or hard
The mode that part is combined is realized.It is by terminal as the device on logical meaning as a example by implemented in software
Or the CPU (Central Process Unit, central processing unit) of server is by corresponding computer program
Instruction runs what is formed in reading internal memory.From for hardware view, except the CPU shown in Fig. 4, interior
Deposit and nonvolatile memory outside, terminal where the device generally also includes for carrying out wireless communication
Number chip etc. of transmitting-receiving other hardware, the server where the device is generally also included for realizing that network leads to
Other hardware such as board of telecommunication function.
Fig. 5 show a kind of device of compression of images of the embodiment of the present application offer, including test image list
Unit, mass parameter target value cell and compression unit, wherein:Test image unit is used to use at least one
The test value of individual mass parameter, with compression algorithm by original image boil down to test image;Mass parameter target
Value cell is used for visual quality fraction, corresponding mass parameter test value according to test image, based on height
This function determines the corresponding mass parameter desired value of the preset target value of visual quality fraction;The vision matter
Amount fraction is used for weighing the visual effect of compressed images;The Gaussian function is by visual quality fraction and matter
The relation fitting for measuring parameter is obtained;Compression unit is used to use mass parameter desired value, is calculated with the compression
Method is compressed to the original image.
In one example, the compression algorithm includes:Splits' positions algorithm;The visual quality fractional root
The saltus step between index, each compression blocks of reflection according to reflection compression image relative to the intensity of variation of original image
The index of degree is generated with the index for reflecting the intensity of variation inside compression blocks.
In above-mentioned example, the reflection compression image includes relative to the index of the intensity of variation of original image:
The value of gained after being normalized to the Y-PSNR PSNR of test image using snr threshold.
In above-mentioned example, the index of the saltus step degree between each compression blocks of reflection includes:Belong to different
Continuity ratio is accounted for no more than the point of continuity threshold value to number between the block of the neighbor pixel of compression blocks
Ratio of all neighbor pixels for belonging to different compression blocks to number;Continuity ratio is between described piece:
Belong to difference and the point between the laterally or longitudinally neighbor pixel pair of different compression blocks to two
Pixel and in respective compression blocks the difference sum of adjacent pixel in the same direction ratio.
In above-mentioned example, the index of the intensity of variation inside the reflection compression blocks includes:In original image block
Change average value changes in lower threshold and block in block with the ratio of change average value in compressed picture blocks and becomes
Change the compression blocks between upper limit threshold, account for the ratio of all compression blocks;Changing average value in described piece is:
After each pixel is added up with the difference of all pixels average in compression blocks, the ratio with number of pixels in compression blocks
Value.
Optionally, the Gaussian function is:
Wherein, Q (s) is mass parameter;S is visual quality fraction;μ is setting value;The value of k and σ with
The visual quality fraction of test image, corresponding mass parameter test value are related.
Optionally, the mass parameter target value cell specifically for:Visual quality point according to original image
Number s1And corresponding to s1Mass parameter Q (s1), the visual quality fraction s of test image2And and correspondence
In s2Mass parameter Q (s2), the preset target value s of visual quality parameter is obtained according to following formulatCorresponding matter
Amount parameter objectives value Q (st):
The preferred embodiment of the application is the foregoing is only, is not used to limit the application, it is all at this
Within the spirit and principle of application, any modification, equivalent substitution and improvements done etc. should be included in
Within the scope of the application protection.
In a typical configuration, computing device includes one or more processors (CPU), input/output
Interface, network interface and internal memory.
Internal memory potentially includes the volatile memory in computer-readable medium, random access memory
And/or the form, such as read-only storage (ROM) or flash memory (flash RAM) such as Nonvolatile memory (RAM).
Internal memory is the example of computer-readable medium.
Computer-readable medium includes that permanent and non-permanent, removable and non-removable media can be by appointing
What method or technique realizes information Store.Information can be computer-readable instruction, data structure, program
Module or other data.The example of the storage medium of computer include, but are not limited to phase transition internal memory (PRAM),
Static RAM (SRAM), dynamic random access memory (DRAM), it is other kinds of with
Machine accesses memory (RAM), read-only storage (ROM), Electrically Erasable Read Only Memory
(EEPROM), fast flash memory bank or other memory techniques, read-only optical disc read-only storage (CD-ROM),
Digital versatile disc (DVD) or other optical storages, magnetic cassette tape, tape magnetic rigid disk are stored or it
His magnetic storage apparatus or any other non-transmission medium, can be used to store the letter that can be accessed by a computing device
Breath.Defined according to herein, computer-readable medium does not include temporary computer readable media (transitory
Media), such as the data-signal and carrier wave of modulation.
Also, it should be noted that term " including ", "comprising" or its any other variant be intended to it is non-
It is exclusive to include, so that process, method, commodity or equipment including a series of key elements are not only wrapped
Include those key elements, but also other key elements including being not expressly set out, or also include for this process,
Method, commodity or the intrinsic key element of equipment.In the absence of more restrictions, by sentence " including
One ... " key element that limits, it is not excluded that in the process including the key element, method, commodity or set
Also there is other identical element in standby.
It will be understood by those skilled in the art that embodiments herein can be provided as method, system or computer journey
Sequence product.Therefore, the application can using complete hardware embodiment, complete software embodiment or combine software and
The form of the embodiment of hardware aspect.And, the application can be used and wherein include calculating at one or more
Machine usable program code computer-usable storage medium (including but not limited to magnetic disk storage, CD-ROM,
Optical memory etc.) on implement computer program product form.