opencv- interpolation algorithm introduced

Recent clinical domain interpolation algorithm:

Suppose now that an image of 500 × 400, we want it to proportionally scaled by the scaling transformation into an image of 400 × 320. We called the original image src, the scaled image called dst, then, for all pixels on the dst, we can use the pixels on the src to represent. Recent clinical domain interpolation algorithm inverse transform by a floating-point coordinates, and subjected to simple rounding, to obtain an integer coordinates. For example, one pixel (40, 32) on dst, we can find the corresponding pixels (50, 40) in the src. Because the pixels must be an integer, so for decimal, we need to take the whole, such as if a pixel corresponds to a pixel on the dst src is on the point (2.2, 2.3), then the recent Pro-domain interpolation algorithm automatically take whole, to the corresponding pixel is in the src (2.2). In other words, take the recent Pro-domain interpolation algorithm is the pixel value of the floating-point coordinates of the nearest point corresponding.

Thus, for a pixel (dst_X, dst_Y) on dst, we can calculate the pixel point (SrC_X, srC_Y) on src: dst_X = srcX * (src_Height / dst_Height) dst_Y = srC_Y * (src_Width / dst_Width)

Recent clinical domain interpolation algorithm is simple and intuitive, but due to its handling of floating point rounding method, and direct access to the pixels closest to the floating point value, and therefore, the image quality by the latest clinical field interpolation algorithm scaling often is not high.

 

 

Bilinear interpolation algorithm:

Bilinear interpolation algorithm is used by default scaling algorithms OpenCV, compared to the recent Pro-domain interpolation algorithm for floating-point rounding direct processing, bilinear interpolation algorithm makes full use of the four pixels surrounding the pixel floating point to jointly determine the final pixel.
We still assume that a pixel corresponds to a pixel on the dst src is on the point (2.2, 2.3), bilinear interpolation algorithm will first of this virtual floating-point pixel projection, may be a horizontal direction, can be It is the vertical direction.

 

投影后分别在水平方向得到×1(2,2.3)、×2(3,2.3)两个点,在竖直方向得到Y1(2.2,2)、Y2(2.2,3)两个点。这四个点都是可以根据虚拟的浮点型像素点四周的四个实际像素点得到,然后我们可以根据X1、X2和Y1、Y2计算转化后的src像素点。我们以Y1、Y2为例,该浮点型像素点距Y1为0.2,距Y2为0.8,那么最终点就可以根据X1*30%+X2*70%和Y1*20%+Y2*80%确定。

双线性插值算法实现起来比最近临域插值算法要复杂得多,我们需要使用几何中心对称的方法获取原图像src的像素点(SrC_x,srC_y),然后找到将用于计算插值的四周的四个点的坐标(SrC_×0,srC_y0)、(src_×0,srC_y1)、(srC_×1,src_y0)、(src_x1.srC_y1),最后根据双线性插值算法进行缩放。这里需要注意的是,由于我们将最终的dst像素点作为一个整体计算,因此在循环的时候我们需要把颜色通道带上。

双线性插值算法虽然计算量较大,但是缩放后的图像质量高,不会像最近临域插值算法那样可能出现像素值不连续的的情况。但是,由于双线性插值算法具有低通滤波器的性质,使高频分量受损,所以可能会使图像轮廓在一定程度上变得模糊。 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/liming19680104/p/12205010.html