CN102521803B - Anti-aliasing method and device in image scaling - Google Patents
Anti-aliasing method and device in image scaling Download PDFInfo
- Publication number
- CN102521803B CN102521803B CN2011103884782A CN201110388478A CN102521803B CN 102521803 B CN102521803 B CN 102521803B CN 2011103884782 A CN2011103884782 A CN 2011103884782A CN 201110388478 A CN201110388478 A CN 201110388478A CN 102521803 B CN102521803 B CN 102521803B
- Authority
- CN
- China
- Prior art keywords
- luminance
- value
- max
- brightness value
- brightness
- 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.)
- Expired - Fee Related
Links
Images
Landscapes
- Image Processing (AREA)
Abstract
本发明涉及图像处理技术领域,提供了一种图像缩放中的抗锯齿失真方法,所述图像缩放中的抗锯齿失真方法包括步骤:A:根据放大后的目标图像中待插值点位置得到对应原始图像中预设邻域的亮度矩阵;B:根据预设邻域的亮度矩阵的亮度差值判断所述待插值点的亮度值是否需要校正,如果是,则进行步骤C;否则,结束流程;C:校正所述待插值点的亮度值。本发明还提供了一种图像缩放中的抗锯齿失真装置。应用本发明,能够在图像放大过程中抑制并减小阶梯的放大,从而达到抗锯齿失真的效果。
The present invention relates to the technical field of image processing, and provides an anti-aliasing method in image scaling. The anti-aliasing method in image scaling includes the steps: A: Obtain the corresponding original The brightness matrix of the preset neighborhood in the image; B: judging whether the brightness value of the point to be interpolated needs to be corrected according to the brightness difference of the brightness matrix of the preset neighborhood, if so, proceed to step C; otherwise, end the process; C: Correcting the brightness value of the point to be interpolated. The invention also provides an anti-aliasing distortion device in image zooming. By applying the present invention, the step enlargement can be suppressed and reduced during image enlargement, so as to achieve the effect of anti-aliasing distortion.
Description
技术领域 technical field
本发明涉及图形处理技术领域,特别涉及一种用于图像缩放中的抗锯齿失真方法及装置。The invention relates to the technical field of graphics processing, in particular to an anti-aliasing method and device used in image zooming.
背景技术 Background technique
目前,显示装置的类型越来越丰富,各种显示装置由于自身特点和应用场合的不同,都有各自最佳的显示大小。另一方面,输入这些显示装置的图像信号的大小也有很宽的变换范围。基于此,必然需要对图像进行缩小、放大处理。除此之外,为使用户专注于图像的某个细节或获得图像的整体概貌等也都需要对图像进行缩放处理。Currently, there are more and more types of display devices, and each display device has its own optimal display size due to its own characteristics and different application occasions. On the other hand, the size of image signals input to these display devices also has a wide range of change. Based on this, it is necessary to reduce and enlarge the image. In addition, in order to make the user focus on a certain detail of the image or obtain an overall overview of the image, it is also necessary to zoom in on the image.
图像放大主要是通过图像插值来实现。图像插值就是根据已知的图像像素信息来推导和计算新的像素信息。传统的插值方法包括最近邻域插值、双线性插值和双三次插值。但是,现有的图像放大方法面临的主要问题包括图像模糊和锯齿失真两个方面,其中图像模糊是指放大后图像的细节变得模糊不清,而锯齿失真是指放大的图像在边缘处出现的锯齿状的人工痕迹。Image enlargement is mainly realized through image interpolation. Image interpolation is to derive and calculate new pixel information based on known image pixel information. Traditional interpolation methods include nearest neighbor interpolation, bilinear interpolation and bicubic interpolation. However, the main problems faced by existing image enlargement methods include image blurring and aliasing. Image blurring means that the details of the enlarged image become blurred, while aliasing means that the enlarged image appears at the edge. jagged artifacts.
由于在数字图像中,除了竖直和水平的直线边缘外,其它边缘是不连续、离散的,即图像中的边缘处本身存在锯齿和阶梯,图像放大的方法会使得这些小阶梯变为大阶梯,从而形成较为明显的锯齿。如果能够在图像放大过程中,抑制和减小阶梯的放大,就会抑制边缘的锯齿失真。Since in a digital image, except for the vertical and horizontal straight line edges, other edges are discontinuous and discrete, that is, there are jagged edges and steps in the edges of the image, and the method of image enlargement will make these small steps into large steps. , thus forming a more obvious sawtooth. If the magnification of the steps can be suppressed and reduced during the image enlargement process, the aliasing distortion of the edge will be suppressed.
这样一来,如何抑制和减小阶梯的放大就成了图像处理技术领域中一个亟待解决的技术问题。In this way, how to suppress and reduce the magnification of steps has become a technical problem to be solved urgently in the field of image processing technology.
发明内容 Contents of the invention
(一)要解决的技术问题(1) Technical problems to be solved
针对上述缺点,本发明为了解决现有图像放大技术中存在的锯齿失真的技术问题,提供了一种用于图像缩放中的抗锯齿失真方法及装置,其能够在图像放大过程中抑制并减小阶梯的放大,从而达到抗锯齿失真的效果。In view of the above shortcomings, the present invention provides an anti-aliasing method and device for image zooming in order to solve the technical problem of aliasing distortion existing in the existing image zooming technology, which can suppress and reduce the Step magnification, so as to achieve the effect of anti-aliasing distortion.
(二)技术方案(2) Technical solution
为了解决上述技术问题,一方面,本发明提供了一种图像缩放中的抗锯齿失真方法,包括步骤:In order to solve the above technical problems, on the one hand, the present invention provides an anti-aliasing method in image scaling, comprising steps:
A:根据放大后的目标图像中待插值点位置得到对应原始图像中预设邻域的亮度矩阵;A: Obtain the brightness matrix corresponding to the preset neighborhood in the original image according to the position of the point to be interpolated in the enlarged target image;
B:根据预设邻域的亮度矩阵的亮度差值判断所述待插值点的亮度值是否需要校正,如果是,则进行步骤C;否则,结束流程;B: judging whether the luminance value of the point to be interpolated needs to be corrected according to the luminance difference of the luminance matrix of the preset neighborhood, if so, proceed to step C; otherwise, end the process;
C:校正所述待插值点的亮度值。C: Correcting the brightness value of the point to be interpolated.
其中,所述步骤B具体包括:Wherein, the step B specifically includes:
步骤B1:计算预设邻域的亮度矩阵的远邻域的亮度差异阈值;Step B1: Calculating the luminance difference threshold of the far neighborhood of the luminance matrix of the preset neighborhood;
步骤B2:计算预设邻域的亮度矩阵的近邻域的亮度差异阈值;Step B2: Calculating the brightness difference threshold of the nearest neighbor of the brightness matrix of the preset neighborhood;
步骤B3:根据预设邻域的亮度矩阵的远近邻域的亮度差异阈值判断所述待插值点的亮度值是否需要校正。Step B3: judging whether the luminance value of the point to be interpolated needs to be corrected according to the luminance difference threshold of the far and near neighborhoods of the luminance matrix of the preset neighborhood.
其中,所述步骤C具体包括:Wherein, the step C specifically includes:
步骤C1:计算所述待插值点的亮度差异阈值;Step C1: Calculating the brightness difference threshold of the points to be interpolated;
步骤C2:计算亮度矩阵的亮度中值;Step C2: calculating the median brightness value of the brightness matrix;
步骤C3:校正所述待插值点的亮度值并输出。Step C3: Correct and output the luminance value of the point to be interpolated.
其中,所述步骤C3具体包括:Wherein, the step C3 specifically includes:
步骤C31:计算亮度矩阵的亮度中值与图像缩放后的该待插值点亮度值间的差值;Step C31: Calculate the difference between the median brightness value of the brightness matrix and the brightness value of the point to be interpolated after image scaling;
步骤C32:将待插值点的亮度差异阈值的正负值分别作为差值的上下限;Step C32: Use the positive and negative values of the brightness difference threshold of the point to be interpolated as the upper and lower limits of the difference;
步骤C33:将差值补偿到图像缩放后的该待插值点亮度值上作为图像输出。Step C33: Compensate the difference to the luminance value of the point to be interpolated after image scaling, and output it as an image.
其中,所述步骤A具体包括:Wherein, the step A specifically includes:
在原始图像中取待插值点(fi,j)的M行N列的邻域,其中M为偶数,N为奇数,以这M行N列个邻域点的亮度值构成M×N的亮度矩阵,其中fi根据公式确定,其中h_src为原始图像高,h_dst为目标图像高,(m,j)为待插值点在目标图像中的位置,(fi,j)为待插值点在原始图像中的位置,Take the neighborhood of M rows and N columns of the point to be interpolated (fi, j) in the original image, where M is an even number and N is an odd number, and the brightness values of these M rows and N columns of neighborhood points constitute M×N brightness matrix, where fi according to the formula Determine, where h_src is the height of the original image, h_dst is the height of the target image, (m, j) is the position of the point to be interpolated in the target image, (fi, j) is the position of the point to be interpolated in the original image,
或,or,
在原始图像中取待插值点(i,fj)的L行P列的邻域,其中L为奇数,P为偶数,以这L行P列个邻域点的亮度值构成L×P的亮度矩阵,其中fj根据公式确定,其中w_src为原始图像宽,w_dst为目标图像宽,(i,n)为待插值点在目标图像中的位置,(i,fj)为待插值点在原始图像中的位置。In the original image, take the neighborhood of L rows and P columns of the point to be interpolated (i, fj), where L is an odd number and P is an even number, and the brightness values of these L rows and P columns of neighborhood points constitute the brightness of L×P matrix, where fj according to the formula Determine, where w_src is the width of the original image, w_dst is the width of the target image, (i, n) is the position of the point to be interpolated in the target image, (i, fj) is the position of the point to be interpolated in the original image.
其中,所述步骤B1具体包括:Wherein, the step B1 specifically includes:
计算M×N的亮度矩阵中间一列上前M/2个像素和第一行上其他像素中的最大亮度值top1_max和最小亮度值top1_min,以及计算中间一列上后M/2个像素和最后一行上其他像素中的最大亮度值bot1_max和最小亮度值bot1_min,并根据公式diff1=max(top1_min-bot1_max,bot1_min-top1_max)计算亮度矩阵的远邻域的亮度差异阈值diff1,并当diff1<0时,令diff1=0;或,Calculate the maximum brightness value top1_max and the minimum brightness value top1_min of the first M/2 pixels on the middle column of the M×N brightness matrix and other pixels on the first row, and calculate the last M/2 pixels on the middle column and the last row The maximum brightness value bot1_max and the minimum brightness value bot1_min in other pixels, and according to the formula diff1=max(top1_min-bot1_max, bot1_min-top1_max), calculate the brightness difference threshold diff1 of the far neighbors of the brightness matrix, and when diff1<0, make diff1=0; or,
计算L×P的亮度矩阵中间一行上前P/2个像素和第一列上其他像素中的最大亮度值left1_max和最小亮度值left1_min,以及计算中间一行上后P/2个像素和最后一列上其他像素中的最大亮度值right1_max和最小亮度值right1_min,并根据公式diff1=max(left1_min-right1_max,right1_min-left1_max)计算亮度矩阵的远邻域的亮度差异阈值diff1,并当diff1<0时,令diff1=0。Calculate the maximum brightness value left1_max and the minimum brightness value left1_min of the first P/2 pixels on the middle row of the brightness matrix of L×P and other pixels on the first column, and calculate the last P/2 pixels on the middle row and the last column The maximum brightness value right1_max and the minimum brightness value right1_min in other pixels, and according to the formula diff1=max(left1_min-right1_max, right1_min-left1_max) calculate the brightness difference threshold diff1 of the far neighbors of the brightness matrix, and when diff1<0, make diff1=0.
其中,所述步骤B2具体包括:Wherein, the step B2 specifically includes:
计算M×N的亮度矩阵中间一列上前M/2个像素和第M/2行上其他像素中的最大亮度值top2_max和最小亮度值top2_min,以及计算中间一列上后M/2个像素和第M/2+1行上其他像素中的最大亮度值bot2_max和最小亮度值bot2_min,并根据公式diff2=max(top2_min-bot2_max,bot2_min-top2_max)计算亮度矩阵的近邻域的亮度差异阈值diff2,并当diff2<0时,令diff2=0;或,Calculate the maximum brightness value top2_max and the minimum brightness value top2_min of the first M/2 pixels on the middle column of the M×N brightness matrix and other pixels on the M/2th row, and calculate the last M/2 pixels and the first M/2 pixels on the middle column Maximum luminance value bot2_max and minimum luminance value bot2_min in other pixels on the M/2+1 line, and calculate the luminance difference threshold diff2 of the neighborhood of the luminance matrix according to the formula diff2=max(top2_min-bot2_max, bot2_min-top2_max), and when When diff2<0, let diff2=0; or,
计算L×P的亮度矩阵中间一行上前P/2个像素和第P/2列上其他像素中的最大亮度值left2_max和最小亮度值left2_min,以及计算中间一行上后P/2个像素和第P/2+1列上其他像素中的最大亮度值right2_max和最小亮度值right2_min,并根据公式diff2=max(left2_min-right2_max,right2_min-left2_max)计算亮度矩阵pixel2的近邻域的亮度差异阈值diff2,并当diff2<0时,令diff2=0。Calculate the maximum brightness value left2_max and the minimum brightness value left2_min of the first P/2 pixels on the middle row of the L×P brightness matrix and other pixels on the P/2th column, and calculate the last P/2 pixels and the first row on the middle row Maximum luminance value right2_max and minimum luminance value right2_min in other pixels on P/2+1 column, and according to formula diff2=max (left2_min-right2_max, right2_min-left2_max) calculate the luminance difference threshold diff2 of the neighborhood of luminance matrix pixel2, and When diff2<0, make diff2=0.
其中,所述步骤B3具体包括:Wherein, the step B3 specifically includes:
根据公式m_diff=diff1-diff2得到预设邻域的亮度矩阵的中点的亮度差异阈值m_diff,当m_diff>0时,确定所述待插值点的亮度值需要校正,否则不需要校正。According to the formula m_diff=diff1-diff2, the brightness difference threshold m_diff of the midpoint of the brightness matrix of the preset neighborhood is obtained. When m_diff>0, it is determined that the brightness value of the point to be interpolated needs to be corrected, otherwise no correction is required.
其中,所述步骤C1具体包括:Wherein, the step C1 specifically includes:
根据纵向的偏移距离Δy与中点的亮度差异阈值m_diff得到待插值点的亮度差异阈值threshold,计算公式为:According to the longitudinal offset distance Δy and the brightness difference threshold m_diff of the midpoint, the brightness difference threshold of the point to be interpolated is obtained, and the calculation formula is:
根据横向的偏移距离Δx与中点的亮度差异阈值m_diff得到待插值点的亮度差异阈值threshold,计算公式为:According to the horizontal offset distance Δx and the brightness difference threshold m_diff of the midpoint, the brightness difference threshold of the point to be interpolated is obtained, and the calculation formula is:
其中,所述步骤C2具体包括:Wherein, the step C2 specifically includes:
对M×N的亮度矩阵中心两行的各个像素的亮度值进行从低到高排序,取排序后中间两个亮度值的平均值avg作为亮度矩阵中点的亮度值;根据下式得到亮度矩阵的亮度中值median,Sort the luminance values of each pixel in the center two rows of the M×N luminance matrix from low to high, and take the average value avg of the two middle luminance values after sorting as the luminance value of the middle point of the luminance matrix; obtain the luminance matrix according to the following formula The median of the brightness,
其中pixeli,j表示点(i,j)的亮度值,pixeli+1,j表示点(i+1,j)的亮度值,i为横坐标fi的下取整值;或,Wherein pixel i, j represents the brightness value of point (i, j), pixel i+1, j represents the brightness value of point (i+1, j), and i is the lower integer value of the abscissa fi; or,
对L×P的亮度矩阵中心两列的各个像素的亮度值进行从低到高排序,取排序后中间两个亮度值的平均值avg作为亮度矩阵中点的亮度值,根据下式得到亮度矩阵的亮度中值median,Sort the luminance values of each pixel in the center two columns of the L×P luminance matrix from low to high, take the average value avg of the two middle luminance values after sorting as the luminance value of the middle point of the luminance matrix, and obtain the luminance matrix according to the following formula The median of the brightness,
其中pixeli,j表示点(i,j)的亮度值,pixeli,j+1表示点(i,j+1)的亮度值,j为纵坐标fj的下取整值。Wherein, pixel i, j represents the brightness value of the point (i, j), pixel i, j+1 represents the brightness value of the point (i, j+1), and j is the lower integer value of the vertical coordinate fj.
本发明还公开了一种图像缩放中的抗锯齿失真装置,包括:The invention also discloses an anti-aliasing device in image zooming, including:
亮度矩阵获取单元,用于根据放大后的目标图像中待插值点位置得到对应原始图像中预设邻域的亮度矩阵;A luminance matrix acquisition unit, configured to obtain a luminance matrix corresponding to a preset neighborhood in the original image according to the position of the point to be interpolated in the enlarged target image;
校正判决单元,用于根据预设邻域的亮度矩阵的亮度差值判断所述待插值点的亮度值是否需要校正;A correction judgment unit, configured to judge whether the luminance value of the point to be interpolated needs to be corrected according to the luminance difference value of the luminance matrix of the preset neighborhood;
亮度值校正单元,用于校正所述待插值点的亮度值。A brightness value correction unit, configured to correct the brightness value of the point to be interpolated.
其中,所述校正判决单元具体包括:Wherein, the correction judgment unit specifically includes:
远邻域亮度差异阈值计算子单元,用于计算预设邻域的亮度矩阵的远邻域的亮度差异阈值;The distant neighborhood brightness difference threshold calculation subunit is used to calculate the brightness difference threshold of the far neighborhood of the brightness matrix of the preset neighborhood;
近邻域亮度差异阈值计算子单元,用于计算预设邻域的亮度矩阵的近邻域的亮度差异阈值;The neighborhood brightness difference threshold calculation subunit is used to calculate the brightness difference threshold of the neighborhood of the brightness matrix of the preset neighborhood;
校正判决子单元,用于根据预设邻域的亮度矩阵的远近邻域的亮度差异阈值判断所述待插值点的亮度值是否需要校正。The correction judgment subunit is used to judge whether the brightness value of the point to be interpolated needs to be corrected according to the brightness difference threshold value of the far and near neighborhoods of the brightness matrix of the preset neighborhood.
其中,所述亮度值校正单元具体包括:Wherein, the brightness value correction unit specifically includes:
亮度差异阈值计算子单元,用于计算所述待插值点的亮度差异阈值;A luminance difference threshold calculation subunit, configured to calculate the luminance difference threshold of the point to be interpolated;
亮度中值计算子单元,用于计算亮度矩阵的亮度中值;The brightness median calculation subunit is used to calculate the brightness median of the brightness matrix;
亮度值校正子单元,用于校正所述待插值点的亮度值并输出。The luminance value correcting subunit is used to correct and output the luminance value of the point to be interpolated.
其中,所述亮度值校正子单元具体包括:Wherein, the brightness value correcting subunit specifically includes:
差值计算模块,用于计算亮度矩阵的亮度中值与图像缩放后的该待插值点亮度值间的差值;A difference calculation module, used to calculate the difference between the brightness median of the brightness matrix and the brightness value of the point to be interpolated after the image is scaled;
差值限制模块,用于将待插值点的亮度差异阈值的正负值分别作为差值的上下限;The difference limit module is used to use the positive and negative values of the brightness difference threshold of the points to be interpolated as the upper and lower limits of the difference respectively;
亮度值校正模块,用于将差值补偿到图像缩放后的该待插值点亮度值上作为图像输出。The luminance value correction module is used to compensate the difference to the luminance value of the point to be interpolated after the image is scaled and output it as an image.
(三)有益效果(3) Beneficial effects
本发明提供了一种图像缩放中的抗锯齿失真方法及装置,其根据放大后的目标图像中待插值点位置得到对应原始图像中预设邻域的亮度矩阵,其分别考虑图像的横纵向放大选取待插值点在对应原始图像中预设邻域的亮度矩阵,避免了其他因素的干扰,简单易行;根据预设邻域的亮度矩阵的亮度差值判断所述待插值点的亮度值是否需要校正,其在选取远近邻域的亮度差异阈值时,除了最远或最近邻域的行或列,还考虑了待插值点所在的行或列上的其他像素,由于待插值点所在的行或列上像素的亮度值变化的最明显,因此使得选取的远近邻域的亮度差异阈值更加准确,由此做出的是否校正的判断更加符合实际;校正所述待插值点的亮度值,将计算得到的所述待插值点的亮度差异阈值的正负值作为亮度矩阵的亮度中值与图像缩放后的该待插值点亮度值间的差值的上下限,将差值限制在一个合理的范围内,再将所述差值补偿到图像缩放后的该待插值点亮度值上作为图像输出,使所述待插值点与邻域点的过渡更加平缓,从而达到抑制边缘的锯齿失真的效果。The present invention provides an anti-aliasing method and device in image scaling, which obtains the brightness matrix corresponding to the preset neighborhood in the original image according to the position of the point to be interpolated in the enlarged target image, and considers the horizontal and vertical enlargement of the image respectively Selecting the luminance matrix of the preset neighborhood corresponding to the point to be interpolated in the original image avoids the interference of other factors and is simple and easy; judging whether the luminance value of the point to be interpolated is based on the brightness difference of the luminance matrix of the preset neighborhood It needs to be corrected. When selecting the brightness difference threshold of the far and near neighbors, in addition to the row or column of the farthest or nearest neighbor, it also considers other pixels on the row or column where the point to be interpolated is located. Since the row or column where the point to be interpolated is located The brightness value of the pixel on or column changes most obviously, so the brightness difference threshold value of the selected far and near neighbors is more accurate, and the judgment of whether to correct is more realistic; to correct the brightness value of the point to be interpolated, the The calculated positive and negative values of the brightness difference threshold of the point to be interpolated are used as the upper and lower limits of the difference between the brightness median value of the brightness matrix and the brightness value of the point to be interpolated after image scaling, and the difference is limited to a reasonable Within the range, the difference value is compensated to the luminance value of the point to be interpolated after the image is scaled as an image output, so that the transition between the point to be interpolated and the neighboring point is smoother, thereby achieving the effect of suppressing the jagged distortion of the edge .
附图说明 Description of drawings
图1为本发明所述的图像缩放中的抗锯齿失真方法的流程图;Fig. 1 is the flow chart of the anti-aliasing distortion method in the image scaling of the present invention;
图2为本发明所述的图像缩放中的抗锯齿失真方法中步骤B的流程图;Fig. 2 is the flowchart of step B in the anti-aliasing distortion method in the image zooming described in the present invention;
图3为本发明所述的图像缩放中的抗锯齿失真方法中步骤C的流程图;Fig. 3 is the flow chart of step C in the anti-aliasing distortion method in the image scaling of the present invention;
图4为本发明所述的图像缩放中的抗锯齿失真方法中步骤C3的流程图;Fig. 4 is the flow chart of step C3 in the anti-aliasing distortion method in the image scaling of the present invention;
图5(a)-图5(b)为本发明实施例1所述的图像缩放中的抗锯齿失真方法中步骤A的结果示意图;FIG. 5(a)-FIG. 5(b) are schematic diagrams of the results of step A in the anti-aliasing method for image scaling described in
图6(a)为本发明实施例1所述的图像缩放中的抗锯齿失真方法中步骤B1的结果示意图;Fig. 6(a) is a schematic diagram of the result of step B1 in the anti-aliasing method in image scaling described in
图6(b)为本发明实施例1所述的图像缩放中的抗锯齿失真方法中步骤B2的结果示意图;Fig. 6(b) is a schematic diagram of the result of step B2 in the anti-aliasing method in image scaling described in
图7(a)-图7(b)为本发明实施例2所述的图像缩放中的抗锯齿失真方法中步骤A的结果示意图;FIG. 7(a)-FIG. 7(b) are schematic diagrams of the results of step A in the anti-aliasing method for image scaling described in
图8(a)为本发明实施例2所述的图像缩放中的抗锯齿失真方法中步骤B1的结果示意图;Fig. 8(a) is a schematic diagram of the result of step B1 in the anti-aliasing method in image scaling described in
图8(b)为本发明实施例2所述的图像缩放中的抗锯齿失真方法中步骤B2的结果示意图;Fig. 8(b) is a schematic diagram of the result of step B2 in the anti-aliasing method in image scaling described in
图9(a)-图9(d)为本发明实施例1所述的图像缩放中的抗锯齿失真方法的去锯齿前后的效果对比图;Fig. 9(a) - Fig. 9(d) are comparison diagrams of effects before and after anti-aliasing of the anti-aliasing distortion method in the image scaling described in
图10为本发明所述的图像缩放中的抗锯齿失真装置的结构示意图。FIG. 10 is a schematic structural diagram of an anti-aliasing device in image scaling according to the present invention.
具体实施方式 Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明的一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.
根据本发明的一方面,如图1所示,本发明所述的图像缩放中的抗锯齿失真方法包括步骤:According to one aspect of the present invention, as shown in FIG. 1, the anti-aliasing method in the image scaling of the present invention includes steps:
A:根据放大后的目标图像中待插值点位置得到对应原始图像中预设邻域的亮度矩阵;A: Obtain the brightness matrix corresponding to the preset neighborhood in the original image according to the position of the point to be interpolated in the enlarged target image;
只考虑图像的纵向放大时,由于横向边缘的纵向点间的亮度差异较大,横向边缘的纵向锯齿也被放大,为了抑制被纵向放大的锯齿,可以设原始图像高为h_src,目标图像高为h_dst,待插值点在目标图像中的位置为(m,j),则待插值点对应在原始图像中的位置为(fi,j),其中:When only considering the vertical enlargement of the image, since the brightness difference between vertical points on the horizontal edge is large, the vertical jaggedness on the horizontal edge is also enlarged. In order to suppress the jagged vertically enlarged, the height of the original image can be set to h_src, and the height of the target image to be h_dst, the position of the point to be interpolated in the target image is (m, j), then the position of the point to be interpolated in the original image is (fi, j), where:
在原始图像中取待插值点(fi,j)的M行N列的邻域,其中M为偶数,N为奇数,此时待插值点(fi,j)位于中间一列上的中间两行像素之间,待插值点(fi,j)与点(i,j)在纵向的偏移距离为Δy,其中i为横坐标fi的下取整值。以这M行N列个邻域点的亮度值构成M×N的亮度矩阵pixel1。Take the neighborhood of M rows and N columns of the point to be interpolated (fi, j) in the original image, where M is an even number and N is an odd number. At this time, the point to be interpolated (fi, j) is located in the middle two rows of pixels on the middle column Between, the vertical offset distance between the point (fi, j) to be interpolated and the point (i, j) is Δy, where i is the lower integer value of the abscissa fi. An M×N luminance matrix pixel1 is formed with the luminance values of these M rows and N columns of neighboring points.
只考虑图像的横向放大时,由于纵向边缘的横向点间的亮度差异较大,纵向边缘的横向锯齿也被放大,为了抑制被横向放大的锯齿,可以设原始图像宽为w_src,目标图像宽为w_dst,待插值点在目标图像中的位置为(i,n),则待插值点对应在原始图像中的位置为(i,fj),其中:When only considering the horizontal enlargement of the image, due to the large brightness difference between the horizontal points of the vertical edge, the horizontal sawtooth on the vertical edge is also enlarged. In order to suppress the horizontally enlarged sawtooth, the width of the original image can be set to w_src, and the width of the target image to be w_dst, the position of the point to be interpolated in the target image is (i, n), then the position of the point to be interpolated in the original image is (i, fj), where:
在原始图像中取待插值点(i,fj)的L行P列的邻域,其中L为奇数,P为偶数,此时待插值点(i,fj)位于中间一行上的中间两列像素之间,待插值点(i,fj)与点(i,j)在横向的偏移距离为Δx,其中j为纵坐标fj的下取整值。以这L行P列个邻域点的亮度值构成L×P的亮度矩阵pixel2。Take the neighborhood of L rows and P columns of the point to be interpolated (i, fj) in the original image, where L is an odd number and P is an even number. At this time, the point to be interpolated (i, fj) is located in the middle two columns of pixels on the middle row Between, the horizontal offset distance between the point (i, fj) to be interpolated and the point (i, j) is Δx, where j is the lower integer value of the vertical coordinate fj. An L×P brightness matrix pixel2 is formed with the brightness values of these L rows and P columns of neighboring points.
如果既考虑图像纵向放大时的纵向锯齿,又考虑图像横向放大时的横向锯齿,则可以任意次序按照上述方法分别得到对应原始图像中预设邻域的亮度矩阵pixel1和亮度矩阵pixel2。If both the vertical aliasing when the image is enlarged vertically and the horizontal aliasing when the image is enlarged horizontally, the brightness matrix pixel1 and the brightness matrix pixel2 corresponding to the preset neighborhood in the original image can be respectively obtained in any order according to the above method.
在本步骤中,分别考虑图像的横纵向放大选取待插值点在对应原始图像中预设邻域的亮度矩阵,避免了其他因素的干扰,简单易行。In this step, considering the horizontal and vertical enlargement of the image, the luminance matrix of the preset neighborhood corresponding to the point to be interpolated is selected, which avoids the interference of other factors and is simple and easy.
B:根据预设邻域的亮度矩阵的亮度差值判断所述待插值点的亮度值是否需要校正,如果是,则进行步骤C;否则,结束流程;B: judging whether the luminance value of the point to be interpolated needs to be corrected according to the luminance difference of the luminance matrix of the preset neighborhood, if so, proceed to step C; otherwise, end the process;
即在本步骤中,根据预设邻域的亮度矩阵的亮度差值判断待插值点是否位于图像的边缘。That is, in this step, it is judged whether the point to be interpolated is located at the edge of the image according to the brightness difference value of the brightness matrix of the preset neighborhood.
如图2所示,本步骤具体包括:As shown in Figure 2, this step specifically includes:
步骤B1:计算预设邻域的亮度矩阵的远邻域的亮度差异阈值;Step B1: Calculating the luminance difference threshold of the far neighborhood of the luminance matrix of the preset neighborhood;
如果是M×N的亮度矩阵pixel1,则计算中间一列上前M/2个像素和第一行上其他像素中的最大亮度值top1_max和最小亮度值top1_min,以及计算中间一列上后M/2个像素和最后一行上其他像素中的最大亮度值bot1_max和最小亮度值bot1_min,并根据下式计算亮度矩阵pixel1的远邻域的亮度差异阈值diff1If it is an M×N brightness matrix pixel1, calculate the maximum brightness value top1_max and the minimum brightness value top1_min of the first M/2 pixels on the middle column and other pixels on the first row, and calculate the last M/2 pixels on the middle column The maximum brightness value bot1_max and the minimum brightness value bot1_min in the pixel and other pixels on the last row, and calculate the brightness difference threshold diff1 of the far neighbors of the brightness matrix pixel1 according to the following formula
diff1=max(top1_min-bot1_max,bot1_min-top1_max) (3)diff1=max(top1_min-bot1_max, bot1_min-top1_max) (3)
由于当待插值点处在图像的横向边缘时,边缘一边的最小值也不小于另一边的最大值,因此diff1≥0。否则,当待插值点不为图像的横向边缘时,为保证不对图像缩放后的亮度值进行校正,当diff1<0时,令diff1=0。Since when the point to be interpolated is on the horizontal edge of the image, the minimum value on one side of the edge is not less than the maximum value on the other side, so diff1≥0. Otherwise, when the point to be interpolated is not the horizontal edge of the image, in order to ensure that the brightness value after image scaling is not corrected, when diff1<0, set diff1=0.
如果是L×P的亮度矩阵pixel2,则计算中间一行上前P/2个像素和第一列上其他像素中的最大亮度值left1_max和最小亮度值left1_min,以及计算中间一行上后P/2个像素和最后一列上其他像素中的最大亮度值right1_max和最小亮度值right1_min,并根据下式计算亮度矩阵pixel2的远邻域的亮度差异阈值diff1If it is an L×P brightness matrix pixel2, calculate the maximum brightness value left1_max and the minimum brightness value left1_min of the first P/2 pixels on the middle row and other pixels on the first column, and calculate the last P/2 pixels on the middle row The maximum brightness value right1_max and the minimum brightness value right1_min in the pixel and other pixels on the last column, and calculate the brightness difference threshold diff1 of the far neighbors of the brightness matrix pixel2 according to the following formula
diff1=max(left1_min-right1_max,right1_min-left1_max) (4)diff1=max(left1_min-right1_max, right1_min-left1_max) (4)
由于当待插值点处在图像的纵向边缘时,边缘一边的最小值也不小于另一边的最大值,因此diff1≥0。否则,当待插值点不为图像的纵向边缘时,为保证不对图像缩放后的亮度值进行校正,当diff1<0时,令diff1=0。Since when the point to be interpolated is at the longitudinal edge of the image, the minimum value on one side of the edge is not less than the maximum value on the other side, so diff1≥0. Otherwise, when the point to be interpolated is not the vertical edge of the image, in order to ensure that the brightness value after image scaling is not corrected, when diff1<0, set diff1=0.
步骤B2:计算预设邻域的亮度矩阵的近邻域的亮度差异阈值;Step B2: Calculating the brightness difference threshold of the nearest neighbor of the brightness matrix of the preset neighborhood;
如果是M×N的亮度矩阵pixel1,则计算中间一列上前M/2个像素和第M/2行上其他像素中的最大亮度值top2_max和最小亮度值top2_min,以及计算中间一列上后M/2个像素和第M/2+1行上其他像素中的最大亮度值bot2_max和最小亮度值bot2_min,并根据下式计算亮度矩阵pixel1的近邻域的亮度差异阈值diff2If it is an M×N brightness matrix pixel1, calculate the maximum brightness value top2_max and the minimum brightness value top2_min of the first M/2 pixels on the middle column and other pixels on the M/2th row, and calculate M/ The maximum brightness value bot2_max and the minimum brightness value bot2_min of 2 pixels and other pixels on the M/2+1 row, and calculate the brightness difference threshold diff2 of the neighborhood of the brightness matrix pixel1 according to the following formula
diff2=max(top2_min-bot2_max,bot2_min-top2_max) (5)diff2=max(top2_min-bot2_max, bot2_min-top2_max) (5)
由于当待插值点处在图像的横向边缘时,边缘一边的最小值也不小于另一边的最大值,因此diff2≥0。否则,当待插值点不为图像的横向边缘时,为保证不对图像缩放后的亮度值进行校正,当diff2<0时,令diff2=0。Since when the point to be interpolated is on the horizontal edge of the image, the minimum value on one side of the edge is not less than the maximum value on the other side, so diff2≥0. Otherwise, when the point to be interpolated is not the horizontal edge of the image, in order to ensure that the brightness value of the scaled image is not corrected, when diff2<0, set diff2=0.
如果是L×P的亮度矩阵pixel2,则计算中间一行上前P/2个像素和第P/2列上其他像素中的最大亮度值left2_max和最小亮度值left2_min,以及计算中间一行上后P/2个像素和第P/2+1列上其他像素中的最大亮度值right2_max和最小亮度值right2_min,并根据下式计算亮度矩阵pixel2的近邻域的亮度差异阈值diff2If it is an L×P brightness matrix pixel2, calculate the maximum brightness value left2_max and the minimum brightness value left2_min of the first P/2 pixels on the middle row and other pixels on the P/2th column, and calculate the rear P/ on the middle row The maximum brightness value right2_max and the minimum brightness value right2_min of 2 pixels and other pixels on the P/2+1 column, and calculate the brightness difference threshold diff2 of the neighborhood of the brightness matrix pixel2 according to the following formula
diff2=max(left2_min-right2_max,right2_min-left2_max) (6)diff2=max(left2_min-right2_max, right2_min-left2_max) (6)
由于当待插值点处在图像的纵向边缘时,边缘一边的最小值也不小于另一边的最大值,因此diff2≥0。否则,当待插值点不为图像的纵向边缘时,为保证不对图像缩放后的亮度值进行校正,当diff2<0时,令diff2=0。Since when the point to be interpolated is at the longitudinal edge of the image, the minimum value on one side of the edge is not less than the maximum value on the other side, so diff2≥0. Otherwise, when the point to be interpolated is not the vertical edge of the image, in order to ensure that the brightness value after image scaling is not corrected, when diff2<0, set diff2=0.
上述步骤B1和B2的执行无先后顺序,可以同时进行,也可以任意次序先后进行。The above steps B1 and B2 are performed in no order, and can be performed simultaneously, or can be performed sequentially in any order.
步骤B3:根据预设邻域的亮度矩阵的远近邻域的亮度差异阈值判断所述待插值点的亮度值是否需要校正。Step B3: judging whether the luminance value of the point to be interpolated needs to be corrected according to the luminance difference threshold of the far and near neighborhoods of the luminance matrix of the preset neighborhood.
在本步骤中,预设邻域的亮度矩阵的中点的亮度差异阈值m_diff为:In this step, the brightness difference threshold m_diff of the midpoint of the brightness matrix of the preset neighborhood is:
m_diff=diff1-diff2 (7)m_diff=diff1-diff2 (7)
由于在图像的边缘,包括横向边缘和/或纵向边缘,远邻域像素的差异一般比近邻域像素的差异大,因此m_diff≥0。为保证不对不是图像边缘的亮度值进行校正,当m_diff<0时,令m_diff=0。Because at the edge of the image, including the horizontal edge and/or the vertical edge, the difference between the pixels in the far neighborhood is generally larger than the difference in the pixels in the near neighborhood, so m_diff≥0. In order to ensure that the luminance values that are not image edges are not corrected, when m_diff<0, set m_diff=0.
即当m_diff=0时,则表示该待插值点不处于图像的边缘,包括横向边缘和/或纵向边缘,因此图像输出result等于图像缩放后的该待插值点亮度值scl_pix,即不需要对该待插值点进行校正,否则需要对该待插值点进行校正。That is, when m_diff=0, it means that the point to be interpolated is not at the edge of the image, including the horizontal edge and/or vertical edge, so the image output result is equal to the luminance value scl_pix of the point to be interpolated after the image is scaled, that is, there is no need for the The point to be interpolated is corrected, otherwise the point to be interpolated needs to be corrected.
在本步骤中,在选取远近邻域的亮度差异阈值时,除了最远或最近邻域的行或列,还考虑了待插值点所在的行或列上的其他像素,由于待插值点所在的行或列上像素的亮度值变化的最明显,因此使得选取的远近邻域的亮度差异阈值更加准确,由此做出的是否校正的判断更加符合实际。In this step, when selecting the brightness difference threshold of the far and near neighbors, in addition to the row or column of the farthest or nearest neighbor, other pixels on the row or column where the point to be interpolated is located are also considered. The luminance value of the pixel on the row or column changes most obviously, so the luminance difference threshold of the selected far and near neighbors is more accurate, and the judgment of whether to correct or not is more realistic.
C:校正所述待插值点的亮度值。C: Correcting the brightness value of the point to be interpolated.
如图3所示,本步骤具体包括:As shown in Figure 3, this step specifically includes:
步骤C1:计算所述待插值点的亮度差异阈值threshold;Step C1: calculating the brightness difference threshold of the points to be interpolated;
如果是M×N的亮度矩阵pixel1,则设原始像素间的距离为1,则纵向的偏移距离0≤Δy≤1,根据纵向的偏移距离Δy与中点的亮度差异阈值m_diff得到待插值点的亮度差异阈值threshold,计算公式为:If it is an M×N luminance matrix pixel1, set the distance between the original pixels to 1, then the longitudinal offset distance 0≤Δy≤1, and obtain the value to be interpolated according to the longitudinal offset distance Δy and the brightness difference threshold m_diff at the midpoint The brightness difference threshold threshold of the point, the calculation formula is:
如果是L×P的亮度矩阵pixel2,则设原始像素间的距离为1,则横向的偏移距离0≤Δx≤1,根据横向的偏移距离Δx与中点的亮度差异阈值m_diff得到待插值点的亮度差异阈值threshold,计算公式为:If it is an L×P brightness matrix pixel2, set the distance between the original pixels to 1, then the horizontal offset distance 0≤Δx≤1, and obtain the value to be interpolated according to the horizontal offset distance Δx and the brightness difference threshold m_diff at the midpoint The brightness difference threshold threshold of the point, the calculation formula is:
步骤C2:计算亮度矩阵的亮度中值median;Step C2: Calculate the median brightness of the brightness matrix;
如果是M×N的亮度矩阵pixel1,则对其中心两行的各个像素的亮度值进行从低到高排序,取排序后中间两个亮度值的平均值avg作为亮度矩阵中点的亮度值;If it is an M×N luminance matrix pixel1, then sort the luminance values of each pixel in the center two rows from low to high, and take the average avg of the two middle luminance values after sorting as the luminance value of the midpoint of the luminance matrix;
设原始像素间的距离为1,则纵向的偏移距离0≤Δy≤1。若0≤Δy≤0.5,则在亮度矩阵中点与点(i,j)之间进行线性插值,得到亮度矩阵的亮度中值median;若0.5<Δy≤1,则在亮度矩阵中点与点(i+1,j)之间进行线性插值,得到亮度矩阵的亮度中值median。计算公式为:Assuming that the distance between the original pixels is 1, the vertical offset distance is 0≤Δy≤1. If 0≤Δy≤0.5, perform linear interpolation between the midpoint of the luminance matrix and the point (i, j) to obtain the median value of the luminance matrix; (i+1, j) is linearly interpolated to obtain the median brightness of the brightness matrix. The calculation formula is:
其中pixeli,j表示点(i,j)的亮度值,pixeli+1,j表示点(i+1,j)的亮度值。Among them, pixel i, j represents the brightness value of point (i, j), and pixel i+1, j represents the brightness value of point (i+1, j).
如果是L×P的亮度矩阵pixel2,则对其中心两列的各个像素的亮度值进行从低到高排序,取排序后中间两个亮度值的平均值avg作为亮度矩阵中点的亮度值;If it is a brightness matrix pixel2 of L×P, the brightness values of each pixel in the two central columns are sorted from low to high, and the average value avg of the two middle brightness values after sorting is taken as the brightness value of the midpoint of the brightness matrix;
设原始像素间的距离为1,则横向的偏移距离0≤Δx≤1。若0≤Δx≤0.5,则在亮度矩阵中点与点(i,j)之间进行线性插值,得到中值median;若0.5<Δx≤1,则在亮度矩阵中点与点(i,j+1)之间进行线性插值,得到中值median。计算公式为:Assuming that the distance between the original pixels is 1, then the horizontal offset distance is 0≤Δx≤1. If 0≤Δx≤0.5, perform linear interpolation between the midpoint of the luminance matrix and the point (i, j) to obtain the median; +1) to perform linear interpolation to obtain the median. The calculation formula is:
其中pixeli,j表示点(i,j)的亮度值,pixeli,j+1表示点(i,j+1)的亮度值。Among them, pixel i, j represents the brightness value of point (i, j), and pixel i, j+1 represents the brightness value of point (i, j+1).
步骤C3:校正所述待插值点的亮度值并输出。Step C3: Correct and output the luminance value of the point to be interpolated.
如图4所示,本步骤具体包括:As shown in Figure 4, this step specifically includes:
步骤C31:计算亮度矩阵的亮度中值median与图像缩放后的该待插值点亮度值scl_pix间的差值diff:Step C31: Calculate the difference diff between the brightness median of the brightness matrix and the brightness value scl_pix of the point to be interpolated after image scaling:
diff=median-scl_pix (12)diff=median-scl_pix (12)
步骤C32:将待插值点的亮度差异阈值threshold的正负值分别作为差值diff的上下限;Step C32: Use the positive and negative values of the brightness difference threshold threshold of the point to be interpolated as the upper and lower limits of the difference diff;
利用下式将diff限制在一个合理的范围内,即:Use the following formula to limit the diff within a reasonable range, namely:
步骤C33:将差值diff补偿到图像缩放后的该待插值点亮度值scl_pix上作为图像输出result:Step C33: Compensate the difference diff to the luminance value scl_pix of the point to be interpolated after image scaling as the image output result:
result=scl_pix+diff (14)result=scl_pix+diff (14)
因此,当待插值点处于图像中的边缘时,包括横向边缘和/或纵向边缘,图像输出result是在亮度矩阵的亮度中值median和图像缩放后的亮度值scl_pix之间根据待插值点的亮度差异阈值threshold限制后的结果;Therefore, when the point to be interpolated is at the edge of the image, including the horizontal edge and/or the vertical edge, the image output result is based on the brightness of the point to be interpolated between the median brightness value of the brightness matrix and the brightness value scl_pix after image scaling. The result after the difference threshold threshold limit;
当待插值点不处于图像中的边缘时,包括横向边缘和/或纵向边缘,图像输出result即为图像缩放后的亮度值scl_pix。When the point to be interpolated is not at the edge of the image, including the horizontal edge and/or vertical edge, the image output result is the luminance value scl_pix after image scaling.
在本步骤中,将计算得到的所述待插值点的亮度差异阈值的正负值作为亮度矩阵的亮度中值与图像缩放后的该待插值点亮度值间的差值的上下限,将差值限制在一个合理的范围内,再将所述差值补偿到图像缩放后的该待插值点亮度值上作为图像输出,使所述待插值点与邻域点的过渡更加平缓,从而达到抑制边缘的锯齿失真的效果。In this step, the positive and negative values of the calculated brightness difference threshold of the point to be interpolated are used as the upper and lower limits of the difference between the median brightness value of the brightness matrix and the brightness value of the point to be interpolated after image scaling, and the difference The value is limited within a reasonable range, and then the difference is compensated to the luminance value of the point to be interpolated after the image is scaled as an image output, so that the transition between the point to be interpolated and the neighboring point is smoother, thereby achieving suppression The effect of jagged edges.
实施例1:Example 1:
如图5-6所示,在本实施例中,以双三次插值法纵向放大原始图像并对纵向锯齿进行抑制为例进行说明。As shown in FIGS. 5-6 , in this embodiment, the bicubic interpolation method is used as an example to vertically enlarge the original image and suppress vertical jaggies.
如图5(a)所示,在步骤A中取点(i,j)的4×3邻域,则待插值点(fi,j)位于中间一列的第2个像素与第3个像素之间,M取值为4与双三次插值需要纵向4个点一致。As shown in Figure 5(a), if the 4×3 neighborhood of point (i, j) is taken in step A, the point to be interpolated (fi, j) is located between the second pixel and the third pixel in the middle column , the value of M is 4 and bicubic interpolation needs to be consistent with 4 vertical points.
如图6(a)所示,在步骤B1中需要计算如图5(b)所示的4×3的亮度矩阵pixel1中坐标为00、01、02和11四个点的最大亮度值top1_max和最小亮度值top1_min,以及计算4×3的亮度矩阵pixel1中坐标为21、30、31和32四个点的最大亮度值bot1_max和最小亮度值bot1_min。As shown in Figure 6(a), in step B1 it is necessary to calculate the maximum brightness values top1_max and The minimum brightness value top1_min, and calculate the maximum brightness value bot1_max and the minimum brightness value bot1_min of four points whose coordinates are 21, 30, 31 and 32 in the 4×3 brightness matrix pixel1.
如图6(b)所示,在步骤B2中需要计算4×3的亮度矩阵pixel1中坐标为01、10、11和12四个点的最大亮度值top2_max和最小亮度值top2_min,以及计算4×3的亮度矩阵pixel1中坐标为20、21、22和31四个点的最大亮度值bot2_max和最小亮度值bot2_min。As shown in Figure 6(b), in step B2, it is necessary to calculate the maximum brightness value top2_max and the minimum brightness value top2_min of the four points whose coordinates are 01, 10, 11 and 12 in the 4×3 brightness matrix pixel1, and calculate the 4× The maximum brightness value bot2_max and the minimum brightness value bot2_min of four points whose coordinates are 20, 21, 22 and 31 in the brightness matrix pixel1 of 3.
在步骤C2中需要对4×3的亮度矩阵pixel1中的坐标为10、11、12、20、21和22六个点的亮度值进行从低到高排序,取排序后中间两个亮度值的平均值avg作为亮度矩阵中点的亮度值。In step C2, it is necessary to sort the brightness values of the six points whose coordinates are 10, 11, 12, 20, 21 and 22 in the 4×3 brightness matrix pixel1 from low to high, and take the middle two brightness values after sorting The average avg is used as the brightness value of the midpoint of the brightness matrix.
实施例2:Example 2:
如图7-8所示,在本实施例中,以双三次插值法横向放大原始图像并对横向锯齿进行抑制为例进行说明。As shown in FIGS. 7-8 , in this embodiment, the bicubic interpolation method is used as an example to horizontally enlarge the original image and suppress the horizontal jaggies.
如图7(a)所示,在步骤A中取中点(i,j)的3×4邻域,则待插值点(i,fj)位于中间一行的第2个像素与第3个像素之间,P取值为4与双三次插值需要纵向4个点一致。As shown in Figure 7(a), if the 3×4 neighborhood of the midpoint (i, j) is taken in step A, the point to be interpolated (i, fj) is located in the second and third pixels of the middle row Between, the value of P is 4 and bicubic interpolation needs to be consistent with 4 vertical points.
如图8(a)所示,在步骤B1中需要计算如图7(b)所示的3×4的亮度矩阵pixel2中坐标为00、10、20和11四个点的最大亮度值left1_max和最小亮度值left1_min,以及计算3×4的亮度矩阵pixel2中坐标为03、13、23和12四个点的最大亮度值right1_max和最小亮度值right1_min。As shown in Figure 8(a), in step B1 it is necessary to calculate the maximum brightness values left1_max and The minimum brightness value left1_min, and calculate the maximum brightness value right1_max and the minimum brightness value right1_min of four points whose coordinates are 03, 13, 23 and 12 in the 3×4 brightness matrix pixel2.
如图8(b)所示,在步骤B2中需要计算3×4的亮度矩阵pixel2中坐标为10、01、11和21四个点的最大亮度值left2_max和最小亮度值left2_min,以及计算3×4的亮度矩阵pixel2中坐标为02、12、22和13四个点的最大亮度值right2_max和最小亮度值right2_min。As shown in Figure 8(b), in step B2, it is necessary to calculate the maximum brightness value left2_max and the minimum brightness value left2_min of four points whose coordinates are 10, 01, 11 and 21 in the 3×4 brightness matrix pixel2, and calculate 3× The maximum brightness value right2_max and the minimum brightness value right2_min of four points whose coordinates are 02, 12, 22 and 13 in the brightness matrix pixel2 of 4.
在步骤C2中需要对3×4的亮度矩阵pixel2中的坐标为01、11、21、02、12和22六个点的亮度值进行从低到高排序,取排序后中间两个亮度值的平均值avg作为亮度矩阵中点的亮度值。In step C2, it is necessary to sort the brightness values of the six points whose coordinates are 01, 11, 21, 02, 12 and 22 in the 3×4 brightness matrix pixel2 from low to high, and take the middle two brightness values after sorting The average avg is used as the brightness value of the midpoint of the brightness matrix.
实施例3:Example 3:
在本实施例中,以双三次插值法横纵向放大原始图像并对横纵向锯齿都进行抑制为例进行说明。In this embodiment, the bicubic interpolation method is used as an example to magnify the original image horizontally and vertically and suppress both horizontal and vertical jaggies.
即以任意顺序分别进行实施例1和实施例2。That is, Example 1 and Example 2 were performed separately in any order.
本发明实施例1中所述用于图像缩放中抗锯齿失真的方法中去锯齿前后效果对比如图9所示,其中图9(a)为缩放前的原始图像,图9(b)为图9(a)的部分截图,可以发现,原始图像中圆弧形的边缘本身就存在着小的阶梯。图9(c)为对图9(a)进行双三次插值成2×2倍后的部分截图,可以发现,圆弧形的边缘的小阶梯也被放大了,产生了锯齿失真。图9(d)为对图9(c)进行纵向去锯齿后的部分截图,可以发现,图9(c)中的纵向锯齿在图9(d)中得到了有效的抑制。The effect comparison before and after anti-aliasing in the method for anti-aliasing in image scaling described in
如图10所示,根据本发明的另一方面,本发明还同时提供一种图像缩放中的抗锯齿失真装置包括:As shown in FIG. 10, according to another aspect of the present invention, the present invention also provides an anti-aliasing device for image zooming, including:
亮度矩阵获取单元,用于根据放大后的目标图像中待插值点位置得到对应原始图像中预设邻域的亮度矩阵;A luminance matrix acquisition unit, configured to obtain a luminance matrix corresponding to a preset neighborhood in the original image according to the position of the point to be interpolated in the enlarged target image;
校正判决单元,用于根据预设邻域的亮度矩阵的亮度差值判断所述待插值点的亮度值是否需要校正;A correction judgment unit, configured to judge whether the luminance value of the point to be interpolated needs to be corrected according to the luminance difference value of the luminance matrix of the preset neighborhood;
亮度值校正单元,用于校正所述待插值点的亮度值。A brightness value correction unit, configured to correct the brightness value of the point to be interpolated.
所述校正判决单元具体包括:The correction decision unit specifically includes:
远邻域亮度差异阈值计算子单元,用于计算预设邻域的亮度矩阵的远邻域的亮度差异阈值;The distant neighborhood brightness difference threshold calculation subunit is used to calculate the brightness difference threshold of the far neighborhood of the brightness matrix of the preset neighborhood;
近邻域亮度差异阈值计算子单元,用于计算预设邻域的亮度矩阵的近邻域的亮度差异阈值;The neighborhood brightness difference threshold calculation subunit is used to calculate the brightness difference threshold of the neighborhood of the brightness matrix of the preset neighborhood;
校正判决子单元,用于根据预设邻域的亮度矩阵的远近邻域的亮度差异阈值判断所述待插值点的亮度值是否需要校正。The correction judgment subunit is used to judge whether the brightness value of the point to be interpolated needs to be corrected according to the brightness difference threshold value of the far and near neighborhoods of the brightness matrix of the preset neighborhood.
所述亮度值校正单元具体包括:The brightness value correction unit specifically includes:
亮度差异阈值计算子单元,用于计算所述待插值点的亮度差异阈值;A luminance difference threshold calculation subunit, configured to calculate the luminance difference threshold of the point to be interpolated;
亮度中值计算子单元,用于计算亮度矩阵的亮度中值;The brightness median calculation subunit is used to calculate the brightness median of the brightness matrix;
亮度值校正子单元,用于校正所述待插值点的亮度值并输出。The luminance value correcting subunit is used to correct and output the luminance value of the point to be interpolated.
所述亮度值校正子单元具体包括:The brightness value correcting subunit specifically includes:
差值计算模块,用于计算亮度矩阵的亮度中值与图像缩放后的该待插值点亮度值间的差值;A difference calculation module, used to calculate the difference between the brightness median of the brightness matrix and the brightness value of the point to be interpolated after the image is scaled;
差值限制模块,用于将待插值点的亮度差异阈值的正负值分别作为差值的上下限;The difference limit module is used to use the positive and negative values of the brightness difference threshold of the points to be interpolated as the upper and lower limits of the difference respectively;
亮度值校正模块,用于将差值补偿到图像缩放后的该待插值点亮度值上作为图像输出。The luminance value correction module is used to compensate the difference to the luminance value of the point to be interpolated after the image is scaled and output it as an image.
综上所述,本发明提供了一种图像缩放中的抗锯齿失真方法及装置,其根据放大后的目标图像中待插值点位置得到对应原始图像中预设邻域的亮度矩阵,其分别考虑图像的横纵向放大选取待插值点在对应原始图像中预设邻域的亮度矩阵,避免了其他因素的干扰,简单易行;根据预设邻域的亮度矩阵的亮度差值判断所述待插值点的亮度值是否需要校正,其在选取远近邻域的亮度差异阈值时,除了最远或最近邻域的行或列,还考虑了待插值点所在的行或列上的其他像素,由于待插值点所在的行或列上像素的亮度值变化的最明显,因此使得选取的远近邻域的亮度差异阈值更加准确,由此做出的是否校正的判断更加符合实际;校正所述待插值点的亮度值,将计算得到的所述待插值点的亮度差异阈值的正负值作为亮度矩阵的亮度中值与图像缩放后的该待插值点亮度值间的差值的上下限,将差值限制在一个合理的范围内,再将所述差值补偿到图像缩放后的该待插值点亮度值上作为图像输出,使所述待插值点与邻域点的过渡更加平缓,从而达到抑制边缘的锯齿失真的效果。To sum up, the present invention provides an anti-aliasing method and device in image zooming, which obtains the luminance matrix corresponding to the preset neighborhood in the original image according to the position of the point to be interpolated in the enlarged target image, which respectively considers The horizontal and vertical enlargement of the image selects the luminance matrix of the preset neighborhood corresponding to the point to be interpolated in the original image, which avoids the interference of other factors and is simple and easy; judge the luminance matrix to be interpolated according to the luminance difference of the luminance matrix of the preset neighborhood Whether the luminance value of the point needs to be corrected, when selecting the luminance difference threshold of the far and near neighbors, in addition to the row or column of the farthest or nearest neighbor, other pixels on the row or column where the point to be interpolated is located are also considered. The brightness value of the pixel on the row or column where the interpolation point is located has the most obvious change, so the brightness difference threshold of the selected far and near neighbors is more accurate, and the judgment of whether to correct is more realistic; correct the point to be interpolated The brightness value of the point to be interpolated is calculated as the positive and negative values of the brightness difference threshold of the point to be interpolated as the upper and lower limits of the difference between the median brightness of the brightness matrix and the brightness value of the point to be interpolated after image scaling, and the difference Limit it within a reasonable range, and then compensate the difference to the luminance value of the point to be interpolated after the image is scaled as an image output, so that the transition between the point to be interpolated and the neighboring point is smoother, so as to achieve edge suppression Aliasing effect.
以上实施方式仅用于说明本发明,而并非对本发明的限制,有关技术领域的普通技术人员,在不脱离本发明的精神和范围的情况下,还可以做出各种变化和变型,因此所有等同的技术方案也属于本发明的范畴,本发明的实际保护范围应由权利要求限定。The above embodiments are only used to illustrate the present invention, but not to limit the present invention. Those of ordinary skill in the relevant technical field can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, all Equivalent technical solutions also belong to the category of the present invention, and the actual protection scope of the present invention should be defined by the claims.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN2011103884782A CN102521803B (en) | 2011-11-29 | 2011-11-29 | Anti-aliasing method and device in image scaling |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN2011103884782A CN102521803B (en) | 2011-11-29 | 2011-11-29 | Anti-aliasing method and device in image scaling |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN102521803A CN102521803A (en) | 2012-06-27 |
| CN102521803B true CN102521803B (en) | 2013-12-11 |
Family
ID=46292708
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN2011103884782A Expired - Fee Related CN102521803B (en) | 2011-11-29 | 2011-11-29 | Anti-aliasing method and device in image scaling |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN102521803B (en) |
Families Citing this family (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109523469B (en) * | 2018-11-16 | 2022-12-27 | 深圳朗田亩半导体科技有限公司 | Image scaling method and device |
| CN110930289B (en) * | 2019-11-04 | 2021-07-23 | 中南大学 | A kind of image enlargement method and VLSI used for realizing image enlargement |
| CN113837955B (en) * | 2021-08-17 | 2024-08-02 | 每平每屋(上海)科技有限公司 | Image antialiasing processing method and electronic equipment |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1806257A (en) * | 2004-05-19 | 2006-07-19 | 索尼株式会社 | Image processor, image processing method, program for image processing method and recording medium with its program recorded thereon |
| CN101197995A (en) * | 2006-12-07 | 2008-06-11 | 深圳艾科创新微电子有限公司 | Edge self-adapting de-interlacing interpolation method |
| CN101216935A (en) * | 2008-01-17 | 2008-07-09 | 四川虹微技术有限公司 | Image Enlargement Method Based on Spline Function Interpolation Algorithm |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20100067818A1 (en) * | 2008-09-15 | 2010-03-18 | Sony Corporation, A Japanese Corporation | System and method for high quality image and video upscaling |
-
2011
- 2011-11-29 CN CN2011103884782A patent/CN102521803B/en not_active Expired - Fee Related
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1806257A (en) * | 2004-05-19 | 2006-07-19 | 索尼株式会社 | Image processor, image processing method, program for image processing method and recording medium with its program recorded thereon |
| CN101197995A (en) * | 2006-12-07 | 2008-06-11 | 深圳艾科创新微电子有限公司 | Edge self-adapting de-interlacing interpolation method |
| CN101216935A (en) * | 2008-01-17 | 2008-07-09 | 四川虹微技术有限公司 | Image Enlargement Method Based on Spline Function Interpolation Algorithm |
Non-Patent Citations (2)
| Title |
|---|
| 一种改进的双线性插值图像放大算法;龚昌来 等;《激光与红外》;20090831;第39卷(第8期);全文 * |
| 龚昌来 等.一种改进的双线性插值图像放大算法.《激光与红外》.2009,第39卷(第8期),全文. |
Also Published As
| Publication number | Publication date |
|---|---|
| CN102521803A (en) | 2012-06-27 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN106204441B (en) | A kind of method and apparatus for magnifying part of image | |
| CN101216935A (en) | Image Enlargement Method Based on Spline Function Interpolation Algorithm | |
| CN103996170A (en) | Image edge saw-tooth eliminating method with super resolution | |
| CN103093418B (en) | A kind of digital image scaling method of improvement | |
| JP2009070123A (en) | Image processing apparatus and method | |
| CN103034973A (en) | Self-adaptive image scaling method based on bicubic interpolation | |
| CN101123679A (en) | Image processing device, image processing method and computer product | |
| CN103236035B (en) | Based on the image magnification method without the bilateral quadratic B-spline interpolation of skew | |
| TWI758630B (en) | Image zooming method and device | |
| CN101188017A (en) | Digital image scaling method and system | |
| CN102289786A (en) | Edge anti-aliasing method and device for image scaling | |
| CN102521803B (en) | Anti-aliasing method and device in image scaling | |
| CN109919847B (en) | Method for improving quality of amplified image | |
| CN101777176B (en) | A method and device for removing sawtooth of hanging net image | |
| CN102547067A (en) | Improved bicubic interpolation video scaling method | |
| CN112308773A (en) | Unmanned aerial vehicle aerial image nondestructive amplification and splicing fusion method | |
| CN102110431B (en) | Method and device for zooming digital images | |
| CN103024331B (en) | Video de-interlacing method based on edge detection | |
| CN101789120A (en) | Image interpolation method based on cosine polynomial | |
| CN115601472B (en) | A Method of Drawing Undistorted Black Border Based on Dilation and Corrosion Algorithm | |
| US8879864B2 (en) | Generating sub-frame images for driving display | |
| JP6444049B2 (en) | Image processing apparatus, method, and program | |
| CN100580702C (en) | Corneal endothelial cell image processing method | |
| CN102547068A (en) | Improved bilinear interpolation video scaling method | |
| US7567732B2 (en) | Image resolution conversion |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| C14 | Grant of patent or utility model | ||
| GR01 | Patent grant | ||
| C41 | Transfer of patent application or patent right or utility model | ||
| TR01 | Transfer of patent right |
Effective date of registration: 20160304 Address after: 266100 Zhuzhou Road, Laoshan District, Shandong, No. 151, No. Patentee after: Qingdao Hisense Electric Co., Ltd. Address before: 266100 Zhuzhou Road, Laoshan District, Shandong, No. 151, No. Patentee before: Qingdao Hisense Xinxin Technology Co., Ltd. |
|
| CF01 | Termination of patent right due to non-payment of annual fee | ||
| CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20131211 Termination date: 20191129 |