Detailed Description
In order that those skilled in the art will better understand the present invention, the following detailed description of the invention is provided in conjunction with the accompanying drawings.
An image scaling method according to an embodiment of the present invention is shown in fig. 1, and includes:
s101: acquiring edge information of pixel points of a target image corresponding to pixel points of a source image;
s102: and calculating the pixel value of the pixel point of the target image according to the edge information.
In the embodiment of the invention, the image is zoomed according to the size of the edge information. Therefore, the scaling amplitude of the strong edge texture, namely the pixel point with large edge information is large, and the corresponding scaled position of the position with large edge intensity of the image can be kept clear and stable. For the texture with weaker edge strength, namely the pixel point with small edge information, the scaling amplitude is smaller, so that the corresponding position of the image with small edge strength appears soft after scaling.
An image scaling method according to an embodiment of the present invention is shown in fig. 2, and a possible scenario is to scale an image output from a DVD, where the scaled image will meet the resolution required by a mobile television client, and then enter an encoder for encoding, where the encoder includes: MPEG-4, H.264 encoder, etc. the code stream encoded by the encoder can be directly played for the mobile phone or sent to the wireless network for live broadcast. The image scaling method specifically comprises the following steps:
s201: according to the image scaling, acquiring edge information of pixel points of the source image corresponding to pixel points of a target image;
firstly, the pixel values of all pixel points of a source image are obtained.
Secondly, according to the image scaling, determining the pixel value of the pixel point of the scaled target image corresponding to the pixel point in the source image before scaling; for example: the source image has 3i multiplied by 3j pixel points, if the target image has i multiplied by j pixel points, the image is reducedI.e. scaled toAnd determining that each pixel point in the i multiplied by j target images corresponds to the pixel value of the pixel point of the source image. Respectively taking the pixel points of the target image corresponding to the pixel points of the source image as the center, and taking n1×n1Each adjacent pixel point (the pixel point containing the target image corresponds to the pixel point of the source image) is formed by the n1×n1The pixel values of the pixel points form a matrix AijWherein n is1Is a natural number greater than 1.
And then, acquiring edge information of pixel points in the source image corresponding to the pixel points of the target image. Edge information yijThe predetermined edge extraction coefficient L and the matrix A can be used for obtainingijPerforming a convolution operation yij=L*AijThat is, there may be many kinds of edge extraction coefficients, and only three of them are listed here:
according to the method for extracting the edge information of the image, the edge information y is extracted from the pixel points of the source image corresponding to the pixel points of all the target imagesijThis results in an i × j edge information matrix B.
For example: assuming that a pixel point of the target image corresponding to a pixel point in the source image is a pixel point p, taking 9 adjacent pixel points (including p points) of 3 × 3 with the pixel point p as the center, and the pixel values of the 9 pixel points form the following matrix, wherein the pixel value of the p point is x4:
The edge extraction coefficients preferably adopted by the embodiment of the invention are as follows:
then the value y of the edge information of pixel point p is:
y=x0×(-1)+x1×(-1)+x2×(-1)+x3×(-1)+x4×8+x5×(-1)+x6×(-1)+x7×(-1)+x8×(-1)
by extracting the edge information of the pixel points of all the target images corresponding to the pixel points in the source image, the edge information meeting the resolution required by a user can be obtained and is used for controlling the size of the coefficient of the zoom filter taking the pixel points of the target images corresponding to the pixel points in the source image as the center.
S202: performing edge filtering on the obtained edge information;
the edge information extracted in S201 may cause the image to appear hard due to the jump of the strong edge information and the weak edge information, so that the subjective quality of the image is prevented from being deteriorated due to the sudden change of the strength of the edge information. At this time, edge filtering needs to be performed on the extracted edge information matrix, so that adjacent edge information of the edge information matrix obtains smooth transition, and the edge filtering process is similar to the process of extracting the edge information in S201: respectively with the obtained edge information yijAs a center, take n2×n2Adjacent edge information (including the edge information) from the n2×n2Edge information forming matrix CijWherein n is2Is a natural number greater than 1, using CijConvolving with the edge filter coefficient K to obtain filtered edge information y'ij. For all edge information y in the edge information matrix BijFiltering is performed so that an i × j filtered edge information matrix D is obtained. There are many kinds of edge filter coefficients, and only three of them are listed here:
for example: assume that the certain obtained edge information is y43 × 3 adjacent edge information and y centered on the edge information4The matrix is formed by the above-mentioned materials,
the edge filter coefficients preferably adopted by the embodiment of the invention are as follows:
then the value y 'of the edge information after filtering'4Comprises the following steps:
y′4=y0×1+y1×1+y2×1+y3×1+y4×4+y5×1+y6×1+y7×1+y8×1
s203: and carrying out image scaling on the source image by utilizing the edge information after edge filtering.
Obtaining edge information y 'after edge filtering by utilizing S202'ijCalculating the scaling filter coefficient F of the pixel point of the target imageij. Based on the derived scaling filter coefficients FijAnd the pixel value calculation of each pixel point after the zooming is finished through the filtering processing of the filter, so that the zooming processing of the image is realized. The method specifically comprises the following steps:
first, edge information y 'after edge filtering obtained in S202 is used'ijTo calculate the scaling filter coefficient F of the pixel point of the target imageij。
The scaling filter coefficients of embodiments of the present invention may be extracted by the following sinc function,
<math>
<mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>a</mi>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mfenced open='{' close=''>
<mtable>
<mtr>
<mtd>
<mfrac>
<mrow>
<mi>sin</mi>
<mrow>
<mo>(</mo>
<mi>π</mi>
<mfrac>
<mi>a</mi>
<mi>d</mi>
</mfrac>
<mo>)</mo>
</mrow>
</mrow>
<mrow>
<mi>π</mi>
<mfrac>
<mi>a</mi>
<mi>d</mi>
</mfrac>
</mrow>
</mfrac>
<mo>×</mo>
<mi>sin</mi>
<mo>[</mo>
<mfrac>
<mi>π</mi>
<mn>2</mn>
</mfrac>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>+</mo>
<mfrac>
<mi>a</mi>
<mrow>
<mi>N</mi>
<mo>×</mo>
<mi>d</mi>
</mrow>
</mfrac>
<mo>)</mo>
</mrow>
<mo>]</mo>
<mo>,</mo>
<mo>|</mo>
<mi>a</mi>
<mo>|</mo>
<mo><</mo>
<mi>N</mi>
<mo>×</mo>
<mi>d</mi>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
<mo>,</mo>
<mo>|</mo>
<mi>a</mi>
<mo>|</mo>
<mo>≥</mo>
<mi>N</mi>
<mo>×</mo>
<mi>d</mi>
</mtd>
</mtr>
</mtable>
</mfenced>
<mo>-</mo>
<mo>-</mo>
<mo>-</mo>
<mn>2.1</mn>
</mrow>
</math>
a in the formula 2.1 represents the distance between the pixel point of the target image corresponding to the pixel point in the source image and other pixel points in the source image, for example, the distance between the pixel point of the target image corresponding to the pixel point in the source image and a certain pixel point in the source image is the distance of 2 unit pixels, and then a can be 2; n is the number of single side lobe, when N is N3Then, it means that a certain pixel point is taken as the center, where n3Is a natural number greater than 1, and n is selected3×n3Each pixel point is taken as the adjacent area of the pixel point; d is a decimation factor, which can be represented by the formula:
d=2/255*y+1 2.2
where y is edge information, which may be the edge information in S201, or the edge after filtering in S202.
Respectively calculating a pixel point q of a pixel point of a target image corresponding to a source image and a pixel point n of the source image with the pixel point q as a center3×n3The distance of each pixel point is obtained3×n3The value of a; then d corresponding to the pixel point q is obtained according to a formula 2.2, and then n is respectively added3×n3The value of a and d are substituted into a formula 2.1, and the scaling filter coefficient F of the pixel point q of the target image can be obtained, wherein the scaling filter coefficient F is n3×n3An order matrix.
Secondly, according to the pixel values of the pixel points obtained in the step S201, taking n from the pixel point q of the target image corresponding to the pixel point in the source image as a center3×n3A neighboring pixel point (including the pixel point q) from the n3×n3The pixel values of the individual pixels form a matrix E.
Then, using n obtained as described above3×n3Filter coefficient F of the order scaling filter, and the above n3×n3Matrix E, corresponding the pixel point of the target image to the pixel of the source imageThe pixel values of the points are filtered.
According to the method described in S203, the same filtering process is performed on all the pixels of the target image corresponding to the pixels of the source image, so that the pixel values of all the scaled pixels of the target image can be obtained, and image scaling is achieved.
For example: according to the above method, if n3If the value is 6, calculating a filter coefficient F of the scaling filter of the pixel point q of the source image corresponding to the pixel point of the target image as:
and obtaining the matrix E, wherein the matrix E is a 6 × 6-order matrix:
then the scaled pixel value x' of the target pixel point may be:
<math>
<mrow>
<msup>
<mi>x</mi>
<mo>′</mo>
</msup>
<mo>=</mo>
<mfrac>
<mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>a</mi>
<mn>11</mn>
</msub>
<mo>)</mo>
</mrow>
<mo>×</mo>
<msub>
<mi>c</mi>
<mn>11</mn>
</msub>
<mo>+</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>a</mi>
<mn>12</mn>
</msub>
<mo>)</mo>
</mrow>
<mo>×</mo>
<msub>
<mi>c</mi>
<mn>12</mn>
</msub>
<mo>+</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<mo>+</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>a</mi>
<mn>66</mn>
</msub>
<mo>)</mo>
</mrow>
<mo>×</mo>
<msub>
<mi>c</mi>
<mn>66</mn>
</msub>
</mrow>
<mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>a</mi>
<mn>11</mn>
</msub>
<mo>)</mo>
</mrow>
<mo>+</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>a</mi>
<mn>12</mn>
</msub>
<mo>)</mo>
</mrow>
<mo>+</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<mo>+</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>a</mi>
<mn>66</mn>
</msub>
<mo>)</mo>
</mrow>
</mrow>
</mfrac>
</mrow>
</math>
in the embodiment of the invention, each target pixel point corresponds to one scaling filter coefficient, so that the scaling filter coefficients of different target pixel points are obtained according to the size of the edge information, and the pixel value of the target pixel point is calculated by using the scaling filter coefficients. Therefore, the scaling amplitude of the strong edge texture, namely the pixel point with large edge information is large, and the corresponding scaled position of the position with large edge intensity of the image can be kept clear and stable. For the texture with weaker edge strength, namely the pixel point with small edge information, the scaling amplitude is smaller, so that the corresponding position of the scaled position with the smaller edge strength of the image is soft, and the soft texture has smoother change with the surrounding pixels, thereby improving the coding efficiency of the image in the compression process.
Fig. 3 shows a schematic structural diagram of an image scaling apparatus according to an embodiment of the present invention, including:
an edge information obtaining unit 31, configured to obtain edge information of a pixel point of the target image corresponding to a pixel point of the source image;
the specific process can be referred to the description in S201.
And the pixel value calculating unit 32 is configured to calculate pixel values of pixel points of the target image according to the edge information.
The specific process can be referred to the description in S203.
Further: the edge information acquiring unit 31 specifically includes a pixel value acquiring first sub-unit 311 and an edge information calculating sub-unit 312; a pixel value obtaining first subunit 311, configured to obtain pixel values of all pixel points of the source image, and take n from the pixel point of the target image corresponding to the pixel point of the source image as a center1×n1Adjacent pixel points of n1×n1The pixel values of adjacent pixel points form a matrix A; and the edge information calculating subunit 312 is configured to obtain, according to the obtained pixel value, edge information of a pixel point of the target image corresponding to a pixel point of the source image.
The specific process can be referred to the description in S201.
Further: the pixel value calculating unit 32 specifically includes a scaling filter coefficient calculating unit 321, a pixel value obtaining subunit 322, and a pixel value calculating subunit 323; wherein,
a scaling filter coefficient calculating unit 321, configured to calculate a scaling filter coefficient F of a pixel point of the target image according to the edge information, where the coefficient is n3×n3Matrix of orders, said n3Is a natural number greater than 1; a second sub-unit 322 for obtaining pixel values, configured to obtain a matrix E, where n is taken from a pixel point q in the source image corresponding to a pixel point of the target image as a center3×n3A neighboring pixel point consisting of n3×n3The pixel values of the pixel points form the matrix E; and the pixel value operator unit 323 is used for calculating the pixel value of the pixel point of the target image according to the scaling filter coefficient F and the matrix E.
The specific process can be referred to the description in S203.
Optionally, as shown in fig. 4, the image scaling apparatus may further include: an edge filtering unit 33, configured to perform edge filtering on the edge information, where the pixel value calculating unit 32 is further configured to calculate a pixel value of a pixel point of the target image according to the edge information after the edge filtering.
The specific process can be seen in the description in S202.
In the embodiment of the invention, the image scaling is realized according to the edge information. Therefore, the scaling amplitude of the strong edge texture, namely the pixel point with large edge information is large, and the corresponding scaled position of the position with large edge intensity of the image can be kept clear and stable. For the texture with weaker edge strength, namely the pixel point with small edge information, the scaling amplitude is smaller, so that the corresponding position of the scaled position with the smaller edge strength of the image is soft, and the soft texture has smoother change with the surrounding pixels, thereby improving the coding efficiency of the image in the compression process.
Through the above description of the embodiments, those skilled in the art will clearly understand that the present invention may be implemented by software plus a necessary general hardware platform, and certainly may also be implemented by hardware, but in many cases, the former is a better implementation method. Based on such understanding, the technical solutions of the embodiments of the present invention may be essentially or partially implemented in the form of a software product stored in a storage medium and including instructions for causing a mobile device (which may be a mobile phone, a personal computer, a media player, etc.) to execute the methods according to the embodiments of the present invention. Storage media, as referred to herein, are: ROM/RAM, magnetic disks, optical disks, and the like.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.